【问题标题】:empty crash file when using ACRA使用 ACRA 时为空的崩溃文件
【发布时间】:2014-08-15 14:34:07
【问题描述】:

我正在使用下面的代码生成崩溃文件,该文件是在 parse.com 创建的,但它是空的。 知道为什么吗?

另一个问题是“ACRA.DEFAULT_REPORT_FIELDS;”有错误,默认报告字段不可用。

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;  
 }

 } 

【问题讨论】:

    标签: android acra


    【解决方案1】:

    没有像ACRA.DEFAULT_REPORT_FIELDS 这样的常量。你在找ACRAConstants.DEFAULT_REPORT_FIELDS

    【讨论】:

      【解决方案2】:

      ACRA.DEFAULT_REPORT_FIELDS 常量值在 acra-4.3.0 版本中...

      如果您使用的是 acra-4.5.0 版本的 ACRA,您将收到此错误“DEFAULT_REPORT_FIELDS 无法解析或不是字段”。

      尝试使用 acra-4.5.0 版本,然后使用以下代码

      // 从崩溃报告中提取所需的数据。

      String reportBody = createCrashReport(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();
      }
      

      不要使用以下代码 /////////////////////

      最终字符串reportBody = buildBody(arg0);

      私有字符串 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();
      }
      

      快乐编码....

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多