Brand new to android development and I wanted to test some new code that I was working on. So I launched the my app on the emulator and the splash screen loads fine.However after the 5 second timer finishes the app crashes.
This is my Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.PackageName.alarmclock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
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=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.PackageName.AlarmClock.MENU" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.PackageName.AlarmClock.ASDF" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TextPlay"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.PackageName.AlarmClock.TextPlay" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Email"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.PackageName.AlarmClock.Email" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Camera"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.PackageName.AlarmClock.Camera" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is my splash.java
OnCreate is dashed out in eclipse and I don't know why and if that is the reason for the crashing
package com.PackageName.alarmclock;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity{
MediaPlayer ourSong;
@Override
@Deprecated
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openMainActivity = new Intent("com.PackageName.AlarmClock.MENU");
startActivity(openMainActivity);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}
And if you need it, here is the Menu.Java
package com.PackageName.alarmclock;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends ListActivity{
String classes[] = { "MainActivity", "TextPlay", "Splash", "Email", "Camera", "example5", "example6"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese= classes[position];
try{
Class<?> ourClass = Class.forName("com.PackageName.AlarmClock." + cheese);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
And here is the LogCat
07-16 00:48:16.120: E/AndroidRuntime(1985): FATAL EXCEPTION: Thread-84
07-16 00:48:16.120: E/AndroidRuntime(1985): Process: com.PackageName.alarmclock, PID: 1985
07-16 00:48:16.120: E/AndroidRuntime(1985): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.PackageName.AlarmClock.MENU }
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Activity.startActivityForResult(Activity.java:3424)
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Activity.startActivityForResult(Activity.java:3385)
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Activity.startActivity(Activity.java:3627)
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Activity.startActivity(Activity.java:3595)
07-16 00:48:16.120: E/AndroidRuntime(1985): at com.PackageName.alarmclock.Splash$1.run(Splash.java:28)
Any help is appreciated as I've spent pretty much the whole day on this app and It'd suck to lose it.
尝试这个
Intent openMainActivity = new Intent(getApplicationContext(), Menu.class);
Add this to your manifest:
<activity
android:name=".Menu"
android:label="@string/app_name" >
</activity>
Call it in Intent as :
Intent openMainActivity = new Intent(Splash.this, Menu.class);
Right now what you have in your manifest is:
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
which, from the code that you have pasted, doesn't exist.
Leave alone, the ListActivity
in java file has the name "Menu" and what you declared in manifest is "MENU"
You have to use intents something like this
Intent i=new Intent(Firstactivity.this,SecondActivity.class);
startActivity(i);
Where first activity is your current activity and second activity is the one you want to move on to; but in your finally block you are doing something like
Intent openMainActivity = new Intent("com.PackageName.AlarmClock.MENU");//wrong
//you specified only one argument
startActivity(openMainActivity);
which is wrong
Change this line in Splash.java
file
Intent openMainActivity = new Intent("com.PackageName.AlarmClock.MENU");
to
Intent openMainActivity = new Intent();
openMainActivity.setClass(this, Menu.class);
And
in Menu.java file
change from
Class<?> ourClass = Class.forName("com.PackageName.AlarmClock." + cheese);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
to
Intent ourIntent = new Intent();
ourIntent.setClass(this, AlarmClock.class);
startActivity(ourIntent);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.