NetworkOnMainThread例外取得: android.os.NetworkOnMainThreadExceptionをは私のデータベースマネージャクラスに次の関数がエラー投げている
この関数は、SQLiteOpenHelper Iを拡張し、私が作成したのDatabaseManagerクラスのパブリックメソッドとして存在しますあなたはUIのコードをブロックし実行しているので、誰かが
public byte[] getBlobFromURL(String url) {
byte[] blobData = null;
DefaultHttpClient mHttpClient = new DefaultHttpClient();
HttpGet mHttpGet = new HttpGet(url);
HttpResponse mHttpResponse;
try {
mHttpResponse = mHttpClient.execute(mHttpGet);
if (mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = mHttpResponse.getEntity();
if (entity != null) {
//ContentValues values = new ContentValues();
blobData = EntityUtils.toByteArray(entity);
//mContext.getContentResolver().insert(MyBaseColumn.MyTable.CONTENT_URI, values);
}
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return blobData;
}
よりも高いレベルだからasynctaskを使用する方がよいかもしれません:http://stackoverflow.com/questions/9745859/networkonmainthread、http://stackoverflow.com/questions/9729825/networkonmainthread-exception-android、http://stackoverflow.com/questions/8427045/how-to-solve-networkonmainthread-exception、http://stackoverflow.com/questions/9156706/what-is-the -error-new-to-android-programming – kabuko
[android.os.NetworkOnMainThreadException]の可能な複製(http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception) – laalto