全新的Android开发,我想测试一些我正在研究的新代码。所以我在模拟器上启动了我的应用程序,并且启动画面加载正常。但是,在5秒计时器完成后应用程序崩溃。
这是我的清单文件
<?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>
这是我的splash.java
OnCreate在日食中消失了,我不知道为什么以及是否是导致崩溃的原因
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();
}
}
如果你需要它,这里是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();
}
}
}
这是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)
任何帮助都表示赞赏,因为我在这个应用程序上度过了整整一天的时间,而且它会失去它。
答案 0 :(得分:1)
试试这个
Intent openMainActivity = new Intent(getApplicationContext(), Menu.class);
答案 1 :(得分:1)
将此添加到您的清单:
<activity
android:name=".Menu"
android:label="@string/app_name" >
</activity>
在Intent中将其称为:
Intent openMainActivity = new Intent(Splash.this, Menu.class);
现在你的清单中有:
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
,从您粘贴的代码中,它不存在。
单独留下,java文件中的ListActivity
名称为“Menu”,您在清单中声明的内容为“MENU”
答案 2 :(得分:0)
你必须使用像这样的意图
Intent i=new Intent(Firstactivity.this,SecondActivity.class);
startActivity(i);
第一项活动是您当前的活动,第二项活动是您想要继续活动的活动;但是在你的finally块中,你正在做类似
的事情 Intent openMainActivity = new Intent("com.PackageName.AlarmClock.MENU");//wrong
//you specified only one argument
startActivity(openMainActivity);
这是错误的
答案 3 :(得分:0)
在Splash.java
档案
Intent openMainActivity = new Intent("com.PackageName.AlarmClock.MENU");
到
Intent openMainActivity = new Intent();
openMainActivity.setClass(this, Menu.class);
和
在Menu.java file
更改
Class<?> ourClass = Class.forName("com.PackageName.AlarmClock." + cheese);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
到
Intent ourIntent = new Intent();
ourIntent.setClass(this, AlarmClock.class);
startActivity(ourIntent);