[英]App crashes after splash screen
Brand new to android development and I wanted to test some new code that I was working on. android开发的新手,我想测试一些我正在开发的新代码。 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.
所以我在模拟器上启动了我的应用程序,启动屏幕加载正常,但是5秒计时器结束后,应用程序崩溃了。
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 这是我的splash.java
OnCreate is dashed out in eclipse and I don't know why and if that is the reason for the crashing 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();
}
}
And if you need it, here is the Menu.Java 如果需要的话,这里是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 这是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中将其称为:
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" ListActivity
,java文件中的ListActivity
的名称为“ Menu”,清单中声明的名称为“ 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
但是在您的finally块中,您正在做类似
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 在
Splash.java
文件中更改此行
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 在
Menu.java file
从
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.