添加启动画面后Android应用程序强制关闭
Posted
技术标签:
【中文标题】添加启动画面后Android应用程序强制关闭【英文标题】:Android app force closing after adding Splash Screen 【发布时间】:2017-02-23 02:26:31 【问题描述】:您好,在我开始将此启动画面添加到我的项目之前,我创建了一个运行良好的项目。我不明白为什么当我在模拟器中运行它时它会强制关闭。
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.acrcloud.rec.demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity">
</activity>
<activity android:name=".SplashScreen"
android:noHistory="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PageActivity"/>
</application>
</manifest>
这是我的 SplashScreen.java 和 XML 文件名 splash_screen.xml
package com.acrcloud.rec.demo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends Activity
private static int splashInterval = 2000;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable()
@Override
public void run()
Intent i = new Intent(SplashScreen.this,MainActivity.class);
startActivity(i);
this.finish();
private void finish()
//TODO Auto
,splashInterval);
;
LogCat 错误:`
10-13 13:14:33.068 12422-12422/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.acrcloud.rec.demo, PID: 12422
java.lang.RuntimeException: Unable to startactivityComponentInfocom.acrcloud.rec.demo/com.acrcloud.rec.demo.SplashScreen: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.ImageView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2144)
at com.acrcloud.rec.demo.SplashScreen.onCreate(SplashScreen.java:12)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_
android:layout_>
<ImageView
android:src="@drawable/logo"
android:layout_
android:layout_
android:scaleType="fitXY" />
</LinearLayout>
【问题讨论】:
分享 xml com.acrcloud.rec.demo.SplashScreen 您的xml
或SplashScreen
存在问题,请在此处发布其布局
添加你的启动 xml
我添加了一个启动画面.xml。谢谢
【参考方案1】:
尝试以下方法: - 添加新屏幕后可能需要清理和重新构建应用程序。 - 在设备而非模拟器上运行应用程序,如果出现相同结果,请反馈给我。
【讨论】:
我正在清理并重新构建项目。然后再次在设备上运行应用程序。但它显示了相同的结果。 (不幸的是,Myapp 已停止。)以上是关于添加启动画面后Android应用程序强制关闭的主要内容,如果未能解决你的问题,请参考以下文章