我支持成千上万的人说“不要使用泼水”,我明白了,但应用程序并不那么大,我只是想知道我做错了什么我认为这是我的清单但是在我的启动画面和它应该进入主页面后,我收到错误“抱歉!应用程序Grifball(进程com.grifball.info)意外停止。请再试一次。
这是我的清单。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.grifball.info"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="Splash">
<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.grifball.info.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
这是我的Splash的Java
package com.grifball.info;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
@Override
protected void onCreate(Bundle startup) {
// TODO Auto-generated method stub
super.onCreate(startup);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openMainActivity = new Intent("com.grifball.info.MAINACTIVITY");
startActivity(openMainActivity);
}
}
};
timer.start();
}
}
这是XML
<?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="@drawable/splashbg">
</LinearLayout>
这是我的Log Cat
04-03 02:39:20.527: D/AndroidRuntime(318): Shutting down VM
04-03 02:39:20.527: W/dalvikvm(318): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-03 02:39:20.537: E/AndroidRuntime(318): FATAL EXCEPTION: main
04-03 02:39:20.537: E/AndroidRuntime(318): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.grifball.info/com.grifball.info.MainActivity}: java.lang.RuntimeException: native typeface cannot be made
04-03 02:39:20.537: E/AndroidRuntime(318): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-03 02:39:20.537: E/AndroidRuntime(318): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-03 02:39:20.537: E/AndroidRuntime(318): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-03 02:39:20.537: E/AndroidRuntime(318): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-03 02:39:20.537: E/AndroidRuntime(318): at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 02:39:20.537: E/AndroidRuntime(318): at android.os.Looper.loop(Looper.java:123)
04-03 02:39:20.537: E/AndroidRuntime(318): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-03 02:39:20.537: E/AndroidRuntime(318): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 02:39:20.537: E/AndroidRuntime(318): at java.lang.reflect.Method.invoke(Method.java:521)
04-03 02:39:20.537: E/AndroidRuntime(318): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-03 02:39:20.537: E/AndroidRuntime(318): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-03 02:39:20.537: E/AndroidRuntime(318): at dalvik.system.NativeStart.main(Native Method)
04-03 02:39:20.537: E/AndroidRuntime(318): Caused by: java.lang.RuntimeException: native typeface cannot be made
04-03 02:39:20.537: E/AndroidRuntime(318): at android.graphics.Typeface.<init>(Typeface.java:147)
04-03 02:39:20.537: E/AndroidRuntime(318): at android.graphics.Typeface.createFromAsset(Typeface.java:121)
04-03 02:39:20.537: E/AndroidRuntime(318): at com.grifball.info.MainActivity.onCreate(MainActivity.java:27)
04-03 02:39:20.537: E/AndroidRuntime(318): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-03 02:39:20.537: E/AndroidRuntime(318): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-03 02:39:20.537: E/AndroidRuntime(318): ... 11 more
答案 0 :(得分:3)
在“AndroidManifest.xml”中,您应该更改此内容:
<action android:name="com.grifball.info.MAINACTIVITY" />
To This:
<action android:name="android.intent.action.MAINACTIVITY" />
而且,在“Splash.java”中,你应该改变:
Intent openMainActivity = new Intent("com.grifball.info.MAINACTIVITY");
对此:
Intent openMainActivity = new Intent(Splash.this, MainActivity.class);
答案 1 :(得分:0)
您必须进行以下更改
<activity android:name=".Splash">
<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" >
</activity>
finally{
Intent openMainActivity = new Intent(Splash.this, MainActivity.class);
startActivity(openMainActivity);
答案 2 :(得分:0)
尝试下面的代码,它应该可以。
public class Splash extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Light_NoTitleBar);
setContentView(R.layout.splash);
Handler handler = new Handler();
handler.postDelayed(new Runnable(){
public void run(){
finish();
Intent intent = new Intent(Splash.this, MainActivity.class);
Splash.this.startActivity(intent);
}
}, 2000);
}
}