2016-04-22 61 views
0

Hei guys。我是Android編程的新手。我試圖製作一個控制RC汽車的應用程序(Arduino)。在這個應用程序是下一個活動:活動之間的Android應用程序交換停止

  1. 按鈕命令
  2. 傾斜指令
  3. 聲音命令
  4. 說明
  5. 關於

當我打開應用程序突然停止和我不知道爲什麼。有人可以通過查看代碼來幫助我,並告訴我我做錯了什麼。非常感謝。

Button buttonCommand; 
Button tiltCommand; 
Button vocalCommand; 
Button instructions; 
Button about; 
Button arduino; // Links Button 
Button android; // Links Button 

public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.content_main); 

    buttonCommand = (Button)findViewById(R.id.buttons); 
    tiltCommand = (Button)findViewById(R.id.tilt); 
    vocalCommand = (Button)findViewById(R.id.vocal); 
    instructions = (Button)findViewById(R.id.instructions); 
    about = (Button)findViewById(R.id.about); 
    arduino = (Button)findViewById(R.id.arduino); 
    android = (Button)findViewById(R.id.android); 
} 

public void onClickButton(View view){ 
    Intent i = new Intent(getApplicationContext(),ButtonCommand.class); // ButtonCommand Activity 
    startActivity(i); 
} 

public void onClickTilt(View view){ 
    Intent i = new Intent(getApplicationContext(),TiltCommand.class); // TiltCommand Activity 
    startActivity(i); 
} 

public void onClickVocal(View view){ 
    Intent i = new Intent(getApplicationContext(),VocalCommand.class); // VocalCommand Activity 
    startActivity(i); 
} 

public void onClickInstructions(View view){ 
    Intent i = new Intent(getApplicationContext(),Instructions.class); // Instructions Activity 
    startActivity(i); 
} 

public void onClickAbout(View view){ 
    Intent i = new Intent(getApplicationContext(),About.class); // About Activity 
    startActivity(i); 
} 

public void onClickArduino(View view){ 
    Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_VIEW); 
    intent.addCategory(Intent.CATEGORY_BROWSABLE); 
    intent.setData(Uri.parse("http://forum.arduino.cc/")); 
    startActivity(intent); 
} 

public void onClickAndroid(View view){ 
    Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_VIEW); 
    intent.addCategory(Intent.CATEGORY_BROWSABLE); 
    intent.setData(Uri.parse("http://forum.xda-developers.com/")); 
    startActivity(intent); 
} 
+2

布納喬治,是非常重要的添加LogCat中顯示的消息 – Jorgesys

+0

嘿。我知道。我的電腦運行有點慢,我正在使用傳統的調試模式。編碼的應用程序,使apk和安裝在我的手機上。對不起,無法提供LogCat消息。 –

+0

您也可以在手機上運行LogCat。 – tynn

回答

0

如果您的應用程序停止在啓動,很可能你缺少添加你的活動的註冊表到您AndroidManifest.xml

<activity android:name=".ButtonCommand" /> 
    <activity android:name=".TiltCommand" /> 
    <activity android:name=".VocalCommand" /> 
    <activity android:name=".Instructions" /> 
    <activity android:name=".About" /> 

喬治,你需要爲每個按鈕例如創建一個OnClickListener :

buttonCommand = (Button)findViewById(R.id.buttons); 
buttonCommand.setOnClickListener(new OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         Intent i = new Intent(getApplicationContext(),ButtonCommand.class); // ButtonCommand Activity 
         startActivity(i); 
        } 
       }); 

加:和互聯網權限打開網址:

<uses-permission android:name="android.permission.INTERNET" /> 
+0

George看到Android監視器內的LogCat,顯示什麼錯誤信息! – Jorgesys

+1

我會嘗試通過爲每個按鈕創建一個OnClickListener。更新很快回來。謝謝。 –

相關問題