-1
Build version: 2.9 
Build date: 1979-11-30 00:00:00 
Current date: 2020-12-12 17:01:30 
Device: Samsung SM-N970U 
OS version: Android 10 (SDK 29) 
 
Stack trace:  
java.lang.RuntimeException: Unable to destroy activity {com.jmctstudios.vibe/com.jmctstudios.vibe.ActivitiesFragment.Splash_A}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.CountDownTimer.cancel()' on a null object reference
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5456)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5493)
    at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8167)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.CountDownTimer.cancel()' on a null object reference
    at com.jmctstudios.vibe.ActivitiesFragment.Splash_A.onDestroy(Splash_A.java:83)
    at android.app.Activity.performDestroy(Activity.java:8225)
    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1342)
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5441)
    ... 11 more
<?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.jmctstudios.vibe">

    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-feature
        android:name="android.hardware.camera2.full"
        android:required="false" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission
        android:name="android.permission.MANAGE_DOCUMENTS"
        tools:ignore="ProtectedPermissions" />
    <uses-permission android:name="android.permission.RECORD_VIDEO" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application
        android:name=".SimpleClasses.VIBE"
        android:allowBackup="false"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_launcher"
        android:screenOrientation="portrait"
        android:supportsRtl="false"
        android:theme="@style/AppTheme"
        tools:replace="allowBackup,supportsRtl">

        <activity android:name=".ActivitiesFragment.Accounts.Forgot_Pass_A"
            android:theme="@style/transparent_status"/>

        <activity
            android:name=".ActivitiesFragment.Video_Recording.Trim_video_A"
            android:theme="@style/black_status" />

        <activity
            android:name=".ActivitiesFragment.Video_Recording.Video_Recoder_Duet_A"
            android:theme="@style/black_status" />

        <activity
            android:name="cat.ereza.customactivityoncrash.activity.DefaultErrorActivity"
            android:process=":error_activity"
            android:theme="@style/error_activity_theme" />

        <activity
            android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Base.Theme.AppCompat"
            tools:ignore="LockedOrientationActivity" />
        <activity android:name=".ActivitiesFragment.SoundLists.VideoSound_A" />

        <activity
            android:name=".ActivitiesFragment.Video_Recording.DraftVideos_A"
            android:screenOrientation="portrait"
            android:theme="@style/white_status"
            tools:ignore="LockedOrientationActivity" />

        <activity
            android:name=".ActivitiesFragment.Video_Recording.GallerySelectedVideo_A"
            android:screenOrientation="portrait"
            tools:ignore="LockedOrientationActivity" />

        <activity
            android:name=".ActivitiesFragment.Accounts.Login_A"
            android:screenOrientation="portrait"
            android:theme="@style/Transparent"
            tools:ignore="LockedOrientationActivity" />

        <activity
            android:name=".ActivitiesFragment.Splash_A"
            android:screenOrientation="portrait"
            tools:ignore="LockedOrientationActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Main_Menu.MainMenuActivity"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@style/transparent_status"
            android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"
            tools:ignore="LockedOrientationActivity"/>

        <activity
            android:name=".ActivitiesFragment.WatchVideos_F"
            android:parentActivityName=".Main_Menu.MainMenuActivity"
            android:screenOrientation="portrait"
            android:theme="@style/transparent_status"
            android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"
            tools:ignore="LockedOrientationActivity">
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="bringthings.com"
                    android:scheme="http" />
            </intent-filter>

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.jmctstudios.vibe.Main_Menu.MainMenuActivity" />
        </activity>

        <activity
            android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name" />

        <activity
            android:name="com.facebook.CustomTabActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>

        <activity
            android:name=".ActivitiesFragment.Video_Recording.Video_Recoder_A"
            android:screenOrientation="portrait"
            android:theme="@style/black_status"
            tools:ignore="LockedOrientationActivity" />

        <activity
            android:name=".ActivitiesFragment.Video_Recording.Preview_Video_A"
            android:screenOrientation="portrait"
            android:theme="@style/black_status"
            tools:ignore="LockedOrientationActivity" />

        <activity
            android:name=".ActivitiesFragment.Video_Recording.Post_Video_A"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustNothing"
            tools:ignore="LockedOrientationActivity" />

        <activity
            android:name=".ActivitiesFragment.SoundLists.SoundList_Main_A"
            android:screenOrientation="portrait"
            tools:ignore="LockedOrientationActivity" />

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="@string/ad_app_id"/>


        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_tic" />

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/redcolor" />

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

        <service
            android:name=".Services.Upload_Service"
            android:enabled="true"
            android:exported="true">

            <intent-filter>
                <action android:name="startservice" />
            </intent-filter>
        </service>

        <service android:name=".Firebase_Notification.Notification_Receive">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />


    </application>

</manifest>
package com.jmctstudios.vibe.ActivitiesFragment;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.CountDownTimer;

import androidx.appcompat.app.AppCompatActivity;

import android.provider.Settings;
import android.view.Window;
import android.view.WindowManager;

import com.jmctstudios.vibe.Main_Menu.MainMenuActivity;
import com.jmctstudios.vibe.R;
import com.jmctstudios.vibe.ApiClasses.ApiLinks;
import com.jmctstudios.vibe.ApiClasses.ApiRequest;
import com.jmctstudios.vibe.Interfaces.Callback;
import com.jmctstudios.vibe.SimpleClasses.Variables;

import org.json.JSONException;
import org.json.JSONObject;

public class Splash_A extends AppCompatActivity {

    CountDownTimer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_splash);

        Variables.sharedPreferences = getSharedPreferences(Variables.pref_name, MODE_PRIVATE);
        if(Variables.sharedPreferences.getString(Variables.device_id,"0").equals("0")) {
            Call_api_register_device();
        }
        else
            Set_Timer();
    }


    public void Set_Timer(){
        countDownTimer = new CountDownTimer(2500, 500) {

            public void onTick(long millisUntilFinished) {
                // this will call on every 500 ms
            }

            public void onFinish() {
                Intent intent=new Intent(Splash_A.this, MainMenuActivity.class);

                if(getIntent().getExtras()!=null) {
                    intent.putExtras(getIntent().getExtras());
                    setIntent(null);
                }

                startActivity(intent);
                overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
                finish();
            }
        }.start();
    }

    @Override
    protected void onDestroy() {
        countDownTimer.cancel();
        super.onDestroy();
    }

    public void Call_api_register_device(){
        String androidId = Settings.Secure.getString(getContentResolver(),
                Settings.Secure.ANDROID_ID);
        JSONObject param=new JSONObject();
        try {
            param.put("key",androidId);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        ApiRequest.Call_Api(this, ApiLinks.registerDevice, param, new Callback() {
            @Override
            public void Responce(String resp) {
                try {
                    JSONObject jsonObject=new JSONObject(resp);
                    String code=jsonObject.optString("code");
                    if(code.equals("200")){
                        Set_Timer();

                        JSONObject msg=jsonObject.optJSONObject("msg");
                        JSONObject Device=msg.optJSONObject("Device");
                        SharedPreferences.Editor editor2 =  Variables.sharedPreferences.edit();
                        editor2.putString(Variables.device_id, Device.optString("id")).commit();
                    }else {
                        Call_api_show_register_device();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
       }

    public void Call_api_show_register_device(){
        String androidId = Settings.Secure.getString(getContentResolver(),
                Settings.Secure.ANDROID_ID);
        JSONObject param=new JSONObject();
        try {
            param.put("key",androidId);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        ApiRequest.Call_Api(this, ApiLinks.showDeviceDetail, param, new Callback() {
            @Override
            public void Responce(String resp) {
                try {
                    JSONObject jsonObject=new JSONObject(resp);
                    String code=jsonObject.optString("code");
                    if(code.equals("200")){
                        Set_Timer();

                        JSONObject msg=jsonObject.optJSONObject("msg");
                        JSONObject Device=msg.optJSONObject("Device");
                        SharedPreferences.Editor editor2 =  Variables.sharedPreferences.edit();
                        editor2.putString(Variables.device_id, Device.optString("id")).commit();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

Your object is null during onDestroy, maybe wrap it around a check like

@Override
protected void onDestroy() {
    super.onDestroy();
    if (countDownTimer!=null) {
      countDownTimer.cancel();
    }
}
Bharadwaj Giridhar
  • 977
  • 11
  • 15