I’m learning android development. I created a simple layout consisting of a button (id:button1). I added an OnClickListener to this button, which when clicked, shows the next page (layout). There appears to be no errors in the code, but when I run it, it simply crashes. I tried it using android 2.3.3 and 2.2 emulators, but no success. when I comment out the onclicklistener part, the app runs.
i searched through various sites and questions, but no success.
Here is the java code:
package com.sid.next;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class mySplash extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent("com.sid.next.SHOWMENU"));
}
});
}
}
Edit1:
stacktrace
Edit2: main.xml
Edit3: [solved!] i didn’t have any contentview set for the myMenu.java activity. Thanks anyways!
edit4: changed android.R.id.button1 to R.id.button1
okay. so finally i figured it out myself!
i hadn’t set any contentView for the myMenu.java class.
also changed android.R.id.button1 to R.id.button1. (credit: Imran Rana)
thank you everyone!