android - 图库 Activity imageLoader 出错

标签 android

我不断收到这些强制关闭我的 Activity 的错误。它可以在普通设备上运行,但在平板电脑上会出现这些错误?

07-21 19:34:45.472:错误/AndroidRuntime(409):在 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)

它指向我这里:

    }
                @Override

                protected void onPostExecute(Void notUsed){
                    ((Gallery) findViewById(R.id.gallery))
                          .setAdapter(new ImageAdapter(MainMenu.this));


                }

当我注释掉它时,它工作正常。

这是我的 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;
                }

最佳答案

您好像被这个错误困住了。你在 Honeycomb 上测试它吗?

https://github.com/mopub/mopub-client/issues/2

Honeycomb 似乎不允许在主线程上进行网络访问。请参阅此线程 Android Honeycomb: NetworkOnMainThreadException even when using AsyncTask and no strict mode?

关于android - 图库 Activity imageLoader 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6781768/

相关文章:

android - 将 'emma' 添加到 Android ant build 触发 "local variable type mismatch"异常

java - Android Studio : can´t resolve symbol R

Android 应用内结算取消付款,应用未激活

android - 如何使用 Android SimpleCursorAdapter 合并两个或多个列

java - 检索照片时相机崩溃

android - android 在启动应用程序时执行什么过程以及它在运行时如何与 R 类交互?

java - 如何从 URL 检索图像?错误

Android fragment getArguments() 返回 null

android - 可以像 RadioGroup 一样将 CheckedTextView 放入 Group 中吗?

android - Linux 下是 iwconfig,Android 下呢