0

こんにちは、私は Android ADK の初心者です。別のファイルにあるクラスSETUPからKakaMainActivityであるメインクラスにメソッドを渡そうとしています。ただし、アプリがシミュレーターを介して実行されるとすぐにクラッシュします。助けてください!

//KakaMainActivity クラス

package com.example.kaka;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;

public class KakaMainActivity extends Activity {

    Button sendMSG1 = (Button)findViewById(R.id.button_Send1);
    Button sendMSG2 = (Button)findViewById(R.id.button_Send2);
    TextView RESULT = (TextView)findViewById(R.id.text_Result);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_kaka_main);

    SETUP clickAGAIN = new SETUP();
    clickAGAIN.click();
   }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.kaka_main, menu);
    return true;
   }

}

//SETUP クラス

package com.example.kaka;

import android.view.View;

public class SETUP extends KakaMainActivity {
    public void click(){
            sendMSG1.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v){
                        RESULT.setText("First message HELLO WORLD!");
            }
        });

        sendMSG2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v){
                RESULT.setText("Second message BYE BYE");
            }
        }); 
  }
}
4

3 に答える 3

0

レイアウトを設定したら、UI コンポーネントをロードする必要があります。

setContentView(R.layout.activity_kaka_main);
sendMSG1 = (Button)findViewById(R.id.button_Send1);
...
RESULT = (TextView)findViewById(R.id.text_Result);
于 2013-09-25T17:40:16.350 に答える