开发者

Force Stop occurs although build has no error ?

My program is not working well, and I don't understand why, mind helping out please?

    package project.ernest;

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;

 public class Part1 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
    }
    Intent DisclaimerHandler = n开发者_高级运维ew Intent(getBaseContext(), Part2.class);
    {
    Part1.this.startActivity(DisclaimerHandler);
   }
} 

I have 2 .java file, namely, Part1 and Part2. as well as a .xml file name disclaimer placed under layout

I tried to run it, but it gave me a force stop.


use like this..

 package project.ernest;

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;

 public class Part1 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

      final Button gs = (Button) findViewById(R.id.save); 
      gs.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) { 
            Intent i = new Intent(getBaseContext(), Part2.class);         
            Part1.this.startActivity(i);    
        }
    });          
} 


Hard to say anything without the logcat, but I'll try to guess. Probably you've forgot to declare your Part2 activity in your Manifest file. Hope I'm right.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜