简体   繁体   中英

ACRA Sending Report in TOAST mode, but not DIALOG mode

I'm using ACRA for the first time and seem to be missing something.

Using ReportingInteractionMode.TOAST , the toast popup displays correctly, the crash report is written to a folder using a custom service and shows exactly what I want.

However, if I switch to ReportingInteractionMode.DIALOG , the dialog popup is correct, but I get a NullPointerException and no report gets written. I've been through the and as much of the as this newb can handle and, while I'm sure it's something quite obvious, I gots nothin' . ,并尽可能多的的 ,因为这福利局可以处理和,而我敢肯定这件事情很明显,我没什么全球有机纺织品标准。

Any help finding the issue and getting this to work will be met with humble gratitude, raucous laughter, thunderous applause and, quite possibly, a peaceful night's sleep for you, knowing that you have helped a fellow human in his time of need.

Below is (hopefully) all the pertinent code. If I can provide any more information or clarity, please let me know. Thanks for your time.

CrashReporter.java, with TOAST :

    @ReportsCrashes(formKey = "",
    customReportContent = {ReportField.DEVICE_ID, ReportField.USER_CRASH_DATE, ReportField.USER_APP_START_DATE, ReportField.STACK_TRACE, ReportField.LOGCAT},
    mode = ReportingInteractionMode.TOAST,
    resToastText = R.string.crash_toast_text)

public class CrashReporter extends Application {

@Override  
public void onCreate() {

    ACRA.init(this);
    ACRA.getErrorReporter().removeAllReportSenders();
    ACRA.getErrorReporter().setReportSender(new CrashReportSender());

    super.onCreate();
    }
}

Changes to implement DIALOG mode :

@ReportsCrashes(formKey="",
    customReportContent = {ReportField.DEVICE_ID, ReportField.USER_CRASH_DATE, ReportField.USER_APP_START_DATE, ReportField.STACK_TRACE, ReportField.LOGCAT},
    mode = ReportingInteractionMode.DIALOG,
    resToastText = R.string.crash_toast_text,
    resDialogText = R.string.crash_dialog_text,
    resDialogIcon = R.drawable.ic_launcher,
    resDialogTitle = R.string.crash_dialog_title)

There's also a sender that builds and sends the crash report to a proxy and writes the file, etc. Works perfectly with TOAST:

CrashReportSender.java:

public class CrashReportSender implements ReportSender {

public CrashReportSender() {
}

@Override
public void send(CrashReportData crashReportData) throws ReportSenderException {

    String deviceID = MainActivity.getInstance().getConfiguration().getDeviceId();
    String url = MainActivity.getInstance().getConfiguration().getUrlBase() + "/service/ErrorLoggingService.asmx";
    String  log = buildCrashLog(crashReportData, deviceID);
    ReportServiceProxy proxy = new ReportServiceProxy(url);
    try {
        proxy.WriteLog(log, deviceID);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private String buildCrashLog(CrashReportData crashReportData, String deviceID){

    StringSender logbuild = new StringSender();

    logbuild.append("Device ID: " + deviceID + "\n\n");
    logbuild.append("Crash Date: " + crashReportData.get(ReportField.USER_CRASH_DATE) + "\n\n");
    logbuild.append("App Start Date: " + crashReportData.get(ReportField.USER_APP_START_DATE) + "\n\n");
    logbuild.append("Stack Trace: " + crashReportData.get(ReportField.STACK_TRACE)  + "\n\n" );
    logbuild.append("Logcat:" + crashReportData.get(ReportField.LOGCAT)  + "\n\n" );

    return  logbuild.toString();
    }
} 

And, finally, here are the logcats from both modes. I'm hitting a NullPointerException in DIALOG mode, but I can't figure out what it's not getting.

TOAST logcat - report written to file correctly:



12-17 13:23:11.867    4944-4961/com.dummyproject.mobile E/ACRA﹕ ACRA caught a RuntimeException exception for com.dummyproject.mobile. Building report.
12-17 13:23:11.867    4944-4961/com.dummyproject.mobile D/ACRA﹕ Using custom Report Fields
12-17 13:23:11.882    4944-4947/com.dummyproject.mobile D/dalvikvm﹕ GC_CONCURRENT freed 369K, 13% free 10463K/11911K, paused 14ms+6ms, total 64ms
12-17 13:23:11.890    4944-4961/com.dummyproject.mobile I/ACRA﹕ READ_LOGS granted! ACRA can include LogCat and DropBox data.
12-17 13:23:11.945    4944-4961/com.dummyproject.mobile D/ACRA﹕ Retrieving logcat output...
12-17 13:23:11.976    4944-4961/com.dummyproject.mobile D/ACRA﹕ Writing crash report file 1418822591000.stacktrace.
12-17 13:23:11.992    4944-4961/com.dummyproject.mobile D/ACRA﹕ About to start ReportSenderWorker from #handleException
12-17 13:23:11.992    4944-4975/com.dummyproject.mobile D/ACRA﹕ Mark all pending reports as approved.
12-17 13:23:11.992    4944-4977/com.dummyproject.mobile D/ACRA﹕ Waiting for Toast + worker...
12-17 13:23:12.000    4944-4975/com.dummyproject.mobile D/ACRA﹕ Looking for error files in /data/data/com.dummyproject.mobile/files
12-17 13:23:12.000    4944-4975/com.dummyproject.mobile D/ACRA﹕ #checkAndSendReports - start
12-17 13:23:12.000    4944-4975/com.dummyproject.mobile D/ACRA﹕ Looking for error files in /data/data/com.dummyproject.mobile/files
12-17 13:23:12.000    4944-4975/com.dummyproject.mobile I/ACRA﹕ Sending file 1418822591000-approved.stacktrace
12-17 13:23:12.031    4944-4975/com.dummyproject.mobile D/ReportServiceProxy﹕ Invocation begin
12-17 13:23:12.062    4944-4947/com.dummyproject.mobile D/dalvikvm﹕ GC_CONCURRENT freed 521K, 13% free 10431K/11911K, paused 14ms+2ms, total 43ms
12-17 13:23:12.062    4944-4975/com.dummyproject.mobile D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 25ms
12-17 13:23:12.226    4944-4975/com.dummyproject.mobile D/ReportServiceProxy﹕ Invocation end
12-17 13:23:12.226    4944-4975/com.dummyproject.mobile D/ACRA﹕ #checkAndSendReports - finish
12-17 13:23:15.007    4944-4977/com.dummyproject.mobile D/ACRA﹕ Wait for Toast + worker ended. Kill Application ? true
12-17 13:23:15.007    4944-4977/com.dummyproject.mobile E/ACRA﹕ com.dummyproject.mobile fatal error : No transition defined from PatronLogin to Request_PatronWelcome
    java.lang.RuntimeException: No transition defined from PatronLogin to Request_PatronWelcome
            at com.dummyproject.mobile.ui.UIManager.findStateTransition(UIManager.java:536)
            at com.dummyproject.mobile.ui.UIManager.handle(UIManager.java:511)
            at com.dummyproject.mobile.StateRequestThread.process(StateRequestThread.java:55)
            at com.dummyproject.mobile.StateRequestThread.access$000(StateRequestThread.java:13)
            at com.dummyproject.mobile.StateRequestThread$1.handleMessage(StateRequestThread.java:66)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at com.dummyproject.mobile.StateRequestThread.run(StateRequestThread.java:70)
12-17 13:23:15.007    4944-4977/com.dummyproject.mobile I/ACRA﹕ Finishing the last Activity prior to killing the Process
12-17 13:23:15.070    4944-4977/com.dummyproject.mobile I/ACRA﹕ Finished class com.dummyproject.mobile.MainActivity
12-17 13:23:15.070    4944-4977/com.dummyproject.mobile I/Process﹕ Sending signal. PID: 4944 SIG: 9

And, the DIALOG logcat:



12-17 13:32:32.320    5025-5042/com.dummyproject.mobile E/ACRA﹕ ACRA caught a RuntimeException exception for com.dummyproject.mobile. Building report.
12-17 13:32:32.328    5025-5042/com.dummyproject.mobile D/ACRA﹕ Using custom Report Fields
12-17 13:32:32.351    5025-5029/com.dummyproject.mobile D/dalvikvm﹕ GC_CONCURRENT freed 368K, 13% free 10459K/11911K, paused 21ms+14ms, total 91ms
12-17 13:32:32.367    5025-5042/com.dummyproject.mobile I/ACRA﹕ READ_LOGS granted! ACRA can include LogCat and DropBox data.
12-17 13:32:32.414    5025-5042/com.dummyproject.mobile D/ACRA﹕ Retrieving logcat output...
12-17 13:32:32.460    5025-5042/com.dummyproject.mobile D/ACRA﹕ Writing crash report file 1418823152000.stacktrace.
12-17 13:32:32.492    5025-5055/com.dummyproject.mobile D/ACRA﹕ Waiting for Toast + worker...
12-17 13:32:32.523    5025-5029/com.dummyproject.mobile D/dalvikvm﹕ GC_CONCURRENT freed 461K, 13% free 10400K/11911K, paused 13ms+4ms, total 47ms
12-17 13:32:35.500    5025-5055/com.dummyproject.mobile D/ACRA﹕ About to create DIALOG from #handleException
12-17 13:32:35.500    5025-5055/com.dummyproject.mobile D/ACRA﹕ Creating Dialog for 1418823152000.stacktrace
12-17 13:32:35.570    5025-5055/com.dummyproject.mobile D/ACRA﹕ Wait for Toast + worker ended. Kill Application ? true
12-17 13:32:35.578    5025-5055/com.dummyproject.mobile E/ACRA﹕ com.dummyproject.mobile fatal error : No transition defined from PatronLogin to Request_PatronWelcome
    java.lang.RuntimeException: No transition defined from PatronLogin to Request_PatronWelcome
            at com.dummyproject.mobile.ui.UIManager.findStateTransition(UIManager.java:536)
            at com.dummyproject.mobile.ui.UIManager.handle(UIManager.java:511)
            at com.dummyproject.mobile.StateRequestThread.process(StateRequestThread.java:55)
            at com.dummyproject.mobile.StateRequestThread.access$000(StateRequestThread.java:13)
            at com.dummyproject.mobile.StateRequestThread$1.handleMessage(StateRequestThread.java:66)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at com.dummyproject.mobile.StateRequestThread.run(StateRequestThread.java:70)
12-17 13:32:35.859    5057-5057/com.dummyproject.mobile D/ACRA﹕ ACRA is enabled for com.dummyproject.mobile, intializing...
12-17 13:32:35.890    5057-5057/com.dummyproject.mobile D/ACRA﹕ Looking for error files in /data/data/com.dummyproject.mobile/files
12-17 13:32:35.890    5057-5057/com.dummyproject.mobile D/ACRA﹕ Looking for error files in /data/data/com.dummyproject.mobile/files
12-17 13:32:35.890    5057-5057/com.dummyproject.mobile D/ACRA﹕ Looking for error files in /data/data/com.dummyproject.mobile/files
12-17 13:32:35.898    5057-5057/com.dummyproject.mobile D/ACRA﹕ Opening CrashReportDialog for 1418823152000.stacktrace
12-17 13:32:35.960    5057-5057/com.dummyproject.mobile D/dalvikvm﹕ GC_FOR_ALLOC freed 226K, 4% free 9418K/9735K, paused 28ms, total 28ms
12-17 13:32:36.039    5057-5057/com.dummyproject.mobile I/libEGL﹕ Processor type: omap4430
12-17 13:32:36.039    5057-5057/com.dummyproject.mobile I/libEGL﹕ egl.cfg: entry POWERVR_SGX540_120 omap4430
12-17 13:32:36.039    5057-5057/com.dummyproject.mobile I/libEGL﹕ Picked EGL type 'POWERVR_SGX540_120' for processor 'omap4430'
12-17 13:32:36.039    5057-5057/com.dummyproject.mobile D/libEGL﹕ loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
12-17 13:32:36.039    5057-5057/com.dummyproject.mobile D/libEGL﹕ loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
12-17 13:32:36.046    5057-5057/com.dummyproject.mobile D/libEGL﹕ loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
12-17 13:32:36.109    5057-5057/com.dummyproject.mobile D/OpenGLRenderer﹕ Enabling debug mode 0
12-17 13:32:48.742    5057-5057/com.dummyproject.mobile D/ACRA﹕ Add user comment to 1418823152000.stacktrace
12-17 13:32:48.875    5057-5060/com.dummyproject.mobile D/dalvikvm﹕ GC_CONCURRENT freed 105K, 2% free 9860K/10055K, paused 16ms+6ms, total 97ms
12-17 13:32:48.875    5057-5057/com.dummyproject.mobile D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 28ms
12-17 13:32:48.890    5057-5057/com.dummyproject.mobile V/ACRA﹕ About to start SenderWorker from CrashReportDialog
12-17 13:32:48.890    5057-5074/com.dummyproject.mobile D/ACRA﹕ Mark all pending reports as approved.
12-17 13:32:48.898    5057-5074/com.dummyproject.mobile D/ACRA﹕ Looking for error files in /data/data/com.dummyproject.mobile/files
12-17 13:32:48.906    5057-5074/com.dummyproject.mobile D/ACRA﹕ #checkAndSendReports - start
12-17 13:32:48.906    5057-5074/com.dummyproject.mobile D/ACRA﹕ Looking for error files in /data/data/com.dummyproject.mobile/files
12-17 13:32:48.906    5057-5074/com.dummyproject.mobile I/ACRA﹕ Sending file 1418823152000-approved.stacktrace
12-17 13:32:48.945    5057-5074/com.dummyproject.mobile E/ACRA﹕ Failed to send crash reports for 1418823152000-approved.stacktrace
    java.lang.NullPointerException
            at com.dummyproject.mobile.webservice.CrashReportSender.send(CrashReportSender.java:18)
            at org.acra.SendWorker.sendCrashReport(SendWorker.java:179)
            at org.acra.SendWorker.checkAndSendReports(SendWorker.java:141)
            at org.acra.SendWorker.run(SendWorker.java:77)
12-17 13:32:48.945    5057-5074/com.dummyproject.mobile D/ACRA﹕ #checkAndSendReports - finish

It is crashing in your own CrashReportSender code:

com.dummyproject.mobile.webservice.CrashReportSender.send(CrashReportSender.java:18)

What's on line#18?

Use customeReportSender and call it in Application class

public class ACRACustomSender implements ReportSender {

@Override
public void send(CrashReportData report) throws ReportSenderException {
    // TODO Auto-generated method stub
    JsonParsing jsonparsing=new JsonParsing();
    crashReport addCrashDetails=new crashReport();
    addCrashDetails.setMobileInfo(report.getProperty(ReportField.BRAND)+report.getProperty(ReportField.PHONE_MODEL));
    addCrashDetails.setPackageName(report.getProperty(ReportField.PACKAGE_NAME));
    addCrashDetails.setVersionName(report.getProperty(ReportField.APP_VERSION_NAME));
    String error = report.getProperty(ReportField.STACK_TRACE);
    addCrashDetails.setErrorDescription(error.substring(0, error.indexOf("Exception")+9) + " " + error.substring(error.indexOf("at"),error.indexOf(")")+1));
    jsonparsing.addCrashDetails("custom url of service", addCrashDetails);

}

}

Application class:

public class MainApp extends Application {

@Override
public void onCreate() {
    super.onCreate();

    // The following line triggers the initialization of ACRA
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                .permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }
    ACRA.init(this);
    ACRACustomSender customSender = new ACRACustomSender();
    ACRA.getErrorReporter().setReportSender(customSender);

}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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