gpt4 book ai didi

java - Android.OS.NetworkOnMainThreadException 中

转载 作者:行者123 更新时间:2023-12-01 18:09:21 24 4
gpt4 key购买 nike

我正在尝试获取用户 facebook 个人资料图片及其缩略图,并在下载后将其添加到解析类中。看看吧

@Override
protected String doInBackground(String[] Params)
{

String accessToken = AccessToken ;
String email = EMAIL;
profile = com.facebook.Profile.getCurrentProfile();
User.put("displayName", profile.getName());
User.put("facebookId", profile.getId());
User.setUsername(profile.getId());
try
{
User.put("FBaccessToken", accessToken);
User.setEmail(email);
}
catch (Exception e){

Log.e("ERROR","Failed");
}
User.setPassword(profile.getId() + profile.getId());
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.whereEqualTo("username", profile.getId());
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, ParseException e)
{
if (e == null)
{
//brace the lord no error
if (list == null)
{
parseSignUp() ;
}
else
{
if (list.isEmpty())
{
parseSignUp() ;
}
else
{
login(profile.getId(), (profile.getId() + profile.getId()));
}
for (ParseObject str : list)
{
Log.e("ERROR", "what ?");
}
}


}
else
{
Log.e("ERROR", "not");

}
}
});
return "done";
}

登录.java

   SendFeedBackJob newJob = new SendFeedBackJob();

newJob.progressBar = progressBar ;


newJob.EMAIL = email ;
newJob.AccessToken = accessToken.getToken();

newJob.invisible = View.INVISIBLE ;

newJob.show = View.VISIBLE ;
newJob.execute();

即使网络内容位于 AsyncTask 中,此代码仍然会引发此错误

  12-04 19:02:27.773    4263-4263/com.socketmill.thisismohit.vine       E/ERROR﹕android.os.NetworkOnMainThreadException
12-04 19:02:27.803 4263-4263/com.socketmill.thisismohit.vine E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.parse.ParseFile.<init>(ParseFile.java:188)
at com.parse.ParseFile.<init>(ParseFile.java:218)
at com.socketmill.thisismohit.vine.SendFeedBackJob.parseSignUp(SendFeedBackJob.java:207)
at com.socketmill.thisismohit.vine.SendFeedBackJob$1.done(SendFeedBackJob.java:90)
at com.socketmill.thisismohit.vine.SendFeedBackJob$1.done(SendFeedBackJob.java:75)
at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:115)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)

最佳答案

FindInBackground 的完成回调方法在 UI 线程上运行,而不是在异步线程上运行

关于java - Android.OS.NetworkOnMainThreadException 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34090120/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com