Reputation: 89
I keep getting these errors that are force closing my activity. It runs on regular devices but on a tablet i get these errors?
07-21 19:34:45.472: ERROR/AndroidRuntime(409): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1077)
07-21 19:34:45.472: ERROR/AndroidRuntime(409): at java.net.InetAddress.lookupHostByName(InetAddress.java:477)
07-21 19:34:45.472: ERROR/AndroidRuntime(409): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581)
07-21 19:34:45.472: ERROR/AndroidRuntime(409): at com.you.MainMenu$ImageAdapter.getView(MainMenu.java:242)
07-21 19:34:45.472: ERROR/AndroidRuntime(409): at android.view.View.measure(View.java:10828)
07-21 19:34:45.472: ERROR/AndroidRuntime(409): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
Its pointing me here:
}
@Override
protected void onPostExecute(Void notUsed){
((Gallery) findViewById(R.id.gallery))
.setAdapter(new ImageAdapter(MainMenu.this));
}
When i commented it out, it worked fine.
Here is my code of the imageLoader
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(this.myContext);
try {
/* Open a new URL and get the InputStream to load data from it. */
URL aURL = new URL(myRemoteImages[position]);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
/* Buffered is always good for a performance plus. */
BufferedInputStream bis = new BufferedInputStream(is);
/* Decode url-data to a bitmap. */
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
Log.v(imageUrl, "Retrieving image");
/* Apply the Bitmap to the ImageView that will be returned. */
i.setImageBitmap(bm);
} catch (IOException e) {
Log.e("DEBUGTAG", "Remtoe Image Exception", e);
}
/* Image should be scaled as width/height are set. */
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
/* Set the Width/Height of the ImageView. */
i.setLayoutParams(new Gallery.LayoutParams(150, 150));
return i;
}
Upvotes: 1
Views: 328
Reputation: 9117
Seems like you are stuck with this bug. Are you testing it on Honeycomb?
https://github.com/mopub/mopub-client/issues/2
Honeycomb doesn't seem to allow network access on the main thread. Refer this thread Android Honeycomb: NetworkOnMainThreadException even when using AsyncTask and no strict mode?
Upvotes: 2