简体   繁体   English

致命异常:AsyncTask#1 java.lang.RuntimeException:执行doInBackground()错误时发生错误

[英]FATAL EXCEPTION: AsyncTask #1 java.lang.RuntimeException: An error occurred while executing doInBackground() error

Sorry, this is the second time posting this issue, my code was working fine a few years ago, when I tried to run it now, I got this issue 抱歉,这是第二次发布此问题,几年前我的代码运行良好,当我尝试现在运行它时,出现了此问题

08-07 06:04:44.801: E/AndroidRuntime(20161): FATAL EXCEPTION: AsyncTask #1
08-07 06:04:44.801: E/AndroidRuntime(20161): Process: com.parents.track, PID: 20161
08-07 06:04:44.801: E/AndroidRuntime(20161): java.lang.RuntimeException: An error occurred while executing doInBackground()
08-07 06:04:44.801: E/AndroidRuntime(20161):    at android.os.AsyncTask$3.done(AsyncTask.java:309)
08-07 06:04:44.801: E/AndroidRuntime(20161):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
08-07 06:04:44.801: E/AndroidRuntime(20161):    at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
08-07 06:04:44.801: E/AndroidRuntime(20161):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
08-07 06:04:44.801: E/AndroidRuntime(20161):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
08-07 06:04:44.801: E/AndroidRuntime(20161):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
08-07 06:04:44.801: E/AndroidRuntime(20161):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
08-07 06:04:44.801: E/AndroidRuntime(20161):    at java.lang.Thread.run(Thread.java:818)
08-07 06:04:44.801: E/AndroidRuntime(20161): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONObject.getInt(java.lang.String)' on a null object reference
08-07 06:04:44.801: E/AndroidRuntime(20161):    at com.parents.track.LoginActivity$LogIn.doInBackground(LoginActivity.java:89)
08-07 06:04:44.801: E/AndroidRuntime(20161):    at com.parents.track.LoginActivity$LogIn.doInBackground(LoginActivity.java:1)
08-07 06:04:44.801: E/AndroidRuntime(20161):    at android.os.AsyncTask$2.call(AsyncTask.java:295)
08-07 06:04:44.801: E/AndroidRuntime(20161):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-07 06:04:44.801: E/AndroidRuntime(20161):    ... 4 more

class LogIn extends AsyncTask<String,Void,String >{

    private JsonParser jsonParser;

    @Override
    protected String doInBackground(String... arg0) {
        jsonParser = new JsonParser();
        String url = "http://localhost/track/login.php?phone=";
        StringBuilder urlStringBuilder = new StringBuilder(url);
        urlStringBuilder.append(arg0[0]);
        SessionManager sessionManager=new SessionManager(context);

        JSONObject json = jsonParser.getJsonObject(urlStringBuilder, "GET");
        int isLongedIn=0;
        try {
            isLongedIn=json.getInt("LogedIn");
            if(isLongedIn==1){
            String sesion=json.getString("Message");
            sessionManager.createLoginSession(sesion);
            Intent intent=new Intent(context,WelcomeActivity.class);
            Bundle extra = new Bundle();
            extra.putString("HP",phone.getText().toString());
             intent.putExtras(extra);
            startActivity(intent);
            }else{
                Intent intent=new Intent(context,LoginActivity.class);
                startActivity(intent);
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            Log.w("Json Error", e.toString());
            e.printStackTrace();
        }


        return null;
    }
}

Check your server response,it can't find "LogedIn" in this line: isLongedIn=json.getInt("LogedIn"); 检查您的服务器响应,在此行中找不到“ LogedIn”: isLongedIn = json.getInt(“ LogedIn”); Add a default isLongedIn=json.getInt("LogedIn",0); 添加默认值isLongedIn = json.getInt(“ LogedIn”,0); and Check response for have a record by name "LogedIn" 并检查响应是否具有名称为“ LogedIn”的记录

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命异常:AsyncTask#1 java.lang.RuntimeException:执行doInBackground()时发生错误 - FATAL EXCEPTION: AsyncTask #1 java.lang.RuntimeException: An error occurred while executing doInBackground() 致命异常:AsyncTask#3 java.lang.RuntimeException:执行doInBackground()时发生错误 - Fatal Exception: AsyncTask #3 java.lang.RuntimeException: An error occurred while executing doInBackground() 致命异常:AsyncTask#1 java.lang.RuntimeException:在执行doInBackground()并将图像发送到服务器时发生错误 - FATAL EXCEPTION: AsyncTask #1 java.lang.RuntimeException: An error occured while executing doInBackground(), while sending an image to the Server E / AndroidRuntime:致命例外:AsyncTask#1 java.lang.RuntimeException:执行doInBackground()时发生错误 - E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 java.lang.RuntimeException: An error occured while executing doInBackground() 如何解决此问题:执行doInBackground()时发生致命异常Asynctask#1 java.lang.RuntimeException错误 - how to solve this : Fatal Exception Asynctask #1 java.lang.RuntimeException error occured while executing doInBackground() 致命异常:AsyncTask#1:java.lang.RuntimeException:执行doInBackground()时发生错误 - FATAL EXCEPTION: AsyncTask #1:java.lang.RuntimeException: An error occured while executing doInBackground() java.lang.RuntimeException:在执行doInBackground()致命错误时发生错误:AsyncTask#2 - java.lang.RuntimeException: An error occured while executing doInBackground() FATAL EXCEPTION: AsyncTask #2 java.lang.RuntimeException:执行doInBackground()时发生错误 - java.lang.RuntimeException: An error occurred while executing doInBackground() 致命异常:asynctask#1 java.lang.runtimeException:执行doinbackground时发生错误 - fatal exception : asynctask #1 java.lang.runtimeException: an error occured while excuting doinbackground java.lang.RuntimeException:在 Google Play 商店上传时执行 doInBackground() 时出错 - java.lang.RuntimeException: An error occurred while executing doInBackground() while upload in google play store
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM