java - 例外:在 Android OREO 中的 android.graphics.drawable.AdaptiveIconDrawable.isProjected
问题描述
我在 Play 商店中有一个应用程序。我每天都会在我的应用程序中收到 NullPointerException,但我不知道它来自哪里。因为,日志不包含我创建的类中的任何行。你能帮我找出它的来源吗?
java.lang.NullPointerException:
at android.graphics.drawable.AdaptiveIconDrawable.isProjected(AdaptiveIconDrawable.java:551)
at android.view.View.invalidateInternal (View.java:16640)
at android.view.View.invalidate (View.java:16600)
at android.view.View.setFrame (View.java:20945)
at android.widget.ImageView.setFrame (ImageView.java:1208)
at android.view.View.layout (View.java:20838)
at android.widget.LinearLayout.setChildFrame (LinearLayout.java:1791)
at android.widget.LinearLayout.layoutHorizontal (LinearLayout.java:1780)
at android.widget.LinearLayout.onLayout (LinearLayout.java:1546)
at android.view.View.layout (View.java:20841)
at android.view.ViewGroup.layout (ViewGroup.java:6401)
at android.widget.ListView.setupChild (ListView.java:2309)
at android.widget.ListView.makeAndAddView (ListView.java:2202)
at android.widget.ListView.fillDown (ListView.java:824)
at android.widget.ListView.fillGap (ListView.java:788)
at android.widget.AbsListView.trackMotionScroll (AbsListView.java:8184)
at android.widget.ListView.trackMotionScroll (ListView.java:2116)
at android.widget.AbsListView$FlingRunnable.run (AbsListView.java:7607)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:911)
at android.view.Choreographer.doCallbacks (Choreographer.java:723)
at android.view.Choreographer.doFrame (Choreographer.java:655)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback (Handler.java:789)
at android.os.Handler.dispatchMessage (Handler.java:98)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6940)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
这是另一份报告。但我认为其原因与上述相同。
java.lang.NullPointerException:
at android.graphics.drawable.AdaptiveIconDrawable.isProjected (AdaptiveIconDrawable.java:551)
at android.view.View.invalidateInternal (View.java:16640)
at android.view.View.invalidate (View.java:16600)
at android.view.View.setFrame (View.java:20945)
at android.widget.ImageView.setFrame (ImageView.java:1208)
at android.view.View.layout (View.java:20838)
at android.widget.LinearLayout.setChildFrame (LinearLayout.java:1791)
at android.widget.LinearLayout.layoutHorizontal (LinearLayout.java:1780)
at android.widget.LinearLayout.onLayout (LinearLayout.java:1546)
at android.view.View.layout (View.java:20841)
at android.view.ViewGroup.layout (ViewGroup.java:6401)
at android.widget.ListView.setupChild (ListView.java:2309)
at android.widget.ListView.makeAndAddView (ListView.java:2202)
at android.widget.ListView.fillDown (ListView.java:824)
at android.widget.ListView.fillGap (ListView.java:788)
at android.widget.AbsListView.trackMotionScroll (AbsListView.java:8184)
at android.widget.ListView.trackMotionScroll (ListView.java:2116)
at android.widget.AbsListView.scrollIfNeeded (AbsListView.java:4829)
at android.widget.AbsListView.onTouchMove (AbsListView.java:6523)
at android.widget.AbsListView.onTouchEvent (AbsListView.java:6340)
at android.widget.ListView.onTouchEvent (ListView.java:1700)
at android.view.View.dispatchTouchEvent (View.java:12539)
at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3153)
at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2829)
at android.widget.AbsListView.dispatchTouchEvent (AbsListView.java:6257)
at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3159)
at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2844)
at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3159)
at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2844)
at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3159)
at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2844)
at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3159)
at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2844)
at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3159)
at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2844)
at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3159)
at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2844)
at com.android.internal.policy.DecorView.superDispatchTouchEvent (DecorView.java:600)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java:1871)
at android.app.Activity.dispatchTouchEvent (Activity.java:3384)
at android.support.v7.view.i.dispatchTouchEvent (WindowCallbackWrapper.java:68)
at com.android.internal.policy.DecorView.dispatchTouchEvent (DecorView.java:562)
at android.view.View.dispatchPointerEvent (View.java:12787)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent (ViewRootImpl.java:5615)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:5410)
at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4903)
at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:4956)
at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:4922)
at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:5059)
at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:4930)
at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:5116)
at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4903)
at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:4956)
at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:4922)
at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:4930)
at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4903)
at android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:7654)
at android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:7594)
at android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:7555)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:7765)
at android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:197)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents (Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents (InputEventReceiver.java:186)
at android.view.ViewRootImpl.doConsumeBatchedInput (ViewRootImpl.java:7728)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run (ViewRootImpl.java:7792)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:911)
at android.view.Choreographer.doCallbacks (Choreographer.java:723)
at android.view.Choreographer.doFrame (Choreographer.java:652)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:897)
at android.os.Handler.handleCallback (Handler.java:789)
at android.os.Handler.dispatchMessage (Handler.java:98)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6940)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
这是我的清单文件。
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.burockgames.timeclocker">
<uses-permissionandroid:name="android.permission.PACKAGE_USAGE_STATS"tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:fullBackupContent="false"
android:hardwareAccelerated="false"
android:largeHeap="true"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".main.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
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=".applist.AppList"
android:screenOrientation="portrait"/>
(more activities)
<receiver android:name=".service.BroadCastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name=".service.AlarmReceiver">
</receiver>
</application>
重要提示:它总是发生在 Android Oreo(8.0 或 8.1)设备上。顺便说一句,我有一个像下面这样的方法。它返回已安装应用程序的列表。列表的元素是“MainActivity_App”。在方法中,首先我一个一个获取应用程序的图标、包名和名称,然后使用它们创建 MainActivity_App。这段代码会出现错误吗?
private List<MainActivity_App> getInstalledApps() {
List<MainActivity_App> temp = new ArrayList<>();
List<ApplicationInfo> packs = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
ArrayList<ApplicationInfo> applistTemp = new ArrayList<>();
for (ApplicationInfo info : packs) {
try {
if (packageManager.getLaunchIntentForPackage(info.packageName) != null) {
applistTemp.add(info);
}
} catch (Exception e) {
e.printStackTrace();
}
}
chosenAppsList=new ArrayList<>();
String s=settings.getString("chosenApps","");
for (int i = 0; i < applistTemp.size(); i++) {
ApplicationInfo info = applistTemp.get(i);
String appPackageName = info.packageName;
String appName="";
Drawable icon=null;
boolean select=false;
if (s.contains(appPackageName)) {
appName = info.loadLabel(getPackageManager()).toString();
icon = info.loadIcon(getPackageManager());
select = true;
}
MainActivity_App newApp=new MainActivity_App(appPackageName, appName, icon, 0, select);
temp.add(newApp);
}
return temp;
}
还有 MainActivity_App 类。
public class MainActivity_App {
private final String appPackageName;
private final String appName;
private final Drawable appIcon;
private long usedTime;
private final boolean isSelected;
MainActivity_App(String packageName, String name, Drawable icon, long time, boolean select) {
appPackageName=packageName;
appName=name;
appIcon=icon;
usedTime=time;
isSelected=select;
}
public String getAppPackageName() {
return appPackageName;
}
String getAppName() {
return appName;
}
Drawable getAppIcon() {
return appIcon;
}
long getUsedTime() {
return usedTime;
}
boolean getIsSelected() {
return isSelected;
}
public void setUsedTime(long usedTime) {
this.usedTime = usedTime;
}
}
解决方案
推荐阅读
- python - Tensorflow 模型不使用 Flask 抛出此图的元素
- r - 根据一列重复单独的数据框
- python - 如何将字符串解析为熊猫数据框
- shopify - 无法通过 NetSuite 中的在线 HTML 表单将文件(jpeg、png、pdf 等)上传到文件柜/自定义记录
- object - 3D 图像中的对象识别
- apache-spark - 在 spark 中跳过 hive 表中丢失的文件以避免 FileNotFoundException
- c# - 无法将“System.Web.UI.WebControls.ContentPlaceHolder”类型的对象转换为“System.Web.UI.WebControls.GridViewRow”类型。在按钮点击
- apache - Apache 关闭意外无法启动
- javascript - 如何在odoo中实现recaptcha
- asp.net-core - 如何解决保单索赔?