开发者

The application expliintent(process.com.nakool) has stopped unexpectly ,please try again..force close

I used this code on android 2.2,but while running this code .I am getting the error as "The application expliintent(process.com.nakool) has stopped unexpectly ,please try again..force close.

When i comment the statement "b.setOnClickListener(this);" .the code is processing successfully..Dont know why I am getting error on this line..pls guide me

enter code here

public void onCreate(Bundle savedInstanceState) {


    Button b=(Button)findViewById(R.id.button1);
    b.setOnClickListener(this);

    i=new Intent(this,activitynew.class);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}
开发者_如何学Cpublic void onClick(View v)
{}}


Looking at your code it looks like you are trying to findViewById before you have set the content of this activity by calling setContentView(R.layout.main). That means that findViewById return null, and your app coloses due to nullPointerException (b is null...).

Make sure you call setContentView before you try any findViewById.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜