Android Null Pointer Exception when connecting Interfaces

匆匆过客 提交于 2019-12-13 16:09:16

问题


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 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;
        }
    });
    }
}

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.

来源:https://stackoverflow.com/questions/5950523/android-null-pointer-exception-when-connecting-interfaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!