【问题标题】:Error in gallery activity imageLoader图库活动 imageLoader 中的错误
【发布时间】:2011-07-22 03:52:28
【问题描述】:

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

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;
                }

【问题讨论】:

  • 它指向 ImageAdaptet 类的 getView 方法,MainMenu(第 242 行)。你能出示一下这段代码吗?
  • 贴在我的问题末尾

标签: android


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多