当前位置: 代码迷 >> Android >> 【小弟我页面跳转老是出错,快崩溃了,求破】
  详细解决方案

【小弟我页面跳转老是出错,快崩溃了,求破】

热度:75   发布时间:2016-05-01 21:08:18.0
【我页面跳转老是出错,快崩溃了,求破】
我使用的是android应用开发揭秘这本书,书中的源代码是1.5SDK下编写的,我的eclipse是3.72 SDK2.2。我把书中的工程导入后,修改SDK到2.2运行可以点击按钮进行两个页面的跳转,但是我自己在SDK2.2重写了一遍后,再运行就一直应用意外停止,昨天晚上就一直出现这个错误。我开始开以为是我代码写错了。然后我按照书中的元代复制了一遍,不管是AndroidManiFest.xml还是两个acitvity的源代码,以及string.xml main.xml main2.xml 结果用模拟器运行老是应用程序意外停止。然后我又用我的手机试了,还是意外停止。然后我注释掉跳转的那部分代码后,可以运行了。 但是为什么一样的代码我的就不行?我不知道我跳转的那部分代码哪里写错了。快崩溃了,各位帮忙快点解救我。。。
Activity01.java

Java code
package com.faith;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;public class Activity01 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.Button1);        button.setOnClickListener(new Button.OnClickListener()        {            public void onClick(View v)            {                /* 新建一个Intent对象 */                Intent intent = new Intent();                /* 指定intent要启动的类 */                intent.setClass(Activity01.this, Activity02.class);                /* 启动一个新的Activity */                startActivity(intent);                /* 关闭当前的Activity */                Activity01.this.finish();            }        });    }}


Activity02.java
Java code
package com.faith;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{    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState)    {        super.onCreate(savedInstanceState);        setContentView(R.layout.main2);        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, Activity01.class);                /* 启动一个新的Activity */                startActivity(intent);                /* 关闭当前的Activity */                Activity02.this.finish();            }        });    }}


main.xml
XML code
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:name="@+id/TextView1"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/app_name"/>    <Button        android:name="@+id/Button1"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/exchange"/></LinearLayout>


main2.xml

XML code
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:name="@+id/TextView2"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/app2_name"/>    <Button        android:name="@+id/Button2"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/exchange"/></LinearLayout>
  相关解决方案