Android 我的闪屏有问题吗

Android 我的闪屏有问题吗,android,eclipse,Android,Eclipse,所以我刚开始设置一个启动屏幕,显示5秒钟,然后进入我的主菜单。我想我在这个过程中标注了一些错误,现在我的应用程序正在强制关闭。我很确定我的活动和清单有问题 DragonFutureActivity.java: package com.Dragon_Fruit; import android.app.Activity; import android.content.Intent; import android.media.MediaPlayer; import android.os.Bundl

所以我刚开始设置一个启动屏幕,显示5秒钟,然后进入我的主菜单。我想我在这个过程中标注了一些错误,现在我的应用程序正在强制关闭。我很确定我的活动和清单有问题

DragonFutureActivity.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));
            }

        });
    }
}
龙果舱单:

<?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>

在您的线程中,尝试更改:

 Intent DragonFruitActivityIntent = new Intent("main");
致:

或者,如果要更改布局而不是启动新活动,请删除:

Intent DragonFruitActivityIntent = new Intent("main");
startActivity(DragonFruitActivityIntent);
而是写:

DragonFruitActivity.this.setContentView(R.layout.main);
顺便说一句,与其睡5秒钟,不如让线程做一些有用的事情,比如为你的应用程序加载一些数据——否则它只是无缘无故地减慢了对你的应用程序的访问

编辑:尝试将所有代码从onCreate()移动到onStart(),如下所示:

@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
}

在UI完全形成之前,您可能在访问它时遇到问题。

正如您的日志猫所建议的那样

at com.Dragon_Fruit.DragonFruitActivity.onCreate(DragonFruitActivity.java:44)
您的活动文件中有一些问题。在OnCreate回调内的第44行


我想删除它可以解决NullpointerException的问题

您是否有强制关闭的logcat输出?请参阅错误日志,这可能会有所帮助…抱歉。我加上了。不,不,运气不好:(你签出我的清单了吗?会有问题吗?我已经看过你的清单了,我不这么认为,因为错误是一个空指针异常。如果是清单问题,很可能是其他问题。我认为你的清单唯一的错误是你的
使用权限
使用sdk
标记。)ld位于
应用程序标记的上方,而不是下方。但是,您在清单中使用了许多我没有使用过的内容,因此我可能遗漏了一些以前从未出现过问题的内容。我不确定问题是什么…但无论如何感谢您的帮助。没问题-抱歉,我无法提供更多帮助,我无法真正了解专业人士的想法问题是。请记住,在调试时,查看logcat输出,并查找它首先列出一个文件的位置。双击该语句,它会将您带到文件和错误行。这通常是您的问题所在。如果您被卡住,请发布文件和logcat输出中的代码,并用t突出显示该行在错误上添加注释(例如,在其旁边添加注释)。这将帮助人们回答您的问题。
@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
}
at com.Dragon_Fruit.DragonFruitActivity.onCreate(DragonFruitActivity.java:44)