2016-04-22 2 views
0

Hei guys。私はAndroidプログラミングの新機能です。私はrc車(Arduino)を制御するアプリケーションを作ろうとしています。このアプリでは、次の活動です:アクティビティ間のAndroidアプリケーションスワップが停止します

  1. ボタンについて

私はアプリを開くと、それが突然停止し、I

  • チルトコマンド
  • 音声コマンド
  • 手順
  • をコマンドなぜか分からない。誰かがコードを見て私を助けて、私が間違っていることを教えてもらえますか?どうもありがとう。

    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

    ねえ。知っている。私のPCは少し遅く走っていて、私は伝統的なデバッグモードを使用しています。アプリをコーディングし、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); 
            } 
           }); 
    

    プラス:とURLを開くために、インターネットのアクセス許可:

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

    GeorgeはAndroid MonitorのLogCatに表示されるエラーメッセージを表示します。 – Jorgesys

    +1

    各ボタンのOnClickListenerを作成してみましょう。すぐに更新プログラムに戻ってください。ありがとう。 –