大家好我曾尝试使用以下代码连接我的应用程序上的两个不同界面
public class HelloForms extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageButton button = (ImageButton) findViewById(R.id.android_button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Perform action on clicks
setContentView(R.layout.secon);
//Toast.makeText(HelloForms.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
Button buttonReg = (Button) findViewById(R.id.android_secon);
buttonReg.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Perform action on clicks
setContentView(R.layout.main);
//Toast.makeText(HelloForms.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
final EditText edittext = (EditText) findViewById(R.id.edittext);
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
Toast.makeText(HelloForms.this, edittext.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
}
}
当我运行模拟时,Eclipse会抛出一个
[2011-05-10 07:57:48 - ddms]null java.lang.NullPointerException
at com.android.ddmlib.Client.sendAndConsume(Client.java:572)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
我不知道我做错了什么。