0

I have been stuck on this error for few days and not able to figure it out the exact error. I am trying to replace the banner ads with the Native ads.It's giving an error when I am trying to place it on one of the screens.

Details here :Error Details

MainActivity.java :

package com.myapp.praveen.healthcareit;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.AdapterView;
import android.view.View;
import android.widget.ListView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import com.google.android.gms.ads.MobileAds;

public class MainActivity extends AppCompatActivity {

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

        MobileAds.initialize(getApplicationContext(),"ca-app-pub-ca-app-pub-6667404740993831~3291209699");

        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

        AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> listView, View itemView, int position, long id) {
                if (position == 0) {
                    Intent intent = new Intent(MainActivity.this, EvlHealthPlans.class);
                    startActivity(intent);
                }
                if (position == 1) {
                    Intent intent = new Intent(MainActivity.this, ConHealthInsurance.class);
                    startActivity(intent);
                }
                if (position == 2) {
                    Intent intent = new Intent(MainActivity.this, HealthPlanNetworks.class);
                    startActivity(intent);
                }
                if (position == 3) {
                    Intent intent = new Intent(MainActivity.this, ProvCompensation.class);
                    startActivity(intent);
                }

                if (position == 4) {
                    Intent intent = new Intent(MainActivity.this, HmoPlans.class);
                    startActivity(intent);
                }

                if (position == 5) {
                    Intent intent = new Intent(MainActivity.this, PpoPlans.class);
                    startActivity(intent);
                }

                if (position == 6) {
                    Intent intent = new Intent(MainActivity.this, CdphpPlans.class);
                    startActivity(intent);
                }

                if (position == 7) {
                    Intent intent = new Intent(MainActivity.this, ProviderTypes.class);
                    startActivity(intent);
                }

                if (position == 8) {
                    Intent intent = new Intent(MainActivity.this, UtilizationManagement.class);
                    startActivity(intent);
                }

                if (position == 9) {
                    Intent intent = new Intent(MainActivity.this, EDIConcept.class);
                    startActivity(intent);
                }

                if (position == 10) {
                    Intent intent = new Intent(MainActivity.this, ClaimProcessing.class);
                    startActivity(intent);
                }

                if (position == 11) {
                    Intent intent = new Intent(MainActivity.this, CobraHippa.class);
                    startActivity(intent);
                }

                if (position == 12) {
                    Intent intent = new Intent(MainActivity.this, GovernmentPrograms.class);
                    startActivity(intent);
                }

            }
        };

        ListView listView = (ListView) findViewById(R.id.list_options);
        listView.setOnItemClickListener(itemClickListener);
    }

}

Activity_Main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    tools:context="com.myapp.praveen.healthcareit.MainActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ListView
        android:id = "@+id/list_options"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries = "@array/topics" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignBottom="@+id/list_options"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_screen1">
    </com.google.android.gms.ads.AdView>


</RelativeLayout>
</ScrollView>

Log

FATAL EXCEPTION: main
Process: com.myapp.praveen.healthcareit, PID: 4077
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.praveen.healthcareit/com.myapp.praveen.healthcareit.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setOnItemClickListener(android.widget.AdapterView$OnItemClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setOnItemClickListener(android.widget.AdapterView$OnItemClickListener)' on a null object reference
at com.myapp.praveen.healthcareit.MainActivity.onCreate(MainActivity.java:95)
at android.app.Activity.performCreate(Activity.java:6259)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
at android.app.ActivityThread.access$900(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
Community
  • 1
  • 1
Praveenks
  • 1,436
  • 9
  • 40
  • 79

0 Answers0