无法启动活动组件信息java.lang.nullpointerexception需要帮助吗?

无法启动活动组件信息java.lang.nullpointerexception需要帮助吗?,java,android,android-activity,nullpointerexception,Java,Android,Android Activity,Nullpointerexception,嗨,我昨天刚开始学习在android上开发。我的应用程序每次启动前都会停止 我做了一些研究,所以我看了一下我的日志。这是我的日志: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: java.lang.NullPointerException at

嗨,我昨天刚开始学习在android上开发。我的应用程序每次启动前都会停止

我做了一些研究,所以我看了一下我的日志。这是我的日志:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
E/AndroidRuntime(26645):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
E/AndroidRuntime(26645):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
E/AndroidRuntime(26645):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
E/AndroidRuntime(26645):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(26645):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(26645):    at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
我有一节课:

package com.example.myfirstapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        Thread logo = new Thread (){
            public void run(){
                try{
                    int logoTimer = 0;
                    while (logoTimer <= 5000){
                        sleep(100);
                        logoTimer = logoTimer + 100;
                    }
                    Intent startActivity = new Intent();
                    startActivity.setClassName("com.example.myfirstapp", "CLEARSCREEN");
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }finally{
                    finish();
                }
            }
        };
        getActionBar().hide();
        logo.run();
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }

    @Override
    protected void onRestart() {
        // TODO Auto-generated method stub
        super.onRestart();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
    }
}
package com.example.myfirstapp;
导入android.app.Activity;
导入android.content.Intent;
导入android.os.Bundle;
公共类MainActivity扩展了活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
螺纹徽标=新螺纹(){
公开募捐{
试一试{
int logoTimer=0;
同时(logoTimer
您应该创建两个活动。第一个是启动屏幕活动,第二个是主活动。我在清单文件中只看到一个。使用intent to SecondActivity.class

更好地使用同步的安全方法编写代码,例如:

私有线程mSplashThread

@Override  
public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  

    setContentView(R.layout.splashscreen);  

    final SplashScreen sPlashScreen = this;     

    mSplashThread =  new Thread(){  
        @Override  
        public void run(){  
            try {  
                synchronized(this){  

                wait(3000);  
                }  
            }  
            catch(InterruptedException ex){                      
            }  

            finish();  

            Intent intent = new Intent();  
            intent.setClass(sPlashScreen, MainActivity.class);  
            startActivity(intent);  

        }  
    };  

    mSplashThread.start();          
} 

尝试在线程构造函数中放置一个
Runnable
@Override  
public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  

    setContentView(R.layout.splashscreen);  

    final SplashScreen sPlashScreen = this;     

    mSplashThread =  new Thread(){  
        @Override  
        public void run(){  
            try {  
                synchronized(this){  

                wait(3000);  
                }  
            }  
            catch(InterruptedException ex){                      
            }  

            finish();  

            Intent intent = new Intent();  
            intent.setClass(sPlashScreen, MainActivity.class);  
            startActivity(intent);  

        }  
    };  

    mSplashThread.start();          
}