Java 我的android应用程序在启动屏幕后停止响应
我正在编写一个包含启动屏幕的新应用程序。 我已经完成了,一切都很好。在我再次打开android studio在导航栏上工作后,我尝试运行应用程序以查看结果,但应用程序在启动屏幕显示后停止并崩溃 这是主课Java 我的android应用程序在启动屏幕后停止响应,java,android,xml,runtime-error,manifest,Java,Android,Xml,Runtime Error,Manifest,我正在编写一个包含启动屏幕的新应用程序。 我已经完成了,一切都很好。在我再次打开android studio在导航栏上工作后,我尝试运行应用程序以查看结果,但应用程序在启动屏幕显示后停止并崩溃 这是主课 package com.example.computer.bsinfoshop; public class Main extends AppCompatActivity { @Override protected void onCreate(Bundle savedIn
package com.example.computer.bsinfoshop;
public class Main extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
这是od类启动屏幕
package com.example.computer.bsinfoshop;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class Screen extends AppCompatActivity {
TextView tv;
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen);
tv = (TextView)findViewById(R.id.textView);
img = (ImageView)findViewById(R.id.imageView);
Typeface font = Typeface.createFromAsset(getAssets(),"fonts/Satisfy-Regular.ttf");
tv.setTypeface(font);
img.setImageResource(R.drawable.rsz_2rsz_img);
Thread timerThread = new Thread(){
public void run(){
try
{
sleep(3700);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
finally {
Intent intent = new Intent(Screen.this , Main.class);
startActivity(intent);
}
}
};
timerThread.start();
}
@Override
protected void onPause() {
super.onPause();
finish();
}
}
我认为问题出在这里
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.computer.bsinfoshop">
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name">
<activity
android:name=".Screen"
android:theme="@style/App">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Information"
android:label="Information"
android:theme="@style/AppTheme">
</activity>
<activity
android:name="com.example.computer.bsinfoshop.Main"
android:theme="@style/AppTheme">
</activity>
</application>
</manifest>
我只是想知道我的代码中有什么问题,以及如何修复它。谢谢^ ^将线程更改为以下内容:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
finish();
startActivity(new Intent(Screen.this, Main.class));
}
}, 1500);
老实说,我认为这不是创建初始屏幕的正确方法。这样,您会强制用户等待3秒钟,从而导致糟糕的用户体验
看看这个教程,你的用户会感谢你的 “…但是应用程序在启动屏幕显示后停止并崩溃”当发生这种情况并且您需要帮助时,您需要发布stacktrace,以便我们可以看到错误代码,只有答案很少被认为是高质量的。您应该考虑添加与代码不同的内容,以及为什么它应该解决OPS问题。这不是问题的答案。这可能是一个评论。对不起。。我没有足够的声誉对这个问题发表评论。。这就是问题所在,否则我早就这么做了。。