连接接口时出现Android空指针异常
大家好,我试着用下面的代码连接我应用程序上的两个不同接口连接接口时出现Android空指针异常,android,android-emulator,nullpointerexception,Android,Android Emulator,Nullpointerexception,大家好,我试着用下面的代码连接我应用程序上的两个不同接口 public class HelloForms extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setC
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)
我不知道我做错了什么。你解决了这个问题吗?我也有同样的问题…你解决了吗?我有完全一样的东西。。。