2011-10-12 128 views
0

這是我第一個使用this series進行學習的Android應用程序,當我運行模擬器時出現錯誤。運行Android模擬器時出錯

這裏的程序:

package com.thenewboston.android.sarabjeet; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 

public class MainActivity extends Activity { 
    /** Called when the activity is first created. */ 

    int counter; 
    Button add, sub; 
    TextView display; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     counter = 0; 
     add = (Button) findViewById(R.id.bAdd); 
     sub = (Button) findViewById(R.id.bSubtract); 
     display = (TextView) findViewById(R.id.tvDisplay); 
     add.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       counter++; 
       display.setText("Your total is " + counter); 
      } 
     }); 
     sub.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       counter--; 
       display.setText("Your total is " + counter); 
      } 
     }); 
    } 
} 

而這裏的運行時信息和錯誤:

[2011-10-12 18:16:57 - sarabjeet] Android Launch! 
[2011-10-12 18:16:57 - sarabjeet] adb is running normally. 
[2011-10-12 18:16:57 - sarabjeet] Performing com.thenewboston.android.sarabjeet.MainActivity activity launch 
[2011-10-12 18:16:57 - sarabjeet] Automatic Target Mode: Preferred AVD 'Sarabjeets_Phone' is available on emulator 'emulator-5554' 
[2011-10-12 18:17:00 - sarabjeet] Application already deployed. No need to reinstall. 
[2011-10-12 18:17:00 - sarabjeet] Starting activity com.thenewboston.android.sarabjeet.MainActivity on device emulator-5554 
[2011-10-12 18:17:02 - sarabjeet] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.thenewboston.android.sarabjeet/.MainActivity } 
[2011-10-12 18:17:02 - sarabjeet] **ActivityManager: Warning: Activity not started, its current task has been brought to the front** 

我全新到Android編程和運行仿真器。這裏有什麼可能是錯誤的,我沒有看到模擬器,因爲我應該?

非常感謝。

+0

程序中的真正錯誤只會顯示在logcat中。閱讀本文以瞭解如何顯示logcat內容:http://developer.android.com/guide/developing/tools/adb.html#logcat – WarrenFaith

回答

1
Warning: Activity not started, its current task has been brought to the front 

這是因爲已經在模擬器按您的應用程序運行後退按鈕,並再次運行,並嘗試或去設置首先刪除應用程序,並重新安裝。

+0

請花些時間格式化您的帖子。謝謝 – WarrenFaith

2

這不是一個錯誤。這些工具只是看到你的程序中沒有任何改變,所以他們沒有重新編譯你的應用程序到一個新的APK。他們在仿真器上啓動了已經安裝的一個。

有時工具會錯過您更改資源(例如/res文件夾內的圖像文件),在這種情況下,您可以清理項目以強制重新生成。在日食裏面使用Project -> Clean ..

+0

@ user658042謝謝它適用於我^ – Amith

0

檢查com.thenewboston.android.sarabjeet 確保其在您的清單文件 可能是這樣的......

<activity android:name="sarabjeet.MainActivity"></activity> 

或任何你的包被稱爲:)

如果然後從模擬器中刪除應用程序,然後關閉仿真器

新聞項目>清潔>清理所有項目

然後再次加載模擬器,一切都會好的

看起來可能就是這樣!

將您的Android清單位發送給我:)