gpt4 book ai didi

java - 启动画面结束后应用程序不断崩溃

转载 作者:行者123 更新时间:2023-12-01 21:26:16 26 4
gpt4 key购买 nike

我目前正在开发一个应用程序,其中包含带有声音的启动屏幕。启动画面完成后,我希望它能够进入我的主菜单。我遇到的问题是播放声音后它不断崩溃。我尝试过以不同的方式处理具有相同问题的其他线程,但它在启动屏幕结束时不断崩溃。

编辑:当我运行应用程序时,我的事件日志显示应用程序成功并且没有发现错误。我运行了调试器,它显示

E/ArrayAdapter: You must supply a resource ID for a TextView
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.finalproject, PID: 12755
java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView

Caused by: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:388)

我相信一定是我的 MainActivity 引起了问题。

我的启动代码:

public class SplashActivity extends AppCompatActivity {

MediaPlayer ourSound;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);

Thread timer = new Thread(){
@Override
public void run(){
try {
ourSound = MediaPlayer.create(SplashActivity.this, R.raw.splashsound);
ourSound.start();
sleep(4000);
} catch (InterruptedException e){

} finally {
Intent i = new Intent(SplashActivity.this, MainActivity.class);
startActivity(i);
} // end finally
} // end run
};
timer.start();
} // end onCreate
@Override

protected void onPause(){
super.onPause();
ourSound.release();

} // end onPause
} // end SplashActivity

我的主要 Activity 代码:

public class MainActivity extends ListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
String[] mainMenu = {"Websites", "Directions", "Scheduling", "Photos"};
setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_main, mainMenu));
} // end onCreate

protected void onListItemClick(ListView l, View v, int position, long id) {
switch (position) {
case 0:
startActivity(new Intent(MainActivity.this, Websites.class));
break;
case 1:
startActivity(new Intent(MainActivity.this, Directions.class));
break;
case 2:
startActivity(new Intent(MainActivity.this, Scheduling.class));
break;
case 3:
startActivity(new Intent(MainActivity.this, Photos.class));
break;
} // end switch
}// end onListItemClick
} // end MainActivity

最佳答案

这应该适合你

setListAdapter(new ArrayAdapter(this, R.layout.activity_main, mainMenu));

问题出在 R.layout.activity_main 上。应该是R.layout.simple_list_item

关于java - 启动画面结束后应用程序不断崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58831547/

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