예외가 httpConn.connect();
있지만 예외는 android에서 nullmsg를 표시합니다. 모든 도움을 주시면 감사하겠습니다. Net Beans에서 코드를 실행하면 완벽하게 실행됩니다. 이미 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
menifest 파일에 작성 했습니다. rss 피드를 구문 분석하는 모든 방법. 메소드가 있지만 예외를 통한 코드 이후입니다.
주요 활동
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView=(TextView)findViewById(R.id.title);
try{
OpenHttpConnection("http://www.business-standard.com/rss/economy-policy-102.rss");
}catch (Exception e) { textView.setText("OnCreate demo exception");}
}
OpenHttpConnection
private InputStream OpenHttpConnection(String urlString) {
InputStream in = null;
TextView textView = (TextView) findViewById(R.id.title);
textView.setText("coct");
try {
int response = -1;
URL url = new URL(urlString);
URLConnection con = url.openConnection();
if(android.os.Debug.isDebuggerConnected()) {
android.os.Debug.waitForDebugger();
}
if (!(con instanceof HttpURLConnection)) {
textView.setText("Not An HTTP Connection");
}
try {
HttpURLConnection httpConn = (HttpURLConnection) con;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
textView.setText("connect");
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK)
in = httpConn.getInputStream();
if (in == null) textView.setText("in passed");
else textView.setText(in.toString());
} catch (Exception ex) {
textView.setText(ex.getMessage()+"msg");
Log.d("Networking", ex.getLocalizedMessage());
}
}
catch (Exception ex) {Log.d("Networking", ex.getLocalizedMessage()); }
return in;
}
여기에 system_process 오류 파일
[ https://drive.google.com/file/d/0BzgBo2Rg7cjEX3pSaGc3TTdodFk/view?usp=sharing][1]
다음과 같이 시도하십시오.
public class MainActivity extends Activity {
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTextView = (TextView) findViewById(R.id.title);
MyAsyncTask mMyAsyncTask = new MyAsyncTask();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
mMyAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
mMyAsyncTask.execute();
}
}
// Getter method for TextView.
public static TextView getTextView() {
return MainActivity.mTextView;
}
// Setter method for TextView.
public static void setTextView(TextView textView) {
MainActivity.mTextView = textView;
}
}
public class MyAsyncTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
String result = MyClass.getResultFromRss();
return result;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (result != null && MainActivity.getTextView() != null) {
MainActivity.getTextView().setText(result);
}
}
}
public class MyClass {
public static String getResultFromRss() {
// Add your OpenHttpConnection method here.
String result = <Result_from_OpenHttpConnection_method>;
return result;
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다