kkxiaoxian
kkxiaoxian
2017-04-08 00:59

安卓入门,一个有关页面跳转的程序闪退

15
  • android

做了两个页面,通过按钮跳转。跳转时闪退。个人感觉时第二个页面的声明出了问题,但是找不出解决办法,求大神帮看看,感谢

debug
线程 [main](已暂挂(异常 ActivityNotFoundException))

Instrumentation.checkStartActivityResult(int, Object) 行: 1879

Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int, Bundle) 行: 1546
Activity1(Activity).startActivityForResult(Intent, int, Bundle) 行: 4284
Activity1(Activity).startActivityForResult(Intent, int) 行: 4231
Activity1(Activity).startActivity(Intent, Bundle) 行: 4568

Activity1(Activity).startActivity(Intent) 行: 4536

Activity1$1.onClick(View) 行: 28
Button(View).performClick() 行: 5698
Button(TextView).performClick() 行: 10896

View$PerformClick.run() 行: 22565

Handler.handleCallback(Message) 行: 739

ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) 行: 95

Looper.loop() 行: 148

ActivityThread.main(String[]) 行: 7224

Method.invoke(Object, Object...) 行: 不可用 [本机方法]

ZygoteInit$MethodAndArgsCaller.run() 行: 1230

ZygoteInit.main(String[]) 行: 1120

报错
04-08 08:51:19.992: E/AndroidRuntime(24556): FATAL EXCEPTION: main
04-08 08:51:19.992: E/AndroidRuntime(24556): Process: com.example.secondact, PID: 24556
04-08 08:51:19.992: E/AndroidRuntime(24556): android.content.ActivityNotFoundException: No Activity found to handle Intent { }
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1879)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1546)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.app.Activity.startActivityForResult(Activity.java:4284)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.app.Activity.startActivityForResult(Activity.java:4231)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.app.Activity.startActivity(Activity.java:4568)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.app.Activity.startActivity(Activity.java:4536)
04-08 08:51:19.992: E/AndroidRuntime(24556): at com.example.secondact.Activity1$1.onClick(Activity1.java:28)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.view.View.performClick(View.java:5698)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.widget.TextView.performClick(TextView.java:10896)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.view.View$PerformClick.run(View.java:22565)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.os.Handler.handleCallback(Handler.java:739)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.os.Handler.dispatchMessage(Handler.java:95)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.os.Looper.loop(Looper.java:148)
04-08 08:51:19.992: E/AndroidRuntime(24556): at android.app.ActivityThread.main(ActivityThread.java:7224)
04-08 08:51:19.992: E/AndroidRuntime(24556): at java.lang.reflect.Method.invoke(Native Method)
04-08 08:51:19.992: E/AndroidRuntime(24556): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
04-08 08:51:19.992: E/AndroidRuntime(24556): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Manifest
<?xml version="1.0" encoding="utf-8"?>
package="com.example.secondact"
android:versionCode="1"
android:versionName="1.0" >
android:minSdkVersion="19"
android:targetSdkVersion="19" />
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:label="@string/app_name">








第一页面代码
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Activity1 extends Activity 
{ 
 public void onCreate(Bundle savedInstanceState) 
 { 

 super.onCreate(savedInstanceState); 
 /* 设置显示main.xml布局*/ 
 setContentView(R.layout.main); 
 /* findViewById(R.id.button1)取得布局main.xml中的button1 */ 
 Button button = (Button) findViewById(R.id.button1); 
 /* 监听button的事件信息*/ 
 button.setOnClickListener(new Button.OnClickListener() { 
 public void onClick(View v)   {   /* 新建一个Intent对象*/ 
 Intent intent = new Intent();   /* 指定intent要启动的类*/ 




 startActivity(intent);   /* 关闭当前的Activity */ 


 intent.setClass(Activity1.this, Activity02.class);   /* 启动一个新的Activity */ 

 Activity1.this.finish();   }   }); 
 } 
}


第二页面代码
import android.app.Activity; 

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Activity02 extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* 设置显示main2布局*/
setContentView(R.layout.main2);
/* findViewById(R.id.button2)取得布局main.xml中的button2 /
Button button = (Button) findViewById(R.id.button2);
/
监听button的事件信息*/
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) { /* 新建一个Intent对象*/
Intent intent = new Intent(); /* 指定intent要启动的类*/
intent.setClass(Activity02.this, Activity1.class); /* 启动一个新的Activity */

/* startActivity(intent); /* 关闭当前的Activity */

Activity02.this.finish(); } });
}
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐