gpt4 book ai didi

android: 初始屏幕上的空指针

转载 作者:行者123 更新时间:2023-11-29 15:29:47 25 4
gpt4 key购买 nike

我正在制作一个应用程序,我必须在启动画面中实现alpha 效果,当我加载图像时它会出现空指针异常。启动动画时的基本问题.如果我删除开始动画那么我的动画根本不会开始。我真的卡住了。任何帮助将不胜感激。我的代码如下:

public class SplashScreen extends Activity {


private Thread mSplashThread;

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


System.out.println("hello");
setContentView(R.layout.splash);

final SplashScreen sPlashScreen = this;

Animation a1 = AnimationUtils.loadAnimation(this, R.anim.alpha);
LinearLayout Ll=(LinearLayout)findViewById(R.id.mainLayoutheader);
System.out.println("hello1");
Ll.startAnimation(a1);
System.out.println("hello2");


// The thread to wait for splash screen events
mSplashThread = new Thread(){
@Override
public void run(){
try {
synchronized(this){
// Wait given period of time or exit on touch

// a.reset();


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

finish();

// Run next activity
Intent intent = new Intent();
intent.setClass(sPlashScreen, Main.class);
startActivity(intent);
stop();
}
};

mSplashThread.start();
}

}

异常在 L1.startAnimation(a1);

最佳答案

我猜你忘了调用 setContentView。您必须在调用 findViewById 之前执行此操作 [编辑:此处未解决问题]

关于android: 初始屏幕上的空指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8120603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com