0

我遇到了一个问题……我尝试在 Android 中加载 FB 个人资料图片:

        // Request user data and show the results
        Request.executeMeRequestAsync(session, new Request.GraphUserCallback() 
        {           
            public void onCompleted(GraphUser user, Response response) {
                if (user != null) 
                {                   
                    userInfoTextView.setText(fb.buildUserInfoDisplay(user));    
                    profilePhoto.setImageBitmap(fb.getUserPic());
                }
            }

        });

问题是,我得到 NetworkOnMainThreadException。现在我知道,我必须使用 AsyncTask,但如果我这样做,我无法修改视图,因为它不是在该线程上创建的。有任何想法吗?

4

1 回答 1

0

for network on main thread exception write this code before setting your layout file

if (android.os.Build.VERSION.SDK_INT > 9(minimum sdk target that you have given in your manifest file)) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); }

于 2013-09-05T04:45:34.040 回答