问题
Ok so.. when I plug in my phone to the computer it starts the application and after the sleep() is finished it crashes with the error shown at the bottom. All of my code which I think you will need is shown in the quotations.
Really baffled Why I am getting this problem. I have my mainActivity.java file looking like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread timer = new Thread(){
public void run(){
try{
sleep(1000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent("com.worcestershire.android.Pagetwo", null);
startActivity(intent);
}
}
};
timer.start();}
Page 2 looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@raw/logo"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="This is Activity 2" />
<Button android:text="Previous"
android:id="@+id/Button02"
android:layout_width="250px"
android:textSize="18px"
android:layout_height="55px">
</Button>
</LinearLayout>
And my manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.worcestershire.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/maps_launcher"
android:label="@string/app_name" >
<activity
android:name="com.worcestershire.android.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=".PAGETWO"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
Heres the log:
01-04 12:27:05.711: W/dalvikvm(25483): threadid=9: thread exiting with uncaught exception (group=0x4001d5a0)
01-04 12:27:05.711: E/AndroidRuntime(25483): FATAL EXCEPTION: Thread-10
01-04 12:27:05.711: E/AndroidRuntime(25483): android.content.ActivityNotFoundException: No
Activity found to handle Intent { act=com.worcestershire.android.Pagetwo }
01-04 12:27:05.711: E/AndroidRuntime(25483): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1569)
01-04 12:27:05.711: E/AndroidRuntime(25483): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1539)
01-04 12:27:05.711: E/AndroidRuntime(25483): at android.app.Activity.startActivityForResult(Activity.java:2901)
01-04 12:27:05.711: E/AndroidRuntime(25483): at android.app.Activity.startActivity(Activity.java:3007)
01-04 12:27:05.711: E/AndroidRuntime(25483): at com.worcestershire.android.MainActivity$1.run(MainActivity.java:43)
Any help will be of use. Cheers!
回答1:
Your activity name in Manifest should be absolutely the same as when you call it. If The activity class is called Pagetwo then the android:name=".Pagetwo" attribute should be in your Manifest. Hope this helps.
回答2:
I think you need to specify activity name with package in manifest.
回答3:
Please Add Page2 Activity in your manifest file, and Use Following code in your mainActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread timer = new Thread(){
public void run(){
try{
sleep(1000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(MainActivity.this, Page2.class);
startActivity(intent);
}
}
};
timer.start();}
回答4:
Well here is the problem...
No Activity found to handle Intent { act=com.worcestershire.android.Pagetwo }
You're probably getting this error because you've not added the class as an activity in the manifest. For more information look here: Using Intent in an Android application to show another activity
Also your intent looks wrong. You want it to look something like this:
new Intent(CurrentActivity.this, NextActivity.class);
Where CurrentActivity and NextActivity are the names of the classes of the activities you are IN and WANT TO GO TO respectively.
回答5:
u dont need to repeat ur whole package while declaring activity, only .ActivityName will work
Intent intent = new Intent(this, NextActivityTobeCalled.class);
startActivity(intent);
来源:https://stackoverflow.com/questions/8726933/starting-a-new-activity-but-i-get-an-activitynotfoundexception