2015-12-02 79 views
0

發送第一條消息到helpshift之後,我收到了以下堆棧。我對android非常陌生,不明白如何調試。此外,這種崩潰發生在5倍,所以我不知道如何重現n修復它。急救中遇到的故障Android

0 
java.lang.RuntimeException: An error occured while executing doInBackground() 
1 
at android.os.AsyncTask$3.done(AsyncTask.java:300) 
2 
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) 
3 
at java.util.concurrent.FutureTask.setException(FutureTask.java:222) 
4 
at java.util.concurrent.FutureTask.run(FutureTask.java:242) 
5 
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
6 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
7 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
8 
at java.lang.Thread.run(Thread.java:818) 
9 
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 
10 
at android.os.Handler.<init>(Handler.java:200) 
11 
at android.os.Handler.<init>(Handler.java:114) 
12 
at com.helpshift.HSApiData.updateUAToken(SourceFile:1260) 
13 
at com.helpshift.Helpshift.registerDeviceToken(SourceFile:641) 
14 
at notifications.GCMRegisterCheck$RegisteringHelpShiftWithToken.doInBackground(SourceFile:337) 
15 
at notifications.GCMRegisterCheck$RegisteringHelpShiftWithToken.doInBackground(SourceFile:331) 
16 
at android.os.AsyncTask$2.call(AsyncTask.java:288) 
17 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
18 
... 4 more 
19 
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 
20 
at android.os.Handler.<init>(Handler.java:200) 
21 
at android.os.Handler.<init>(Handler.java:114) 
22 
at com.helpshift.HSApiData.updateUAToken(SourceFile:1260) 
23 
at com.helpshift.Helpshift.registerDeviceToken(SourceFile:641) 
24 
at notifications.GCMRegisterCheck$RegisteringHelpShiftWithToken.doInBackground(SourceFile:337) 
25 
at notifications.GCMRegisterCheck$RegisteringHelpShiftWithToken.doInBackground(SourceFile:331) 
26 
at android.os.AsyncTask$2.call(AsyncTask.java:288) 
27 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
28 
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
29 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
30 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
31 
at java.lang.Thread.run(Thread.java:818) 

回答

0

發生此次崩潰的原因是調用發生在不包含關聯的活套的線程中。要停止此次崩潰:

  1. 創建處理程序線程。
  2. 使用上述處理程序線程的循環並創建一個註冊處理程序。
  3. 在註冊處理程序中進行API調用。

內,您的異步任務 -

@Override 
protected Void doInBackground(Void... voids) { 
    HandlerThread handlerThread = new HandlerThread("register-device-token"); 
    handlerThread.start(); 
    new RegisterDeviceTokenHandler(handlerThread.getLooper(), context).post(null); 
    return null; 
} 

您註冊設備標記處理程序 -

private static class RegisterDeviceTokenHandler extends Handler { 

    private final Context context; 

    public RegisterDeviceTokenHandler(Looper looper, Context context) { 
     super(looper); 
     this.context = context; 
    } 

    @Override 
    public void handleMessage(Message msg) { 
     Helpshift.registerDeviceToken(context, "hello"); 
    } 
} 

對於其他任何疑問,請隨時[email protected]

與我們聯繫