遇到问题,我闪屏 [英] Having Trouble with my Splash Screen
问题描述
所以,我刚开始建立一个闪屏,将显示5秒钟,然后进入我的主菜单。我想我标记一些错误的过程中,现在我的应用程序是力闭幕。我是pretty的肯定与我的行为和我的表现的一个问题。
DragonFruitActivity.java:
包com.Dragon_Fruit;
进口android.app.Activity;
进口android.content.Intent;
进口android.media.MediaPlayer;
进口android.os.Bundle;
进口android.view.View;
进口android.view.Window;
进口android.view.WindowManager;
进口android.widget.ImageButton;
公共类DragonFruitActivity延伸活动{
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
的setContentView(R.layout.splash);
螺纹logoTimer =新的Thread(){
公共无效的run(){
尝试 {
睡眠(5000);
DragonFruitActivity.this.setContentView(R.layout.main);
}赶上(InterruptedException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}
最后 {
完();
}
}
};
logoTimer.start();
// ***按键声音*** //
最后的MediaPlayer buttonSound = MediaPlayer.create(
DragonFruitActivity.this,R.raw.button_click);
的ImageButton PLAYBUTTON =(的ImageButton)findViewById(R.id.playbutton);
playbutton.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(查看为arg0){
arg0.setBackgroundResource(R.drawable.playbuttonselected);
// TODO自动生成方法存根
buttonSound.start();
startActivity(新意图(DragonFruitActivity.this,
playbutton.class));
}
});
的ImageButton settingsbutton =(的ImageButton)findViewById(R.id.settingsbutton);
settingsbutton.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(查看为arg0){
// TODO自动生成方法存根
buttonSound.start();
startActivity(新意图(DragonFruitActivity.this,
settingsbutton.class));
}
});
}
}
火龙果清单:
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.Dragon_Fruit
安卓版code =1
机器人:VERSIONNAME =1.0
机器人:INSTALLLOCATION =preferExternal>
<应用机器人:图标=@可绘制/图标
机器人:标签=@字符串/ APP_NAME
机器人:可调试=真正的>
<活动机器人:名称=。DragonFruitActivity
机器人:标签=@字符串/ APP_NAME
机器人:screenOrientation =风景
机器人:configChanges =键盘| keyboardHidden |定位>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动机器人:PLAYBUTTONNAME =
机器人:标签=@字符串/ APP_NAME
机器人:screenOrientation =风景
机器人:configChanges =键盘| keyboardHidden |定位>
<意向滤光器>
<作用机器人:名称=com.Dragon_Fruit.PLAYBUTTON/>
<类机器人:名称=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT;
<活动机器人:settingsbuttonNAME =
机器人:标签=@字符串/ APP_NAME
机器人:screenOrientation =风景
机器人:configChanges =键盘| keyboardHidden |定位>
<意向滤光器>
<作用机器人:名称=com.Dragon_Fruit.SETTINGSBUTTON/>
<类机器人:名称=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
<使用-权限的Android:名称=android.permission.WRITE_EXTERNAL_STORAGE/>
<使用-权限的Android:名称=android.permission.WAKE_LOCK/>
<使用-SDK安卓的minSdkVersion =3安卓targetSdkVersion =9/>
< /舱单>
LogCat中:
08-06 22:46:27.942:ERROR / dalvikvm(9896):不能禁用核心文件生成的PID 9896,错误号= 1
08-06 22:46:28.271:ERROR /(5531):此文件不是ASF文件。
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):致命异常:主要
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):java.lang.RuntimeException的:无法启动的活动ComponentInfo {com.Dragon_Fruit / com.Dragon_Fruit.DragonFruitActivity}:显示java.lang.NullPointerException
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2737)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在android.app.ActivityThread.access $ 2500(ActivityThread.java:129)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2107)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在android.os.Handler.dispatchMessage(Handler.java:99)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在android.os.Looper.loop(Looper.java:143)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在android.app.ActivityThread.main(ActivityThread.java:4701)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在java.lang.reflect.Method.invokeNative(本机方法)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在java.lang.reflect.Method.invoke(Method.java:521)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在dalvik.system.NativeStart.main(本机方法)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):由:显示java.lang.NullPointerException
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在com.Dragon_Fruit.DragonFruitActivity.onCreate(DragonFruitActivity.java:44)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
08-06 22:46:28.364:ERROR / AndroidRuntime(9896):11 ...更多
在你的线程,尝试改变:
意图DragonFruitActivityIntent =新的意向书(主);
到
意图DragonFruitActivityIntent =新的意图(DragonFruitActivity.this,NameOfActivityToStart.class);
另外,如果你想改变布局,而不是开始一个新的活动,删除:
意图DragonFruitActivityIntent =新的意向书(主);
startActivity(DragonFruitActivityIntent);
,而是写:
DragonFruitActivity.this.setContentView(R.layout.main);
顺便说一句,这将是更好,如果,而不是睡5秒,该线程做一些有用的东西,比如加载一些数据,为您的应用程序 - 否则它只是放慢访问你的应用程序没有任何理由
编辑:尝试从的onCreate()来ONSTART()将所有的code,所以它是这样的:
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
的setContentView(R.layout.splash);
}
@覆盖
公共无效的OnStart(){
super.onStart()
螺纹logoTimer =新的Thread(){
... //你的code,其余在这里
}
您可能会遇到访问UI问题它完全形成之前。
So I just started to set up a splash screen that would show for 5 seconds and then go to my main menu. I think I labeled something wrong in the process and now my app is force closing. I'm pretty sure its a problem with my activity and my manifest.
DragonFruitActivity.java:
package com.Dragon_Fruit;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
public class DragonFruitActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread logoTimer = new Thread() {
public void run() {
try {
sleep(5000);
DragonFruitActivity.this.setContentView(R.layout.main);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
finish();
}
}
};
logoTimer.start();
// ***BUTTON SOUND***//
final MediaPlayer buttonSound = MediaPlayer.create(
DragonFruitActivity.this, R.raw.button_click);
ImageButton playbutton = (ImageButton) findViewById(R.id.playbutton);
playbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
arg0.setBackgroundResource(R.drawable.playbuttonselected);
// TODO Auto-generated method stub
buttonSound.start();
startActivity(new Intent(DragonFruitActivity.this,
playbutton.class));
}
});
ImageButton settingsbutton = (ImageButton) findViewById(R.id.settingsbutton);
settingsbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
buttonSound.start();
startActivity(new Intent(DragonFruitActivity.this,
settingsbutton.class));
}
});
}
}
Dragon Fruit Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Dragon_Fruit"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal">
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true">
<activity android:name=".DragonFruitActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".playbutton"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation">
<intent-filter>
<action android:name="com.Dragon_Fruit.PLAYBUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".settingsbutton"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation">
<intent-filter>
<action android:name="com.Dragon_Fruit.SETTINGSBUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="9" />
</manifest>
LogCat:
08-06 22:46:27.942: ERROR/dalvikvm(9896): could not disable core file generation for pid 9896, errno=1
08-06 22:46:28.271: ERROR/(5531): This file is not ASF file.
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): FATAL EXCEPTION: main
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Dragon_Fruit/com.Dragon_Fruit.DragonFruitActivity}: java.lang.NullPointerException
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2737)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at android.app.ActivityThread.access$2500(ActivityThread.java:129)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at android.os.Looper.loop(Looper.java:143)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at android.app.ActivityThread.main(ActivityThread.java:4701)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at java.lang.reflect.Method.invoke(Method.java:521)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at dalvik.system.NativeStart.main(Native Method)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): Caused by: java.lang.NullPointerException
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at com.Dragon_Fruit.DragonFruitActivity.onCreate(DragonFruitActivity.java:44)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
08-06 22:46:28.364: ERROR/AndroidRuntime(9896): ... 11 more
In your thread, try changing:
Intent DragonFruitActivityIntent = new Intent("main");
to:
Intent DragonFruitActivityIntent = new Intent(DragonFruitActivity.this, NameOfActivityToStart.class);
Alternatively, if you want to change the layout rather than starting a new activity, remove:
Intent DragonFruitActivityIntent = new Intent("main");
startActivity(DragonFruitActivityIntent);
and instead write:
DragonFruitActivity.this.setContentView(R.layout.main);
Incidentally, it would be better if rather than sleeping for 5 seconds, the thread did something useful like load some data for your app - otherwise it's just slowing down access to your app for no reason.
Edit: Try moving all your code from onCreate() to onStart(), so it's like this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
}
@Override
public void onStart() {
super.onStart()
Thread logoTimer = new Thread() {
... // the rest of your code here
}
You may be experiencing problems accessing the UI before it's fully formed.
这篇关于遇到问题,我闪屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!