2

I have an application in Play Store. I get NullPointerException everday in my application and I don't know where it come from. Because, logs do not contain any lines from classes i create. Could you please help me to find where it arise from?

  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)

This is another report. But i think its reason is the same as above.

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)

And this is my manifest file.

 <?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>

IMPORTANT: It always happens at Android Oreo (8.0 or 8.1) devices. By the way, I have a method like below. It returns the list of installed applications. Element of list is "MainActivity_App". In method, firsty i get the icon, packagename and name of applications one by one and i create the MainActivity_App by using them. Can the bug occur from this code?

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;
}

And there is the MainActivity_App class.

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;
}

}

Burak
  • 1,401
  • 2
  • 10
  • 17
  • @Talendar Thanks, but it is not duplicate of it. Its reason is not as easy as it is. – Burak Sep 01 '18 at 20:46
  • 1
    I've noticed that the error is related to android's views. A common source of NullPointerException in this case is when one attempt to call methods on a view before it has finished loading/drawing. Could that be your case? – Talendar Sep 01 '18 at 20:53
  • Hmm, It can be the reason. But, if it is the reason, why it happens only Oreo version devices? Your mentioned case can happen in all version devices. Am i right? – Burak Sep 01 '18 at 21:03
  • Looks related to your adaptive icon. Can you reproduce it in an Android 8 emulator? If you post your manifest and relevant icon file locations/contents it may help. – Tyler V Sep 01 '18 at 22:27
  • What is adaptive icon? Is it icon of application? – Burak Sep 01 '18 at 22:28
  • Yes, it is the application icon. Can you reproduce it in an emulator running Oreo? Read about them here, they're new in Oreo. https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive – Tyler V Sep 01 '18 at 22:31
  • @mstburak If you are still having the same question I'd suggest you ask a new one with some more info about your icons and a giant clause at the start of the question stating that you know what a NullPointerException is. Also remove "NullPointerException" from the question title. – Tyler V Sep 02 '18 at 13:35
  • @TylerV thank you for helping. I guess it is about the launcher icon. I will try to solve this by reproducing the icon. I will write here after i try. – Burak Sep 03 '18 at 00:35
  • @TylerV I'm tired to repeat it. Every NPE is the same story. You only have to find the cause. Therefore this question is a duplicate. – Phantômaxx Sep 03 '18 at 07:16
  • @KlingKlang Of course every NPE is the same story. But thats the point already. I have this error at only Oroe devices and i don't know why. Therefore i asked for the that STORY. I can not understand the reason of this exception from the link you give. You just do not want to deal with the problem. – Burak Sep 03 '18 at 10:36
  • @mstburak It may be some issue which only arises on Oreo devices. You have to investigate and debug your code to figure out which is the (still) not eferenced object you're using (explicitly or implicitly). – Phantômaxx Sep 03 '18 at 12:16
  • @TylerV This bug is occured 6 times in this week again even though i reproduced the application icon as you said. Please help me to find why it is occuring? (I edited the question maybe you want to review it.) – Burak Sep 13 '18 at 11:43
  • As I've asked a couple times now, can you reproduce the error in an Oreo emulator? – Tyler V Sep 14 '18 at 00:20
  • I am not able to produce this error. It doesn't occur always. I do not know when it occurs. I am only able to see the trace and how many times it has been occured in playstore developer website. – Burak Sep 14 '18 at 13:42
  • Possibly related to [this](https://stackoverflow.com/questions/50077917/android-graphics-drawable-adaptiveicondrawable-cannot-be-cast-to-android-graphic)? You could always try wrapping the call to `loadIcon` in a `try` `catch` statement and catching the exception. If it's coming from there, it may be that the user has an app installed with a lower targetSdkLevel and it doesn't use adaptive icons or something. Really just guessing at this point. – Tyler V Sep 15 '18 at 01:25
  • I found the reason and the solution. I have to give the answer in here, thanks to @KlingKlang. Its reason is setting the image resource by the application icon Drawable. If you loadicon from the packagemanager and if it returns the Adaptive icon, it causes the nullpointer exception. You have to convert it to bitmap before setting image resourse. You can found the solution in [here](https://stackoverflow.com/questions/44447056/convert-adaptiveicondrawable-to-bitmap-in-android-o-preview) – Burak Sep 28 '18 at 21:39

0 Answers0