我有一个listView显示个人的个人资料图片(一种学校社交媒体),我将这些图片的链接存储在一个sql数据库中,其中包含他们的名字和其他两个参数。
这是我的custom adapter

class customAdapter extends ArrayAdapter<String> {
public customAdapter(Context context, String[] friends) {
    super(context, R.layout.customrow, friends);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MyDBHandler  dbHandler = new MyDBHandler(getContext(), null, null, 1);
   Product product;
    LayoutInflater myinfl = LayoutInflater.from(getContext());
    View customview = myinfl.inflate(R.layout.customrow, parent, false);
    String singlefooditem  = getItem(position);
    TextView name = (TextView)customview.findViewById(R.id.rowText);
    ImageView img = (ImageView)customview.findViewById(R.id.profilePic);
    product = dbHandler.findProductName(singlefooditem);
   try {
        URL url = new URL(product.getImage());
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();

        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        img.setImageBitmap(myBitmap);
    }catch (IOException e){

    }

    name.setText(singlefooditem);
    return customview;
}

那是我的logcat:
            at android.view.View.measure(View.java:17479)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
        at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:444)
        at android.view.View.measure(View.java:17479)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:17479)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
        at android.view.View.measure(View.java:17479)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2532)
        at android.view.View.measure(View.java:17479)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2262)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1391)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1590)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6585)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
        at android.view.Choreographer.doCallbacks(Choreographer.java:603)
        at android.view.Choreographer.doFrame(Choreographer.java:573)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5586)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
        at dalvik.system.NativeStart.main(Native Method)

最佳答案

我怀疑stacktrace没有包含真正的错误,这似乎是您试图在主(ui)线程上执行网络活动,这是一个很大的错误。要么在新线程中执行此工作,要么使用androidImageManager类为您完成所有的繁重工作。

关于android - 列出来自网络的 View 图像,显示使用Android Studio出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31880506/

10-10 15:07