今天做android开发一个小项目怎么都调不通,然后就随便建了个测试用例,发现startActivity函数竟然总是出错,我已经在AndroidManifest.xml 对新建的页面进行的注册了,但是依然不行不知道是什么原因,现在贴出来代码请大家指教!
Activity01代码package An.Android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class TestA extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button to_anoter = (Button) findViewById(R.id.button1); //测试打开新的activity
        to_anoter.setOnClickListener(new OnClickListener()
        {
     public void onClick(View v) 
     {
     // TODO Auto-generated method stub     Intent intent0 = new Intent(TestA.this,anotherActivity.class);            
                setTitle("test");   
                startActivity(intent0);  
                TestA.this.finish();
                //CityWeather.this.finish();
     }
        
        });
    }
    
   
}对应的mian.xml文件如下<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<Button android:text="试试" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>Activity02的代码如下:package An.Android;import android.app.Activity;
import android.os.Bundle;public class anotherActivity extends Activity{
/** Called when the activity is first created. */
    @Override
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.another);
    };}
对应的xml文件如下:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="你好啊!"
    /></LinearLayout>AndroidManifest.xml 对应如下:<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="An.Android"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".TestA"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <activity android:name=".another" android:label="activityFrameLayout">   
         <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>    </application>
</manifest>请大家指教一下 为什么调试不通 很奇怪在线等 谢谢

解决方案 »

  1.   

    你的两个activity都是MAIN, 那么加载哪一个呢?
      

  2.   

    那我把第二个 <action android:name="android.intent.action.MAIN" />
    改成 <action android:name="android.intent.action.DEFAULT" />之后还是不行啊,这个应该不是问题的关键吧,activity1的页面已经正常打开了,只是在单机按钮的时候会出现错误
      

  3.   

    <activity android:name=".anotherActivity" android:label="activityFrameLayout"> 
      

  4.   

    谢谢 fontlose, 哎!今天晕了,怎么会犯这种错误呢,我差点准备重新搭建一次android环境...谢谢
      

  5.   

    我的也是同样的错误,请问如何修改,请高手赐教。
    Intent intent = new Intent(MainActivity.this,ResultActivity.class);
    intent.putExtra("data", b);
    startActivity(intent);
    我已在Manefest.xml中注册
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".MainActivity"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".ResultActivity"
                      android:label="@string/app_result">
            </activity>

    </application>
    怎么还是不行呢?程序异常终止