开发者

Error while calling next activity in android?

开发者 https://www.devze.com 2023-02-22 12:19 出处:网络
this is my first activity code: public class hello extends Activity { /** Called when the activity is first created. */

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

精彩评论

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