嗨,我对 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;
}
}
//设置类
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");
}
});
}
}