2011-07-04 104 views
0

每次我嘗試啓動我的應用程序它顯示了這個錯誤:應用程序已意外停止,請重試的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

應用程序加載一次展示了應用程序,然後意外停止錯誤調試器顯示上面的窗口,我可以跨過這一切,如此下去,直到永遠,然後錯誤再次顯示:/

謝謝您提前。

+0

這不是你得到的錯誤。警告「Source not found」適用於Eclipse試圖通過跟蹤堆棧跟蹤來調試崩潰的嘗試。如果您粘貼您獲得的堆棧跟蹤,我們可能會提供幫助。 – Estel

+0

我想ive添加了我認爲的堆棧跟蹤?即時通訊過去使用淨豆,而不是蝕,所以即時通訊不完全確定袋的蹤跡是什麼? :s – Houlahan

+0

哎呀,好的!看看:http://stackoverflow.com/questions/2581837/android-debugging-with-logcat-and-emulator-is-it-possible – Estel

回答

0

此類型警告在您調試缺少您的.xml文件的應用程序時得到。這可能是你的佈局文件或清單文件。仔細檢查你的.xml文件。
如果你可以看到logcat,那麼你可以很容易地找到問題。

例如:源未找到和打開Instrumentation.class那麼它可能ü沒有在Android清單文件中添加您的活動類

0

這是我們許多人面臨的問題,而這個問題可能不僅適用於測試應用程序,還適用於您在設備上安裝的應用程序。 如果開發人員爲特定佈局設計了應用程序或未更改所有佈局的XML,則會在某些設備中引發錯誤。

Android有4個佈局(我們大多數人都知道)

佈局 佈局小 佈局大型 佈局,XLARGE

與我的問題是,我提出在XML文件中的變化支持2.7英寸的佈局 - 小文件夾。 我跑了2.7英寸的模擬器,工作非常好。 現在,當我導出已簽名的應用程序並在設備中進行測試時,它將失敗。原因是我沒有在Layout文件夾中進行必要的更改。 我的設備期望在main.xml文件中計算佈局的一些字段 - 小而不是安裝的佈局版本。 所以你應該做的一些事情。 1)測試應用程序時,只需創建1個文件夾(包含所有xml文件的佈局),這樣您就可以在所有設備上測試應用程序的功能。2)如果您創建了所有佈局文件夾,然後在任何XML文件中進行更改,請確保將更改級聯到所有文件夾。

快樂的發展...

相關問題