2016-04-22 60 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。更新很快回来。谢谢。 –

相关问题