Android Null Pointer Exception when connecting Interfaces
Hi guys I´ve tried to connect two different interfaces on my app with the following code
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 v开发者_C百科oid 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;
}
});
}
}
When I run the simulation Eclipse throws a
[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)
I do not know what I am doing wrong.
精彩评论