Error while calling next activity in android?
this is my first activity code:
public class hello extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.imageButton1);
button.setOnClickListener(new View.OnClickListener()
{
public void onC开发者_运维技巧lick(View v)
{
// Perform action on click
Intent i = new Intent(hello.this,Selectmsg.class);
startActivity(i);
}
});
}
}
following is my next activity code:
public class Selectmsg extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
}
}
but i am occurring error.it closing forcefully.,its not working.i just want to call next activity.and i also written driver for next activity in Androidmanifest.so please help me to remove error.. Thanks in Advance--
You say you get this exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{demo.hello/demo.hello.hello}: java.lang.ClassCastException: android.widget.ImageButton
I believe therefore that you should change this line:
Button button = (Button) findViewById(R.id.imageButton1);
To this:
ImageButton button = (ImageButton) findViewById(R.id.imageButton1);
You can try this:
Intent i=new Intent();
i.setClassName("packageName","Classname");
startActivity(i);
精彩评论