应用程序意外停止请再次尝试android

时间:2011-07-04 15:57:31

标签: java android

每次尝试启动我的应用时,都会显示以下错误:

The application SMSbackupv1 (process com.SMS.Backup) has stpped unexpectedly. please try again.

我不知道错误在哪里创建。但是当我调试文件时,threadGroup.class显示并显示

Source not found
the JAR file C:\Program Files (x86)\Android\android-sdk\platforms\android-8\android.jar has no source attachment.

这是代码:

import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SMSbackup extends Activity {
    private Button backupBTN;
    public ArrayList<String> exportBuffer = new ArrayList<String>();

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try {
            backupBTN = (Button) this.findViewById(R.id.button1);

        } catch (Exception e) {
            this.backupBTN.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    try {

                        Cursor c = getContentResolver().query(
                                Uri.parse("content://sms"), null, null, null,
                                null);
                        getColumnData(c);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });

        }
    }

    public void getColumnData(Cursor cur) {
        try {
            if (cur.moveToFirst()) {
                String id;
                String date;
                String phoneNumber;
                String body;

                int idColumn = cur.getColumnIndex("_id");
                int dateColumn = cur.getColumnIndex("date");
                int numberColumn = cur.getColumnIndex("address");
                int bodyColumn = cur.getColumnIndex("body");

                do {

                    id = cur.getString(idColumn);
                    date = cur.getString(dateColumn);
                    body = cur.getString(bodyColumn);
                    phoneNumber = cur.getString(numberColumn);

                    exportBuffer.add(id + " ," + date + " ," + body + " ,"
                            + phoneNumber);

                } while (cur.moveToNext());
            }
            WriteToFile();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void WriteToFile() {
        try {
            CSV export = new CSV();
            export.generateCSVFile(exportBuffer);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

创建CSV类:

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import android.os.Environment;
import android.widget.Toast;

public class CSV extends SMSbackup {

    public static ArrayList<String> data = new ArrayList<String>();
    public static File rootFolder;
    public static File root;
    private static String subFolderName;
    private static String fileName;
    public boolean mExternalStorageAvailable = false;
    public boolean mExternalStorageWriteable = false;

    public CSV() 
    {
        checkStorage();

        if(mExternalStorageAvailable == true && mExternalStorageWriteable == true)
        {
            root = new File(Environment.getExternalStorageDirectory() + "/SMSMonitor/", null);
            subFolderName = GetSubFolder();
            fileName = getFileName();
        }
    }

    public void checkStorage()
    {
        CharSequence text;
        int duration = Toast.LENGTH_SHORT;
        mExternalStorageAvailable = false;
        mExternalStorageWriteable = false;

        String state = Environment.getExternalStorageState();

        if (Environment.MEDIA_MOUNTED.equals(state)) 
        {
            text = "SD card is Read and Write";
            mExternalStorageAvailable = mExternalStorageWriteable = true;

        } 
        else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) 
        {
            text = "SD Card is Read Only";
            mExternalStorageAvailable = true;
            mExternalStorageWriteable = false;
        } 
        else 
        {
            mExternalStorageAvailable = mExternalStorageWriteable = false;
            text = "Something else is wrong...";
        }
        //Toast toast = Toast.makeText(SmsBackupActivity.defaultInstance, text, duration);
        //toast.show();
    }

    public void generateCSVFile(ArrayList<String> list)
    {
        root = new File(rootFolder + "/SMSMonitor/" + subFolderName, fileName);

        try 
        {
            FileWriter write = new FileWriter(root);

            write.append("ID, Date, Address, Body");
            write.append('\n');

            for (String s : list)
            {
                write.append(s);
                write.append('\n');
            }
            write.flush();
            write.close();
        }
        catch (IOException e) 
        {
            e.printStackTrace();
        }
    }


    private static String getFileName()
    {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        String fileName = "Backup_" + sdf.format(cal.getTime()).toString() + ".csv";

        return fileName;
    }

    private static String GetSubFolder()
    {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        subFolderName = sdf.format(cal.getTime()).toString();

        return subFolderName;
    }

}

可能的堆栈跟踪?:

    // Compiled from ThreadGroup.java (version 1.5 : 49.0, super bit)
public class java.lang.ThreadGroup implements java.lang.Thread$UncaughtExceptionHandler {

  // Method descriptor #9 (Ljava/lang/String;)V
  // Stack: 3, Locals: 2
  public ThreadGroup(java.lang.String name);
     0  aload_0 [this]
     1  invokespecial java.lang.Object() [1]
     4  new java.lang.RuntimeException [2]
     7  dup
     8  ldc <String "Stub!"> [3]
    10  invokespecial java.lang.RuntimeException(java.lang.String) [4]
    13  athrow
      Line numbers:
        [pc: 0, line: 5]
      Local variable table:
        [pc: 0, pc: 14] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 14] local: name index: 1 type: java.lang.String

  // Method descriptor #17 (Ljava/lang/ThreadGroup;Ljava/lang/String;)V
  // Stack: 3, Locals: 3
  public ThreadGroup(java.lang.ThreadGroup parent, java.lang.String name);
     0  aload_0 [this]
     1  invokespecial java.lang.Object() [1]
     4  new java.lang.RuntimeException [2]
     7  dup
     8  ldc <String "Stub!"> [3]
    10  invokespecial java.lang.RuntimeException(java.lang.String) [4]
    13  athrow
      Line numbers:
        [pc: 0, line: 6]
      Local variable table:
        [pc: 0, pc: 14] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 14] local: parent index: 1 type: java.lang.ThreadGroup
        [pc: 0, pc: 14] local: name index: 2 type: java.lang.String

  // Method descriptor #20 ()I
  // Stack: 3, Locals: 1
  public int activeCount();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 7]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #20 ()I
  // Stack: 3, Locals: 1
  public int activeGroupCount();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 8]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #23 (Z)Z
  // Stack: 3, Locals: 2
  public boolean allowThreadSuspension(boolean b);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 9]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 10] local: b index: 1 type: boolean

  // Method descriptor #27 ()V
  // Stack: 3, Locals: 1
  public final void checkAccess();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 10]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #27 ()V
  // Stack: 3, Locals: 1
  public final void destroy();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 11]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #30 ([Ljava/lang/Thread;)I
  // Stack: 3, Locals: 2
  public int enumerate(java.lang.Thread[] threads);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 12]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 10] local: threads index: 1 type: java.lang.Thread[]

  // Method descriptor #33 ([Ljava/lang/Thread;Z)I
  // Stack: 3, Locals: 3
  public int enumerate(java.lang.Thread[] threads, boolean recurse);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 13]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 10] local: threads index: 1 type: java.lang.Thread[]
        [pc: 0, pc: 10] local: recurse index: 2 type: boolean

  // Method descriptor #35 ([Ljava/lang/ThreadGroup;)I
  // Stack: 3, Locals: 2
  public int enumerate(java.lang.ThreadGroup[] groups);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 14]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 10] local: groups index: 1 type: java.lang.ThreadGroup[]

  // Method descriptor #38 ([Ljava/lang/ThreadGroup;Z)I
  // Stack: 3, Locals: 3
  public int enumerate(java.lang.ThreadGroup[] groups, boolean recurse);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 15]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 10] local: groups index: 1 type: java.lang.ThreadGroup[]
        [pc: 0, pc: 10] local: recurse index: 2 type: boolean

  // Method descriptor #20 ()I
  // Stack: 3, Locals: 1
  public final int getMaxPriority();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 16]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #41 ()Ljava/lang/String;
  // Stack: 3, Locals: 1
  public final java.lang.String getName();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 17]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #43 ()Ljava/lang/ThreadGroup;
  // Stack: 3, Locals: 1
  public final java.lang.ThreadGroup getParent();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 18]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #27 ()V
  // Stack: 3, Locals: 1
  public final void interrupt();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 19]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #46 ()Z
  // Stack: 3, Locals: 1
  public final boolean isDaemon();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 20]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #46 ()Z
  // Stack: 3, Locals: 1
  public synchronized boolean isDestroyed();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 21]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #27 ()V
  // Stack: 3, Locals: 1
  public void list();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 22]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #50 (Ljava/lang/ThreadGroup;)Z
  // Stack: 3, Locals: 2
  public final boolean parentOf(java.lang.ThreadGroup g);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 23]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 10] local: g index: 1 type: java.lang.ThreadGroup

  // Method descriptor #27 ()V
  // Stack: 3, Locals: 1
  public final void resume();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 24]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #54 (Z)V
  // Stack: 3, Locals: 2
  public final void setDaemon(boolean isDaemon);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 25]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 10] local: isDaemon index: 1 type: boolean

  // Method descriptor #56 (I)V
  // Stack: 3, Locals: 2
  public final void setMaxPriority(int newMax);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 26]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 10] local: newMax index: 1 type: int

  // Method descriptor #27 ()V
  // Stack: 3, Locals: 1
  public final void stop();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 27]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #27 ()V
  // Stack: 3, Locals: 1
  public final void suspend();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 28]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #41 ()Ljava/lang/String;
  // Stack: 3, Locals: 1
  public java.lang.String toString();
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 29]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup

  // Method descriptor #63 (Ljava/lang/Thread;Ljava/lang/Throwable;)V
  // Stack: 3, Locals: 3
  public void uncaughtException(java.lang.Thread t, java.lang.Throwable e);
     0  new java.lang.RuntimeException [2]
     3  dup
     4  ldc <String "Stub!"> [3]
     6  invokespecial java.lang.RuntimeException(java.lang.String) [4]
     9  athrow
      Line numbers:
        [pc: 0, line: 30]
      Local variable table:
        [pc: 0, pc: 10] local: this index: 0 type: java.lang.ThreadGroup
        [pc: 0, pc: 10] local: t index: 1 type: java.lang.Thread
        [pc: 0, pc: 10] local: e index: 2 type: java.lang.Throwable

  Inner classes:
    [inner class info: #7 java/lang/Thread$UncaughtExceptionHandler, outer class info: #76 java/lang/Thread
     inner name: #78 UncaughtExceptionHandler, accessflags: 1545 public abstract static]
}

控制台:

    [2011-07-04 17:59:32 - SMSbackupv1] Android Launch!
[2011-07-04 17:59:32 - SMSbackupv1] adb is running normally.
[2011-07-04 17:59:32 - SMSbackupv1] Performing com.SMS.Backup.SMSbackupv1Activity activity launch
[2011-07-04 17:59:32 - SMSbackupv1] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'Test'
[2011-07-04 17:59:32 - SMSbackupv1] Uploading SMSbackupv1.apk onto device 'emulator-5554'
[2011-07-04 17:59:33 - SMSbackupv1] Installing SMSbackupv1.apk...
[2011-07-04 17:59:37 - SMSbackupv1] Success!
[2011-07-04 17:59:37 - SMSbackupv1] Starting activity com.SMS.Backup.SMSbackupv1Activity on device emulator-5554
[2011-07-04 17:59:41 - SMSbackupv1] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.SMS.Backup/.SMSbackupv1Activity }
[2011-07-04 17:59:42 - SMSbackupv1] Attempting to connect debugger to 'com.SMS.Backup' on port 8621

DDMS没什么 调试窗口显示: enter image description here

应用程序加载一次显示应用程序意外停止错误然后调试器显示上面的窗口我可以跳过它所有它继续然后错误再次显示:/

提前谢谢。

2 个答案:

答案 0 :(得分:0)

当您调试.xml文件中缺少的应用程序时,会收到此类型警告。这可能是您的布局文件或清单文件。仔细检查你的.xml文件 如果您能看到logcat,那么您可以轻松找到问题。

例如:找不到源并打开Instrumentation.class 然后它可能你没有在android清单文件中添加你的活动类

答案 1 :(得分:0)

这是我们很多人面临的问题,这个问题可能不仅适用于测试应用,也适用于您在设备上安装的应用。 如果开发人员为特定布局设计应用程序或者没有更改所有布局的XML,则会在某些设备中引发错误。

Android有4个布局(我们大多数人都知道)

布局 布局小 布局大 布局XLARGE

我的问题是我在支持2.7英寸的layout-small文件夹中对XML文件进行了更改。 我跑了Emulator,再次为2.7英寸并且工作得非常好。 现在,当我导出已签名的应用程序并在设备中进行测试时,它将失败。原因是我没有在Layout文件夹中进行必要的更改。 我的设备期望在main.xml文件中为layout -small而不是在安装的布局版本中进行计算的某些字段。 所以你应该做几件事。 1)测试应用程序时,只创建一个文件夹(包含所有xml文件的布局),这样您就可以在所有设备上测试应用程序的功能。 2)如果您已创建所有布局文件夹,然后在任何XML文件中进行更改,请确保将更改(级别)级联到所有文件夹。

快乐发展......