ユーザーがDONEを押した後、簡単なhttp通知を送信したいと思います。ネットワーク操作にAsyncTaskを使用していますが、この例外でアプリケーションがクラッシュする理由がわかりませんandroid.os.NetworkOnMainThreadException
。
private void buttonPressed() {
EditText editTextLogin = (EditText) findViewById(R.id.editTextPassword);
editTextLogin.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView arg0, int actionId, KeyEvent event) {
try{
MyAsync test = new MyAsync(activity);
test.execute("http://google.com");
}catch (Exception e) {
// TODO: handle exception
Log.e("log_tag", "Error in http connection "+e.toString());
}
return true;
}
});
}
その行でこのタスクを実行することは許可されていませんか?
これがクラスです
class MyAsync extends AsyncTask<String, Void, String[]>{
private final Activity activity;
public MyAsync(Activity anActivity){
activity = anActivity; //just in case i will need it later
}
@Override
protected String[] doInBackground(String... args) {
// TODO Auto-generated method stub
Document doc = Jsoup.connect(args[0]).get();
//do something with this document as soon this error android.os.NetworkOnMainThreadException wont rise again
return new String[0];
}
@Override
// Once the image is downloaded, associates it to the imageView
protected void onPostExecute(String[] result) {
Log.e('MyAsync','Finally i got it to work');
}
}
エラーログキャット:-
10-26 23:20:16.729: E/AndroidRuntime(1029): FATAL EXCEPTION: AsyncTask #1
10-26 23:20:16.729: E/AndroidRuntime(1029): java.lang.RuntimeException: An error occured while executing doInBackground()
10-26 23:20:16.729: E/AndroidRuntime(1029): at android.os.AsyncTask$3.done(AsyncTask.java:278)
10-26 23:20:16.729: E/AndroidRuntime(1029): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-26 23:20:16.729: E/AndroidRuntime(1029): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-26 23:20:16.729: E/AndroidRuntime(1029): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
10-26 23:20:16.729: E/AndroidRuntime(1029): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-26 23:20:16.729: E/AndroidRuntime(1029): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
10-26 23:20:16.729: E/AndroidRuntime(1029): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-26 23:20:16.729: E/AndroidRuntime(1029): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-26 23:20:16.729: E/AndroidRuntime(1029): at java.lang.Thread.run(Thread.java:856)
10-26 23:20:16.729: E/AndroidRuntime(1029): Caused by: java.lang.VerifyError: org/jivesoftware/smack/sasl/SASLMechanism
10-26 23:20:16.729: E/AndroidRuntime(1029): at java.lang.reflect.Constructor.constructNative(Native Method)
10-26 23:20:16.729: E/AndroidRuntime(1029): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)