2011-12-17 43 views
0

我對Android非常陌生,並且有一段簡單的代碼,它有一些按鈕,當點擊它時會打開正確的下一個屏幕(PriceScreen),但當另一個點擊時(LocationScreen)在線startActivity(viewlocationScreen);崩潰第一個應用程序 - 在startActivity上崩潰

LocationScreen.java和PriceScreen.java的代碼「似乎」是完全一致的。 代碼調用它是

public class TaxiAppActivity extends Activity { 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Button bBtnYes = (Button) findViewById(R.id.btnYes); 
     bBtnYes.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View arg0) { 
      Intent viewLocationScreen = new Intent(TaxiAppActivity.this,LocationScreen.class); 
//   Intent viewLocationScreen = new Intent(TaxiAppActivity.this,PriceScreen.class); 
       startActivity(viewLocationScreen); // << error here 

      } 
     }); 

     Button cBtnGetPrice = (Button) findViewById(R.id.btnGetPrices); 
     cBtnGetPrice.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View arg0) { 
      Intent viewPriceScreen = new Intent(TaxiAppActivity.this,PriceScreen.class); 
      startActivity(viewPriceScreen); 
      } 
     }); 

//  super.onCreate(savedInstanceState); 
    } 

在上面的代碼,如果我註釋掉線

Intent viewLocationScreen = new Intent(TaxiAppActivity.this,LocationScreen.class); 

並使用.... PriceScreen.class);作爲結束,而不是..它的工作原理。 誰能告訴我爲什麼?

在此先感謝 託尼

+0

您是否已將「LocationScreen」活動添加到清單中? – Dalmas 2011-12-17 18:29:55

+0

「誰能告訴我爲什麼?」 - 只是猜測,但你還沒有在你的'AndroidManifest.xml'中聲明'LocationScreen'爲''?如果這不是答案,那麼發佈logcat輸出。 – Squonk 2011-12-17 18:31:28

+4

歡迎來到SO。當試圖解決Java/Android中的崩潰問題時,最好將堆棧跟蹤添加異常詳細信息,這樣,沒有人需要猜測太多,並且幫助您更容易。 – MByD 2011-12-17 18:32:41

回答

0

你已經註冊在清單文件中的第二個活動? 如果您也可以發佈您的清單文件,這將有助於診斷問題。

應用程序中使用的所有活動必須在清單文件中有一個條目才能讓android實際啓動它們。

不需要在發射露面

額外的活動可以在這樣的清單文件中註冊(從應用程序我目前工作)

<activity 
    android:label="@string/app_name" 
    android:name=".LineupActivity"> 
</activity> 

隨着「.LineupActivity」在該示例將替換爲您的活動的類名稱。在你的情況下.LocationScreen

+0

在這個活動的Android manifest.xml中有一個定義。 這裏是大部分文件 ... ... 的<活動機器人:名字=機器人 「LocationScreen」:標籤= 「位置屏幕」> <活動的android: 「PriceScreen」 NAME =機器人:標籤=「價格屏幕」> <使用庫機器人:名字=「com.google.android.maps」 /> NoToy 2011-12-18 17:04:15

+0

您可以編輯您的問題,並從增加堆棧跟蹤和異常的詳細信息logcat輸出? – 2011-12-18 18:54:01

+0

我相對比較新的android ..並在控制檯中看到,似乎有寫入文件的權限問題。 – NoToy 2011-12-18 19:28:01

相關問題