0
votes

I'm building an android application which first, users are register account with an id and then login where the system will checked if this user is using the same device as they use when registered. When the device are the same, then system will send a token to server. this is the method when checking the users device:

private void cekDataLogin(final String serial, final String device) throws IOException, JSONException {
    @SuppressLint("StaticFieldLeak")
    class dataLogin extends AsyncTask<Void, Void, String> {
        private final WeakReference<MainActivity> mActivityRef;
        private dataLogin(MainActivity activity) {
            mActivityRef = new WeakReference<>(activity);
        }
        protected String doInBackground(Void[] params) {
            String response = "";
            HashMap<String, String> map = new HashMap<>();
            try {
                HttpRequest req = new HttpRequest(ipAddress + "/preserv/index.php?func=tokenget&ser=" + serial + "&dev=" + device);
                response = req.prepare(HttpRequest.Method.GET).sendAndReadString();
            } catch (Exception e) {
                response = e.getMessage();
            }
            return response;
        }
        protected void onPostExecute(String result) {
            onTaskCompletedPin(result, jsoncode);
        }
    }
    new dataLogin(this).execute();
}
public void onTaskCompletedPin(String response, int serviceCode) {
    Log.d("responsejson", response);
    switch (serviceCode) {
        case jsoncode:
                try {
                    postDataToken();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
    }
} 

this is the method when sending new token:

 private void postDataToken() throws IOException, JSONException {
    final String android_id = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
    final String token = SharedPreference.getInstance(MainActivity.this).getDeviceToken();
    @SuppressLint("StaticFieldLeak")
    class dataToken extends AsyncTask<Void, Void, String> {
        private final WeakReference<MainActivity> mActivityRef;
        private dataToken(MainActivity activity) {
            mActivityRef = new WeakReference<>(activity);
        }
        protected String doInBackground(Void[] params) {
            String response = "";
            HashMap<String, String> map = new HashMap<>();
            try {
                HttpRequest req = new HttpRequest(ipAddress + "/preserv/index.php?func=devuptoken&ser=" + Build.SERIAL + "&dev=" + android_id + "&token=" + token);
                response = req.prepare(HttpRequest.Method.POST).withData(map).sendAndReadString();
            } catch (Exception e) {
                response = e.getMessage();
            }
            return response;
        }
        protected void onPostExecute(String result) {
            onTaskCompletedDevice(result, jsoncode);
        }
    }
    new dataToken(this).execute();
}
public void onTaskCompletedDevice(String response, int serviceCode) {
    Log.d("responsejson", response);
    switch (serviceCode) {
        case jsoncode:
            if (response.contains("sukses")) {
                final String android_id = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
                if (KEY_CON.equalsIgnoreCase("Wifi")) {
                    if (ipAddress.contains("10.20.")) {
                        URL = "http://10.20.2.14/personal/index.php?serial=" + Build.SERIAL + "&device=" + android_id;
                    } else {
                        URL = "http://36.67.40.162:9024/personal/index.php?serial=" + Build.SERIAL + "&device=" + android_id;
                    }
                } else {
                    URL = "http://36.67.40.162:9024/personal/index.php?serial=" + Build.SERIAL + "&device=" + android_id;
                }
                webView.loadUrl(URL);
            } else if (response.contains("failed")) {
                try {
                    postDataToken();
                } catch (Exception e) {
                    toastMessage("Can't generate token");
                }
            } else {
                toastMessage("ELSE");
            }
    }
}

and this resulting Unfortunately App has stopped and the error logcat look like this:

08-06 14:11:13.948 10722-10722/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.launcher.rsupsanglah.personalNotif, PID: 10722
java.lang.NullPointerException: println needs a message
    at android.util.Log.println_native(Native Method)
    at android.util.Log.d(Log.java:164)
    at com.launcher.rsupsanglah.personal.MainActivity.m(Unknown Source)
    at com.launcher.rsupsanglah.personal.MainActivity.a(Unknown Source)
    at com.launcher.rsupsanglah.personal.MainActivity$a.a(Unknown Source)
    at com.launcher.rsupsanglah.personal.MainActivity$a.onPostExecute(Unknown Source)
    at android.os.AsyncTask.finish(AsyncTask.java:632)
    at android.os.AsyncTask.access$600(AsyncTask.java:177)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5942)
    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:1400)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
08-06 14:11:14.013 3006-10804/? E/android.os.Debug: ro.product_ship = true
ro.debug_level = 0x4f4c
08-06 15:09:01.573 3006-3589/? V/ApplicationPolicy: isApplicationStateBlocked 
userId 0 pkgname com.launcher.rsupsanglah.personalNotif
08-06 15:09:01.573 3006-3589/? W/ActivityManager:   Force finishing activity 
com.launcher.rsupsanglah.personalNotif/
com.launcher.rsupsanglah.personal.MainActivity
08-06 15:09:01.588 3006-27720/? W/DropBoxManagerService: Dropping: 
data_app_crash (1228 > 0 bytes)
08-06 15:09:01.598 27618-27719/? I/FirebaseCrash: Sending crashes
08-06 15:09:01.603 27618-27719/? I/System.out: (HTTPLog)-Static: 
isSBSettingEnabled false
08-06 15:09:01.633 3006-27722/? E/android.os.Debug: ro.product_ship = true
ro.debug_level = 0x4f4c
08-06 15:09:01.653 3006-3035/? D/StatusBarManagerService: manageDisableList 
userId=0 what=0x0 pkg=WindowManager.LayoutParams
08-06 15:09:01.653 3006-3037/? D/PointerIcon: setMouseIconStyle1 pointerType: 
1001iconType:101 flag:0
setMouseCustomIcon IconType is same.101
08-06 15:09:01.653 3006-3006/? D/CrashAnrDetector: NO DROPBOX ENTRY for 
:data_app_crash 1533539341593
08-06 15:09:01.653 3006-3037/? D/PointerIcon: setHoveringSpenIconStyle1 
pointerType: 10001iconType:1 flag:0
08-06 15:09:01.658 3006-3037/? D/PointerIcon: setHoveringSpenCustomIcon 
IconType is same.1
08-06 15:09:01.663 2352-2352/? I/SurfaceFlinger: id=972 createSurf (49x49),1 
flag=4, qersonalNot
08-06 15:09:01.663 21591-21591/? W/ContextImpl: Calling a method in the 
system process without a qualified user: 
android.app.ContextImpl.startService:2051 
android.content.ContextWrapper.startService:533 
android.content.ContextWrapper.startService:533 
com.samsung.android.sm.common.SmartManagerReceiver.b:199 
com.samsung.android.sm.common.SmartManagerReceiver.onReceive:93 
08-06 15:09:01.663 3006-3449/? D/ActivityManager: startService 
callerProcessName:com.samsung.android.sm, calleePkgName: 
com.samsung.android.sm
caller:android.app.ApplicationThreadProxy@18ebc41, r.packageName 
:com.samsung.android.sm
08-06 15:09:01.673 3006-3585/? D/ActivityManager: 
caller:android.app.ApplicationThreadProxy@37c86727, r.packageName 
:com.google.android.gms
08-06 15:09:01.683 3006-4255/? D/ActivityManager: startService 
callerProcessName:com.google.android.gms, calleePkgName: 
com.google.android.gms
caller:android.app.ApplicationThreadProxy@17c9db7d, r.packageName 
:com.google.android.gms
08-06 15:09:01.683 3006-3175/? I/OpenGLRenderer: Initialized EGL, version 1.4
08-06 15:09:01.693 3006-3449/? D/ActivityManager: bindService 
callerProcessName:com.google.android.gms, calleePkgName: 
com.google.android.gms, action: 
com.google.android.gms.phenotype.service.START
08-06 15:09:01.703 3006-3175/? I/OpenGLRenderer: HWUI protection enabled for 
context ,  &this =0x9e959f88 ,&mEglDisplay = 1 , &mEglConfig = -1641421900 
08-06 15:09:01.703 3006-3019/? D/ActivityManager: startService 
callerProcessName:com.google.android.gms, calleePkgName: 
com.google.android.gms
08-06 15:09:01.708 3006-3019/? D/ActivityManager: 
caller:android.app.ApplicationThreadProxy@7a9336c, r.packageName 
:com.google.android.gms
08-06 15:09:01.723 3006-3587/? D/ActivityManager: bindService 
callerProcessName:com.google.android.gms, calleePkgName: 
com.google.android.gms, action: com.google.android.gms.clearcut.service.START
08-06 15:09:01.738 3006-3413/? D/ActivityManager: bindService 
callerProcessName:com.google.android.gms, calleePkgName: 
com.google.android.gms, action: com.google.android.gms.udc.service.START
08-06 15:09:01.758 3006-3585/? D/ActivityManager: startService 
callerProcessName:com.google.android.gms, calleePkgName: 
com.google.android.gms
caller:android.app.ApplicationThreadProxy@10932be9, r.packageName 
:com.google.android.gms
08-06 15:09:01.768 3006-3586/? D/ActivityManager: startService 
callerProcessName:com.google.android.gms, calleePkgName: 
com.google.android.gms
caller:android.app.ApplicationThreadProxy@24164f9c, r.packageName 
:com.google.android.gms
08-06 15:09:01.778 3006-3449/? D/ConnectivityService: returning 
getActiveNetworkInfo :[type: WIFI[] - WIFI, state: CONNECTED/CONNECTED, 
reason: (unspecified), extra: "KECOA SALTO", roaming: false, failover: false, 
isAvailable: true, isConnectedToProvisioningNetwork: false]
08-06 15:09:01.788 27618-27719/? I/System.out: 
KnoxVpnUidStorageknoxVpnSupported API value returned is false
08-06 15:09:01.788 3006-3373/? D/ActivityManager: startService 
callerProcessName:com.google.android.gms, calleePkgName: 
com.google.android.gms
08-06 15:09:01.793 3006-3373/? D/ActivityManager: 
caller:android.app.ApplicationThreadProxy@18699da5, r.packageName 
:com.google.android.gms
08-06 15:09:01.798 3006-3590/? D/ActivityManager: startService 
callerProcessName:com.google.android.gms, calleePkgName: 
com.google.android.gms
caller:android.app.ApplicationThreadProxy@259e957a, r.packageName 
:com.google.android.gms
08-06 15:09:01.808 3006-4578/? D/ActivityManager: startService 
 callerProcessName:com.google.android.gms, calleePkgName: 
 com.google.android.gms
08-06 15:09:01.813 3006-4578/? D/ActivityManager: 
caller:android.app.ApplicationThreadProxy@2c6d012b, r.packageName 
:com.google.android.gms
08-06 15:09:01.918 4024-27128/? I/qtaguid: Untagging socket 87
08-06 15:09:02.128 3006-3032/? W/ActivityManager: Activity pause timeout for 
ActivityRecord{1df5a9bd u0 
com.launcher.rsupsanglah.personalNotif
/com.launcher.rsupsanglah.personal.MainActivity t392 f}
mDVFSHelper.acquire()
08-06 15:09:02.138 3006-3032/? V/WindowOrientationListener: 
mSContextAutoRotationListener.getProposedRotation, mbResultFaceDectection: 
false mSContextAutoRotationListener.getProposedRotation, Rotation: -1
08-06 15:09:02.138 3006-3032/? V/WindowManager: 
rotationForOrientationLw(orient=-1, last=0); user=0 USER_ROTATION_LOCKED 
sensorRotation=-1 mLidState=-1 mDockMode=0 mHdmiPlugged=false
08-06 15:09:02.143 3006-3032/? V/WindowOrientationListener: 
mSContextAutoRotationListener.getProposedRotation, mbResultFaceDectection: 
false mSContextAutoRotationListener.getProposedRotation, Rotation: -1
08-06 15:09:02.148 2352-2352/? I/SurfaceFlinger: id=973 createSurf 
(1080x1920),1 
flag=404, TubSettings
08-06 15:09:02.243 18041-18041/? E/AccessibilityManager: assistantMenuUpdate 
invoking from manager:
08-06 15:09:02.323 3006-3043/? D/ActivityManager: bindService 
callerProcessName:android, calleePkgName: com.android.defcontainer, action: 
null
08-06 15:09:02.333 2360-2360/? E/installd: system dir 0 : /system/app/
08-06 15:09:02.338 3006-3449/? D/UsbSettingsManager: hasDefaults: 
com.launcher.rsupsanglah.personalNotif FALSE
08-06 15:09:02.378 3006-3043/? D/PackageManager: remove MCS_UNBIND message 
and Posting MCS_UNBIND 10 secs later
08-06 15:09:02.378 2360-2360/? E/installd: system dir 0 : /system/app/
08-06 15:09:02.388 18041-18041/? W/ResourceType: Failure getting entry for 
0x7f020000 (t=1 e=0) (error -75)
08-06 15:09:02.388 18041-18041/? W/PackageManager: Failure retrieving 
resources 
for com.sec.android.provider.badge: Resource ID #0x7f020000
08-06 15:09:02.403 3006-3043/? D/PackageManager: remove MCS_UNBIND message 
and Posting MCS_UNBIND 10 secs later
08-06 15:09:02.403 3006-4578/? D/SecContentProvider2: uri = 1 selection = 
getApplicationUninstallationEnabled
mCursor = null
08-06 15:09:02.403 3006-4578/? D/ApplicationPolicy: 
getApplicationUninstallationEnabled
getApplicationUninstallationEnabled :  enabled true
08-06 15:09:02.403 2360-2360/? E/installd: system dir 0 : /system/app/
system dir 1 : /system/priv-app/
08-06 15:09:02.408 3006-3373/? D/ActivityManager: post active user change for 
0 fullscreen true record.isFloatingActivity() false
08-06 15:09:02.408 3006-3373/? D/KnoxTimeoutHandler: postActiveUserChange for 
user 0
08-06 15:09:02.413 3006-3006/? D/PersonaManagerService: getPersonasForUser(): 
returning null!
08-06 15:09:02.408 3006-3373/? I/KnoxTimeoutHandler: postActiveUserChange, 
showWhenLocked: false
08-06 15:09:02.413 3006-3006/? D/KnoxTimeoutHandler: handleActiveUserChange 
for user 0
08-06 15:09:02.428 3006-3043/? D/PackageManager: remove MCS_UNBIND message 
and Posting MCS_UNBIND 10 secs later
08-06 15:09:02.428 2360-2360/? E/installd: system dir 0 : /system/app/
08-06 15:09:02.448 3006-3043/? D/PackageManager: remove MCS_UNBIND message 
and Posting MCS_UNBIND 10 secs later
08-06 15:09:02.448 2360-2360/? E/installd: system dir 0 : /system/app/
system dir 1 : /system/priv-app/
08-06 15:09:02.468 3006-3043/? D/PackageManager: remove MCS_UNBIND message 
and Posting MCS_UNBIND 10 secs later
08-06 15:09:02.468 2360-2360/? E/installd: system dir 0 : /system/app/
system dir 1 : /system/priv-app/
08-06 15:09:02.488 3006-3043/? D/PackageManager: remove MCS_UNBIND message 
and Posting MCS_UNBIND 10 secs later
08-06 15:09:02.488 2360-2360/? E/installd: system dir 0 : /system/app/
system dir 1 : /system/priv-app/
system dir 2 : /vendor/app/
system dir 3 : /oem/app/
08-06 15:09:02.513 3006-3043/? D/PackageManager: remove MCS_UNBIND message 
and Posting MCS_UNBIND 10 secs later
08-06 15:09:02.513 2360-2360/? E/installd: system dir 0 : /system/app/
system dir 1 : /system/priv-app/
system dir 2 : /vendor/app/
system dir 3 : /oem/app/
08-06 15:09:02.518 18041-18041/? I/Timeline: Timeline: Activity_idle id: 
android.os.BinderProxy@8c69e1e time:24624275
08-06 15:09:02.548 3006-3043/? D/PackageManager: remove MCS_UNBIND message 
and Posting MCS_UNBIND 10 secs later
08-06 15:09:02.548 2360-2360/? E/installd: system dir 0 : /system/app/
system dir 1 : /system/priv-app/
system dir 2 : /vendor/app/
system dir 3 : /oem/app/
08-06 15:09:02.593 3006-3043/? D/PackageManager: remove MCS_UNBIND message 
and Posting MCS_UNBIND 10 secs later
08-06 15:09:02.593 2360-2360/? E/installd: system dir 0 : /system/app/
system dir 1 : /system/priv-app/
system dir 2 : /vendor/app/
system dir 3 : /oem/app/
08-06 15:09:02.613 3006-3043/? D/PackageManager: remove MCS_UNBIND message 
and Posting MCS_UNBIND 10 secs later
08-06 15:09:02.613 2360-2360/? E/installd: system dir 0 : /system/app/
system dir 1 : /system/priv-app/
system dir 2 : /vendor/app/
system dir 3 : /oem/app/

any idea? I'm new to android and sometimes the app runs okay (after multiple error like this), but when I clear the data/uninstalled, mostly resulting to this E/installd: system dir 0 : /system/app/ and sometimes E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE because I'm using firebase when generating new token. I already set generate the token only if device is connected to internet.

1
this line ` Log.d("responsejson", response);` is a problem. your response in nullprashant17
the response from server is a string "sukses" (success). it is not nullpdiani
Your error logs clearly say your response is null and that's why there is a crash. as Log.d requires non-null messageprashant17
08-06 14:37:41.118 17833-17833/? D/responsejson: sukses. But this the log for responsejsonpdiani

1 Answers

-1
votes
static jint android_util_Log_println_native(JNIEnv* env, jobject clazz,
    jint bufID, jint priority, jstring tagObj, jstring msgObj)
{
    const char* tag = NULL;
    const char* msg = NULL;

    if (msgObj == NULL) {
        jniThrowNullPointerException(env, "println needs a message");
        return -1;
    }
    // Rest of the method
}

As per the native print method for printing the message in Android, your message object should be non null value.

In your case, response object is null. so add null check before printing message

if(null != response)
{
    Log.d("responsejson", response);
}

If you want to still print what is the value of response object even though it is null. Try to use below line.

Log.d("responsejson", "Response is "+response);