empty crash file when using ACRA

ε祈祈猫儿з 提交于 2019-12-24 11:26:57

问题


i am using the code below to generate a crash file, the file is created at parse.com but it is empty. any idea why?

Another problem is that "ACRA.DEFAULT_REPORT_FIELDS;" has an error, default report fields is not available.

public class LocalSender implements ReportSender {  
      private final Map<ReportField, String> mMapping = new HashMap<ReportField, String>() ;  
      private FileOutputStream crashReport = null;  
      private Context ctx;  
      public LocalSender(Context ct) {  
           ctx = ct;  
      }  
      public void send(CrashReportData report) throws ReportSenderException {  
           final Map<String, String> finalReport = remap(report);  
           ByteArrayOutputStream buf = new ByteArrayOutputStream();  
           Log.i("hcsh","Report send");  
           try {  
                Set set = finalReport.entrySet();  
                Iterator i = set.iterator();  
                String tmp;  
                while (i.hasNext()) {  
                     Map.Entry<String,String> me = (Map.Entry) i.next();  
                     tmp = "[" + me.getKey() + "]=" + me.getValue();  
                     buf.write(tmp.getBytes());  
                }  
                ParseFile myFile = new ParseFile("crash.txt", buf.toByteArray());  
                myFile.save();  
                ParseObject jobApplication = new ParseObject("AppCrash");  
                jobApplication.put("MyCrash", "app name");  
                jobApplication.put("applicantResumeFile", myFile);  
                try {  
                     jobApplication.save();  
                } catch (ParseException e) {  
                     // TODO Auto-generated catch block  
                     e.printStackTrace();  
                }  
           }catch (FileNotFoundException e) {  
                Log.e("TAG", "IO ERROR",e);  
           }  
           catch (IOException e) {  
                Log.e("TAG", "IO ERROR",e);  
           } catch (ParseException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
           }  
 }  
 private Map<String, String> remap(Map<ReportField, String> report) {  
      ReportField[] fields = ACRA.getConfig().customReportContent();  
      if (fields.length == 0) {  
           fields = ACRA.DEFAULT_REPORT_FIELDS;
         }  
      final Map<String, String> finalReport = new HashMap<String, String>(  
                report.size());  
      for (ReportField field : fields) {  
           if (mMapping == null || mMapping.get(field) == null) {  
                finalReport.put(field.toString(), report.get(field));  
           } else {  
                finalReport.put(mMapping.get(field), report.get(field));  
           }  
      }  
      return finalReport;  
 }

 } 

回答1:


There is no such constant as ACRA.DEFAULT_REPORT_FIELDS. You are looking for ACRAConstants.DEFAULT_REPORT_FIELDS




回答2:


ACRA.DEFAULT_REPORT_FIELDS constant value is in acra-4.3.0 version ...

if you are using acra-4.5.0 version ACRA you will get this error "DEFAULT_REPORT_FIELDS cannot be resolved or is not a field" .

try to use acra-4.5.0 version and then use following code

// Extract the required data out of the crash report.

String reportBody = createCrashReport(report);

/** Extract the required data out of the crash report. */

private String createCrashReport(CrashReportData report) {

    // I've extracted only basic information.
    // U can add loads more data using the enum ReportField. See below.
    StringBuilder body = new StringBuilder();
    body.append(
            "Device : " + report.getProperty(ReportField.BRAND) + "-"
                    + report.getProperty(ReportField.PHONE_MODEL))
            .append("\n")
            .append("Android Version :"
                    + report.getProperty(ReportField.ANDROID_VERSION))
            .append("\n")
            .append("App Version : "
                    + report.getProperty(ReportField.APP_VERSION_CODE))
            .append("\n")
            .append("STACK TRACE : \n"
                    + report.getProperty(ReportField.STACK_TRACE));

    return body.toString();
}

Don't use following code ////////////////////////

final String reportBody = buildBody(arg0);

private String buildBody(CrashReportData errorContent) {

    ReportField[] fields = ACRA.getConfig().customReportContent();
    if (fields.length == 0) {
        // fields = ACRA.DEFAULT_MAIL_REPORT_FIELDS;
        fields = ACRA.DEFAULT_REPORT_FIELDS;
    }

    final StringBuilder builder = new StringBuilder();
    for (ReportField field : fields) {
        builder.append(field.toString()).append("=");
        builder.append(errorContent.get(field));
        builder.append('\n');
    }
    return builder.toString();
}

Happy Coding....



来源:https://stackoverflow.com/questions/25328370/empty-crash-file-when-using-acra

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!