简体   繁体   English

单击android中的后退按钮时应用程序崩溃

[英]App Crashes when click back button in android

I am using an activity in multiple screens, and the app crashes when I click back button on a specific one screen only, but it works fine on the others...我在多个屏幕中使用一个活动,当我只在特定的一个屏幕上单击后退按钮时应用程序崩溃,但它在其他屏幕上工作正常......

So I call the screen in the below method:所以我在下面的方法中调用屏幕:

@Override
public void donateOnClic(ActivityOrganizationModel activityOrganizationModel) {
    DonateActivity.startActivity(activityOrganizationModel, getScreenName(), getContext());
    try {
        sendToMixpanelLanguage(Config.MIXPANEL_EVENT_DONATION_ACTIVITY);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

and this is the below exception I found when I click back button:这是我单击后退按钮时发现的以下异常:

V/FA: Inactivity, disconnecting from the service
E/HTTP: <-- 500 INTERNAL SERVER ERROR https://automator.appgain.io/automessages/5e403f53970b2b000b92de74/firevent/userdidnotdonate/123468393 (7568ms)
E/HTTP: Access-Control-Allow-Origin: *
    Access-Control-Expose-Headers: x-parse-master-key,x-parse-application-id,Accept,Accept-Version,Content-Length,Content-MD5,Content-Type,Date,X-Auth-Token,authToken,appapikey,Authorization,appid
    Content-Type: text/html; charset=UTF-8
    Date: Sun, 07 Nov 2021 09:00:58 GMT
    Server: gunicorn/19.6.0
    Via: kong/0.11.2
    X-Kong-Proxy-Latency: 2862
    X-Kong-Upstream-Latency: 3764
    Content-Length: 291
    Connection: keep-alive
E/HTTP: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <title>500 Internal Server Error</title>
    <h1>Internal Server Error</h1>
    <p>The server encountered an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>
    <-- END HTTP (291-byte body)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.quantatil.ikhar, PID: 22387
    com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
        at com.google.gson.Gson.fromJson(Gson.java:927)
        at com.google.gson.Gson.fromJson(Gson.java:892)
        at com.google.gson.Gson.fromJson(Gson.java:841)
        at com.google.gson.Gson.fromJson(Gson.java:813)
        at io.appgain.sdk.controller.Utils.getAppGainFailure(Utils.java:81)
        at io.appgain.sdk.controller.Automator$1$2.onResponse(Automator.java:65)
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:71)
        at android.os.Handler.handleCallback(Handler.java:794)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:6651)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
     Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
        at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:215)
        at com.google.gson.Gson.fromJson(Gson.java:927) 
        at com.google.gson.Gson.fromJson(Gson.java:892) 
        at com.google.gson.Gson.fromJson(Gson.java:841) 
        at com.google.gson.Gson.fromJson(Gson.java:813) 
        at io.appgain.sdk.controller.Utils.getAppGainFailure(Utils.java:81) 
        at io.appgain.sdk.controller.Automator$1$2.onResponse(Automator.java:65) 
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:71) 
        at android.os.Handler.handleCallback(Handler.java:794) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:176) 
        at android.app.ActivityThread.main(ActivityThread.java:6651) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824) 

The problem is:问题是:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

This happens when you try to convert an Json object to POJO but in this case the Json object & POJO object doesn't match at all, so Gson throw this Exception当您尝试将Json对象转换为POJO时会发生这种情况,但在这种情况下, Json对象和POJO对象根本不匹配,因此Gson抛出此Exception

<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>

So, the application is crashing on Gson conversation state where Gson was expacting an Json object (respective to your POJO ) but got an HTML page.因此,应用程序在Gson对话状态下崩溃,其中Gson正在提取一个Json对象(相对于您的POJO )但得到了一个HTML页面。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM