2016-11-02 8 views
-8

`私はアンドロイドの開発には新しく、ボタンをクリックすると他のページやアクティビティに行くことができるアプリを作成しようとしています。計算やアルゴリズムボタンをクリックするとアプリケーションがクラッシュする私が間違っていることを教えてください。ボタンボタンクリックでアンドロイドアプリがクラッシュする

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Algorithm" android:id="@+id/button7" android:layout_gravity="center_horizontal" android:onClick="algorithm1"/> 
+0

ボタンのXMLコード<ボタン アンドロイド:layout_width = "wrap_content" アンドロイド:layout_height = "wrap_content" アンドロイド:テキスト= "アルゴリズム" アンドロイド:ID = "@ + ID/button7" アンドロイド:layout_gravity = "center_horizo​​ntal" android:onClick = "algorithm1" /> – user3642714

+1

エラートレースのエラーは何ですか? –

+1

AppManifestファイルにアルゴリズムクラスを登録しましたか? PS:小文字ではなく、大文字で始まるクラス名。 – Furqan

答えて

0

ため

package com.example.myfirstapp; 
import android.content.Intent; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 

public class Main3Activity extends AppCompatActivity { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main3); 
} 
public void algorithm1(View view) { 
Intent intent = new Intent(this, algorithm.class); 
startActivity(intent); 
} 
public void compute(View view){ 
Intent intent = new Intent(this,result.class); 
startActivity(intent); 
}` 

XMLコードはまた、Javaコードを使用してのonClickを実装することができます。以下に示すサンプルコードを使用することができます。

Button btn = (Button) findViewById(R.id.button7); 

btn.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     yourMethod(v); 
    } 
}); 

public void yourMethod(View v) { 
    // does something 
} 

これを試してください。この方法を試してください。 詳細については、linkを参照してください。

-1

algorithm.classのマニフェストを変更しましたか?あなたは、manifestにalgorithm.classのために<activity>を加えなければなりません。

関連する問題