【问题标题】:problem with send me log向我发送日志的问题
【发布时间】:2010-03-29 06:52:37
【问题描述】:

我曾尝试在我的应用程序中实现向我发送日志功能,但我无法做到。有人可以帮我吗?在 logcat 中,它显示了错误:

03-29 21:23:37.636:错误/AndroidRuntime(820):未捕获的处理程序:线程 AsyncTask #1 由于未捕获的异常而退出 03-29 21:23:37.726: 错误/AndroidRuntime(820): java.lang.RuntimeException: 执行 doInBackground() 时发生错误 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 android.os.AsyncTask$3.done(AsyncTask.java:200) 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:234) 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:258) 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 java.util.concurrent.FutureTask.run(FutureTask.java:122) 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648) 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673) 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 java.lang.Thread.run(Thread.java:1058) 03-29 21:23:37.726: 错误/AndroidRuntime(820): 由: java.lang.NullPointerException 引起 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 resonet.android.androidgallery.helloAndroid$CheckForceCloseTask.doInBackground(helloAndroid.java:1565) 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 resonet.android.androidgallery.helloAndroid$CheckForceCloseTask.doInBackground(helloAndroid.java:1) 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 android.os.AsyncTask$2.call(AsyncTask.java:185) 03-29 21:23:37.726: 错误/AndroidRuntime(820): 在 java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:256) 03-29 21:23:37.726: 错误/AndroidRuntime(820): ... 4 更多

这是我的代码:

public class helloAndroid extends Activity implements OnClickListener {

public static final int DIALOG_SEND_LOG = 345350;
protected static final int DIALOG_PROGRESS_COLLECTING_LOG = 3255;
protected static final int DIALOG_FAILED_TO_COLLECT_LOGS = 3535122;


private static final int DIALOG_REPORT_FORCE_CLOSE = 3535788;

 private LogCollector mLogCollector;

public void onCreate(Bundle savedInstanceState) {


requestWindowFeature(Window.FEATURE_NO_TITLE);

  Bundle b = this.getIntent().getExtras();
  s = b.getString("specialValue").trim();
  String xmlURL = "";

  CheckForceCloseTask task = new CheckForceCloseTask();
     task.execute();
    }
    private void throwException() {
  throw new NullPointerException();
 }

 @Override
 protected Dialog onCreateDialog(int id) {
  Dialog dialog = null;
  switch (id) {
  case DIALOG_SEND_LOG:
  case DIALOG_REPORT_FORCE_CLOSE:
   Builder builder = new AlertDialog.Builder(this);
   String message;
   if (id==DIALOG_SEND_LOG)
    message = "Do you want to send me your logs?";
   else 
    message = "It appears this app has been force-closed, do you want to report it to me?";
   builder.setTitle("Warning")
   .setIcon(android.R.drawable.ic_dialog_alert)
   .setMessage(message)
   .setPositiveButton("Yes", this)
   .setNegativeButton("No", this);
   dialog = builder.create();
   break;
  case DIALOG_PROGRESS_COLLECTING_LOG:
   ProgressDialog pd = new ProgressDialog(this);
   pd.setTitle("Progress");
   pd.setMessage("Collecting logs...");
   pd.setIndeterminate(true);
   dialog = pd;   
   break;
  case DIALOG_FAILED_TO_COLLECT_LOGS:
   builder = new AlertDialog.Builder(this);
   builder.setTitle("Error")
   .setMessage("Failed to collect logs.")
   .setNegativeButton("OK", null);
   dialog = builder.create();
  }
  return dialog;
 }

 class CheckForceCloseTask extends AsyncTask<Void, Void, Boolean> {
  @Override
  protected Boolean doInBackground(Void... params) {
   return mLogCollector.hasForceCloseHappened();
  }

  @Override
  protected void onPostExecute(Boolean result) {
   if (result) {
    showDialog(DIALOG_REPORT_FORCE_CLOSE);
   } else
    Toast.makeText(getApplicationContext(), "No force close detected.", Toast.LENGTH_LONG).show();
  }
 }

 public void onClick(DialogInterface dialog, int which) {
  switch (which) {
  case DialogInterface.BUTTON_POSITIVE:
   new AsyncTask<Void, Void, Boolean>() {
    @Override
    protected Boolean doInBackground(Void... params) {
     return mLogCollector.collect();
    }
    @Override
    protected void onPreExecute() {
     showDialog(DIALOG_PROGRESS_COLLECTING_LOG);
    }
    @Override
    protected void onPostExecute(Boolean result) {
     dismissDialog(DIALOG_PROGRESS_COLLECTING_LOG);
     if (result)
      mLogCollector.sendLog("lintonye@gmail.com", "Error Log", "Preface\nPreface line 2");
     else
      showDialog(DIALOG_FAILED_TO_COLLECT_LOGS);
    }

   }.execute();
  }
  dialog.dismiss();
 }
}

【问题讨论】:

    标签: android


    【解决方案1】:

    问题是mLogCollector 从未初始化,因此它始终为空。这是在doInBackground 中为您提供NullPointerException

    你可以在堆栈跟踪中看到这个:

    Caused by: java.lang.NullPointerException
      at resonet.android.androidgallery.helloAndroid$CheckForceCloseTask.doInBackground(helloAndroid.java:1565)
    

    如果您阅读了android-send-me-logs 文档的用法部分,它用粗体字写的第一句话是:

    实例化 LogCollector

    LogCollector collector = new LogCollector(context);
    

    你需要这样做。

    【讨论】:

    • 谢谢马克。我没有意识到这一点。在我添加 mLogCollector = new LogCollector(this);这条线然后它工作。但是,当我单击报告强制关闭时,它会显示一条消息,指出不支持的操作 - 当前不支持该操作。我在代码中遗漏了什么可以将日志发送到我的电子邮件?
    【解决方案2】:

    只是想指出 LogCollector 库在 Droid X 2.3.x 上不起作用。

    【讨论】:

      猜你喜欢
      • 2020-06-29
      • 1970-01-01
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多