每当我启动该应用程序时,它会说这是错误报告
Unfortunately, {app-name} has stopped
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2413)
at android.app.ActivityThread.access$800 (ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1317)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:135)
at android.app.ActivityThread.main (ActivityThread.java:5343)
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:905)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:700)
原因:android.view.InflateException:
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:763)
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView (AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:139)
at com.khokhar.yousaf.cipher.Splash.onCreate (Splash.java:15)
at android.app.Activity.performCreate (Activity.java:6010)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2292)
原因:android.content.res.Resources $ NotFoundException:
at android.content.res.Resources.loadDrawableForCookie (Resources.java:2444)
at android.content.res.Resources.loadDrawable (Resources.java:2384)
at android.content.res.TypedArray.getDrawable (TypedArray.java:749)
at android.view.View.<init> (View.java:3742)
at android.widget.ImageView.<init> (ImageView.java:149)
at android.widget.ImageView.<init> (ImageView.java:145)
at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:71)
at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:67)
at android.support.v7.app.AppCompatViewInflater.createImageView (AppCompatViewInflater.java:181)
at android.support.v7.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:105)
at android.support.v7.app.AppCompatDelegateImplV9.createView (AppCompatDelegateImplV9.java:1035)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView (AppCompatDelegateImplV9.java:1092)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:725)
这是我的启动画面编码
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Window;
public class Splash extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_splash);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
//thread for splash screen running
Thread logoTimer = new Thread() {
public void run() {
try {
sleep(2500);
} catch (InterruptedException e) {
Log.d("Exception", "Exception" + e);
} finally {
startActivity(new Intent(Splash.this, MainActivity.class));
}
finish();
}
};
logoTimer.start();
}
}
和这个XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/splashScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorPrimary"
android:orientation="vertical"
tools:context="com.khokhar.yousaf.cipher.Splash">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@drawable/ic_launcher_foreground"
android:contentDescription="@string/app_name"
android:scaleType="fitXY"
android:src="@drawable/mediumload" />
</RelativeLayout>
我使用的可绘制图像为600x1024 PNG
list
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.khokhar.yousaf.cipher">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:fullBackupContent="true"
android:hardwareAccelerated="true"
android:icon="@drawable/cee"
android:label="@string/app_name"
android:roundIcon="@drawable/cee"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "java-lang-programming://android-app-google-plus-demo"-->
<data
android:host="cipherengineers"
android:scheme="android-app-cipher-engineers" />
</intent-filter>
</activity>
<activity android:name=".Splash"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
我的MainActivity基本上是网络 View
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
ProgressBar progressBar;
WebView webView;
String url="https://website/";
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
webView = (WebView) findViewById(R.id.webView);
textView = (TextView) findViewById(R.id.textView1212);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
textView.setText(progress + "");
}
@Override
public boolean onCreateWindow(WebView view, boolean isDialog,
boolean isUserGesture, Message resultMsg) {
WebView newWebView = new WebView(MainActivity.this);
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setSupportZoom(true);
newWebView.getSettings().setBuiltInZoomControls(true);
newWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
newWebView.getSettings().setSupportMultipleWindows(true);
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
return true;
}
});
webView.setWebViewClient(new MyWebViewClient());
WebSettings browserSetting = webView.getSettings();
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
browserSetting.setJavaScriptCanOpenWindowsAutomatically(true);
browserSetting.setJavaScriptEnabled(true);
browserSetting.setLoadWithOverviewMode(true);
browserSetting.setSupportMultipleWindows(true);
browserSetting.setDatabaseEnabled(true);
browserSetting.setAppCacheEnabled(true);
browserSetting.setDomStorageEnabled(true);
browserSetting.setDomStorageEnabled(true);
browserSetting.setGeolocationEnabled(true);
browserSetting.setSaveFormData(false);
browserSetting.setUseWideViewPort(true);
browserSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
browserSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
browserSetting.setDomStorageEnabled(true);
if (android.os.Build.VERSION.SDK_INT >= 21) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
}else {
CookieManager.getInstance().setAcceptCookie(true);
}
webView.loadUrl(url);
}
private class MyWebViewClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progressBar.setVisibility(View.INVISIBLE);
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
public void onBackPressed() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
MainActivity.this);
// set title
alertDialogBuilder.setTitle("Exit");
// set dialog message
alertDialogBuilder
.setMessage("Are You Sure?")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.GRAY));
}
}
我从启动画面XML中删除了背景,但没有任何效果
MainActivity XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/loading_screen"
android:orientation="vertical"
tools:context="com.khokhar.yousaf.cipher.MainActivity">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="218dp"
android:progressTint="?android:attr/fastScrollTextColor"
android:visibility="invisible" />
<TextView
android:id="@+id/textView1212"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="23dp"
android:textColor="@android:color/holo_red_dark"
android:textSize="13sp"
android:textStyle="bold|italic" />
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:animationCache="true"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="41dp" />
</RelativeLayout>
我不知道。
最佳答案
从中删除background
ImageView
原因是较低的版本无法在 drawable-v24中实际存在的 drawable 目录中找到ic_launcher_foreground。
关于java - 应用程序可在Nougat +版本上运行,但在棉花糖和 Lollipop 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51797665/