Main activity not launching after updating Kotlin

Viewed 160

I had built the app 3 days ago and the app was working fine. yesterday I updated the Kotlin plugin to 1.3.71-studio3.6-1 after that when I build my app and run it on my phone then after login, the main activity does not launch and the app stops working but I am getting a successful login in my Firebase. If I try to reopen the app, it does not open. all other activities are working fine but main_activity does not. the code of main activity was not modified

this is my manifest file

<application
        android:allowBackup="false"
        android:icon="@mipmap/g_c"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/g_c_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".otp" />
        <activity android:name=".Register" />
        <activity android:name=".Login">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
    </application>
</manifest>

logcat error

03-30 01:40:05.051 6724-6724/com.trackerbin.guardchecker E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.trackerbin.guardchecker, PID: 6724
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.trackerbin.guardchecker/com.trackerbin.guardchecker.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.ads.AdView.loadAd(com.google.android.gms.ads.AdRequest)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
        at android.app.ActivityThread.access$1100(ActivityThread.java:229)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:7325)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.ads.AdView.loadAd(com.google.android.gms.ads.AdRequest)' on a null object reference
        at com.trackerbin.guardchecker.MainActivity.onCreate(MainActivity.java:63)
        at android.app.Activity.performCreate(Activity.java:6904)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415) 
        at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:7325) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

MainActivity

public class MainActivity extends AppCompatActivity {

    private Button mreport;
    private Button mon;
    private Button msignout;
    private FirebaseAuth fAuth;
    private Spinner mtower;
    private ProgressBar mBar;

    //AD
    private AdView mAdView;

    // Access a Cloud Firestore instance from your Activity
    private final FirebaseFirestore db = FirebaseFirestore.getInstance();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        mreport = findViewById(R.id.button);
        mon = findViewById(R.id.onn);
        fAuth = FirebaseAuth.getInstance();
        mtower = findViewById(R.id.tower);
        msignout = findViewById(R.id.signout);
        mBar = findViewById(R.id.bar);

        MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus) {
            }
        });
        mAdView = findViewById(R.id.adViewR);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

        if (fAuth.getCurrentUser() == null) {
            startActivity(new Intent(getApplicationContext(), Login.class));
            finish();
        }

        final String email = fAuth.getCurrentUser().getEmail();
        final String phone = fAuth.getCurrentUser().getPhoneNumber();



        mreport.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mBar.setVisibility(View.VISIBLE);

                        String tower = mtower.getSelectedItem().toString();
                        String currentTime = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(new Date());
                        String currentDate = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(new Date());

                        Map<String, Object> values = new HashMap<>(); values.put(currentTime,email + phone);

                        db.collection("tower").document(tower)
                                .collection(currentDate).document("duty")
                                .collection("off").document(currentTime).set(values);
                        mBar.setVisibility(View.INVISIBLE);
                        Toast.makeText(MainActivity.this, "THANK YOU FOR REPORTING !", Toast.LENGTH_SHORT).show();
                    }
                });

        mon.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mBar.setVisibility(View.VISIBLE);

                        String tower = mtower.getSelectedItem().toString();
                        String currentTime = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(new Date());
                        String currentDate = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(new Date());

                        Map<String, Object> values = new HashMap<>(); values.put(currentTime,email + phone);

                        db.collection("tower").document(tower)
                                .collection(currentDate).document("duty")
                                .collection("on").document(currentTime).set(values);
                        mBar.setVisibility(View.INVISIBLE);
                        Toast.makeText(MainActivity.this, "THANK YOU FOR REPORTING !", Toast.LENGTH_SHORT).show();
                    }
                });

        msignout.setOnClickListener
                (
                    new View.OnClickListener()
                    {
                        @Override
                        public void onClick(View v) {
                            fAuth.signOut();
                            startActivity(new Intent(getApplicationContext(), Login.class));
                            finish();
                        }
                    }

                );
    }
    @Override
    public void onBackPressed() {
        finishAffinity();
    }
}
1 Answers
<meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->

insert your own admob app id inside value="XXXXXXX"/>

Related