0

This was working fine in Recyclerview.. however problem started when i started converting to gridview(included image)....

ERROR - java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.GridView.setAdapter(android.widget.ListAdapter)' on a null object reference......OfferParser.java:83
**(OfferParser.java:83)**------- gv.setAdapter(offerAdapter);

**OfferParser.java:34**-----public class OfferParser extends AsyncTask<Void, Void, Integer> {

FATAL EXCEPTION: main
Process: khanduri2.shobhit.myapplication, PID: 23717
  java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.GridView.setAdapter(android.widget.ListAdapter)' on a null object reference
  at khanduri2.shobhit.myapplication.mLiquorSQL.OfferParser.onPostExecute(OfferParser.java:83)
  at khanduri2.shobhit.myapplication.mLiquorSQL.OfferParser.onPostExecute(OfferParser.java:34)
  at android.os.AsyncTask.finish(AsyncTask.java:636)
  at android.os.AsyncTask.access$500(AsyncTask.java:177)
  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5351)
  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:947)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)

OfferParser() class

package khanduri2.shobhit.myapplication.mLiquorSQL;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.support.v7.widget.RecyclerView;
import android.widget.GridView;
import android.widget.Toast;

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

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.ArrayList;

import java.util.Collections;

import khanduri2.shobhit.myapplication.MainActivity;
import khanduri2.shobhit.myapplication.mGridView.OfferAdapterGv;
import khanduri2.shobhit.myapplication.mLiquorDataObjext.GetOfferData;
import khanduri2.shobhit.myapplication.mLiquorDataObjext.GetShopsData;
import khanduri2.shobhit.myapplication.mLiquorRecyclerActivity.MyAdapter;

/**
 * Created by jack on 18/01/2018.
 */

public class OfferParser extends AsyncTask<Void, Void, Integer> {

    String jsonData;
    GridView gv;
    Context context;

    ArrayList<GetOfferData> getOfferDatas= new ArrayList<>();
    ProgressDialog pd;
    double distanceNumeric=0.0;

    public OfferParser(Context c,String jsonData,GridView gv) {
        this.jsonData = jsonData;
        this.gv = gv;
        this.context = c;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        distanceNumeric=0.0;

        pd = new ProgressDialog(context);
        pd.setTitle("Parse");
        pd.setMessage("Parsing Offer's..... Please Wait!!!!");
        pd.show();

    }

    @Override
    protected Integer doInBackground(Void... params) {
        return this.parse();
    }

    @Override
    protected void onPostExecute(Integer result) {
        super.onPostExecute(result);


        pd.dismiss();

        if(result==0){

            Toast.makeText(context,"Unable to parse 
Offer's",Toast.LENGTH_SHORT);

        }else{


            //CALL ADAPTER TO BIND DATA TO GRIDVIEW
            OfferAdapterGv offerAdapter = new 
OfferAdapterGv(context,getOfferDatas);
            gv.setAdapter(offerAdapter);

        }



    }


    private int parse()
    {

        try {

            JSONArray ja = new JSONArray(jsonData);
            JSONObject jo = null;

            getOfferDatas.clear();
            GetOfferData getOfferData = null;

            for(int i=0;i<ja.length();i++){
                jo= ja.getJSONObject(i);

                int id = jo.getInt("Id");
                String shopName = jo.getString("Name");
                String city = jo.getString("City");
                String imageurl = jo.getString("ImageUrl");
                String offer1 = jo.getString("Offer1");
                String offer2 = jo.getString("Offer2");
                String offer3 = jo.getString("Offer3");
                String offer4 = jo.getString("Offer4");
                String offer5 = jo.getString("Offer5");
                String offertc = jo.getString("OfferTC");
                double ownerLatitude = jo.getDouble("OwnerLatitude");
                double ownerLongitude = jo.getDouble("OwnerLongitude");
                String distance = jo.getString("Distance");
                distanceNumeric = jo.getDouble("DistanceNumeric");

                distance = getDistance(MainActivity.userMasterLat,MainActivity.userMasterLng,ownerLatitude,ownerLongitude);

                getOfferData = new GetOfferData();

                getOfferData.setId(id);
                getOfferData.setShop_name(shopName);
                getOfferData.setCity(city);
                getOfferData.setImageurl(imageurl);
                getOfferData.setOffer1(offer1);
                getOfferData.setOffer2(offer2);
                getOfferData.setOffer3(offer3);
                getOfferData.setOffer4(offer4);
                getOfferData.setOffer5(offer5);
                getOfferData.setOffer_tc(offertc);
                getOfferData.setOwner_latitude(ownerLatitude);
                getOfferData.setOwner_longitude(ownerLongitude);
                getOfferData.setDistance(distance);
                getOfferData.setDistance_numeric(distanceNumeric);

                getOfferDatas.add(getOfferData);

            }

            // SORTING BY THE DISTANCE
            sortData();
            return 1;

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return 0;
    }

    private void sortData() {

        Collections.sort(getOfferDatas,(l1, l2) -> {

            if((int)(l1.getDistance_numeric()) > (int)l2.getDistance_numeric())
            {

                return 1;

            } else if(l1.getDistance_numeric() < l2.getDistance_numeric())
            {
                return -1;

            }else
            {

                return 0;
            }

        });

    }


    public String getDistance(final double lat1, final double lon1, final double lat2, final double lon2){
        final String[] parsedDistance = new String[1];
        final String[] response = new String[1];
        final Double[] parsedDistanceint = new Double[1];
        distanceNumeric=0.0;
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    URL url = new URL("http://maps.googleapis.com/maps/api/directions/json?origin=" + lat1 + "," + lon1 + "&destination=" + lat2 + "," + lon2 + "&sensor=false&units=metric&mode=driving");
                    final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setRequestMethod("POST");
                    InputStream in = new BufferedInputStream(conn.getInputStream());

                    response[0] = org.apache.commons.io.IOUtils.toString(in, "UTF-8");

                    JSONObject jsonObject = new JSONObject(response[0]);
                    JSONArray array = jsonObject.getJSONArray("routes");
                    JSONObject routes = array.getJSONObject(0);
                    JSONArray legs = routes.getJSONArray("legs");
                    JSONObject steps = legs.getJSONObject(0);
                    JSONObject distance = steps.getJSONObject("distance");

                    parsedDistance[0] =distance.getString("text");
                    parsedDistanceint[0] = distance.getDouble("value");

                } catch (ProtocolException e) {
                    e.printStackTrace();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });

        thread.start();

        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        distanceNumeric = parsedDistanceint[0];
        return parsedDistance[0];
    }





}

OfferAdaptergv

package khanduri2.shobhit.myapplication.mGridView;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

 import khanduri2.shobhit.myapplication.R;
 import khanduri2.shobhit.myapplication.mLiquorDataObjext.GetOfferData;
import 
khanduri2.shobhit.myapplication.m_FullDetailActivity.OfferDetailActivity;


public class OfferAdapterGv extends BaseAdapter {

Context c;
ArrayList<GetOfferData> getOfferDatas;

LayoutInflater inflater;



public OfferAdapterGv(Context con, ArrayList<GetOfferData> gODS) {
    this.c = con;
    this.getOfferDatas = gODS;

    inflater = (LayoutInflater) this.c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}


@Override
public int getCount() {
    return getOfferDatas.size();
}

@Override
public Object getItem(int position) {
    return getOfferDatas.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View cvOffer, ViewGroup parent) {

    if(cvOffer==null)
    {

        cvOffer = inflater.inflate(R.layout.offergridmodel,parent,false);

    }

    ImageView img = (ImageView) cvOffer.findViewById(R.id.shopPicOfferImageView);

    TextView nameTv = (TextView) cvOffer.findViewById(R.id.shopNameOfferTextView);
    TextView offer1Tv = (TextView) cvOffer.findViewById(R.id.offer1TextView);
    TextView offer2Tv = (TextView) cvOffer.findViewById(R.id.offer2TextView);
    TextView offer3Tv = (TextView) cvOffer.findViewById(R.id.offer3TextView);
    TextView offer4Tv = (TextView) cvOffer.findViewById(R.id.offer4TextView);
    TextView offer5Tv = (TextView) cvOffer.findViewById(R.id.offer5TextView);
    TextView offerTcTv = (TextView) cvOffer.findViewById(R.id.offerTcTextView);
    TextView shopDistanceTv = (TextView) cvOffer.findViewById(R.id.shopDistanceOfferTextView);

    // BIND DATA

    GetOfferData getOfferData = getOfferDatas.get(position);

    PicassoClient.downloadImage(c,getOfferData.getImageurl(),img);

    nameTv.setText(getOfferData.getShop_name());
    offer1Tv.setText(getOfferData.getOffer1());
    offer2Tv.setText(getOfferData.getOffer2());
    offer3Tv.setText(getOfferData.getOffer3());
    offer4Tv.setText(getOfferData.getOffer4());
    offer5Tv.setText(getOfferData.getOffer5());
    offerTcTv.setText(getOfferData.getOffer_tc());
    shopDistanceTv.setText(getOfferData.getDistance());


    cvOffer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            openDetailActivity(getOfferData.getId());

        }
    });


    return cvOffer;
}


private void openDetailActivity(int id){


    Intent i = new Intent (c,OfferDetailActivity.class);

    i.putExtra("ID_KEY",id);

    c.startActivity(i);

}
}

Offergridmodel(xml) for gridview

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mCardGv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@android:drawable/spinner_background"
android:orientation="horizontal"
card_view:cardBackgroundColor="@color/colorPrimaryDark"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="5dp"
>


<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:drawable/dialog_holo_light_frame">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/shopPicOfferImageView"
        android:layout_width="180dp"
        android:layout_height="100dp"
        android:padding="2dp"
        android:layout_gravity ="center_horizontal"
        android:contentDescription="@null" />

    <TextView
        android:id="@+id/shopDistanceOfferTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="2dp"
        android:paddingRight="5dp"
        android:paddingLeft="5dp"

        android:background="@color/colorPrimaryDark"
        android:layout_gravity="end"
        android:text="@string/shopDistanceTextView"
        android:textAlignment="viewEnd"

        android:textColor="@color/colorPrimary"
        android:textSize="16sp"
        android:textStyle="bold" />
    </FrameLayout>

    <TextView
        android:id="@+id/shopNameOfferTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_gravity="center_horizontal"
        android:text="@string/shopNameTextView"
        android:textAlignment="center"
        android:textAllCaps="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/colorAccent"
        android:textSize="14sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/offer1TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="@string/offer1TextView"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/colorAccent"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/offer2TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="@string/offer2TextView"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/colorAccent"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/offer3TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="@string/offer3TextView"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/colorAccent"
        android:textSize="14sp" />
    <TextView
        android:id="@+id/offer4TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="@string/offer4TextView"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/colorAccent"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/offer5TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="@string/offer5TextView"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/colorAccent"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/offerTcTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/wallet_dim_foreground_holo_dark"
        android:paddingBottom="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="@string/offerTcTextView"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/colorAccent"
        android:textSize="14sp"
        android:textStyle="italic" />




</LinearLayout>

</android.support.v7.widget.CardView>

OfferRestBarTabFragment(where i decleared gridview)(also if this helps i can see the gridview data which i wanted to display(image and text) on my phone before the app crashes)

package khanduri2.shobhit.myapplication.mLiquorTab;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import khanduri2.shobhit.myapplication.R;
import khanduri2.shobhit.myapplication.mGridView.OfferAdapterGv;
import khanduri2.shobhit.myapplication.mLiquorSQL.OfferSenderReceiver;
import khanduri2.shobhit.myapplication.mLiquorSQL.SenderReceiver;

import static khanduri2.shobhit.myapplication.MainActivity.userMasterLat;
import static khanduri2.shobhit.myapplication.MainActivity.userMasterLng;

public class OfferRestBarTabFragment extends Fragment {

final static String urlSearchCityRbOffer = "http://192.168.0.105/Daru/offerrestpubdata_city.php";
final static String urlSearchRbOffer = "http://192.168.0.105/Daru/offerrestpubdata_city.php";


ImageView noDataImgRbOffer,noNetworkImgRbOffer;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle 
savedInstanceState) {

    View vRbOffer = 
inflater.inflate(R.layout.fragment_offer_rest_bar_tab,null);

    Geocoder geocoder = new Geocoder(this.getActivity(), 
Locale.getDefault());
    List<Address> addresses = null;
    try {
        addresses = geocoder.getFromLocation(userMasterLat , userMasterLng, 
1);
    } catch (IOException e) {
        e.printStackTrace();
    }


    String cityQueryRbOffer = addresses.get(0).getLocality();

    //GridView

    GridView gvRbOffer = 
(GridView)vRbOffer.findViewById(R.id.mGvRestBarOffer);



    SearchView svRbOffer = (SearchView) 
vRbOffer.findViewById(R.id.mSvRestBarOffer);


    noDataImgRbOffer = (ImageView) vRbOffer.findViewById(R.id.noDataOfferImg);
    noNetworkImgRbOffer = (ImageView) vRbOffer.findViewById(R.id.noServerOfferImg);

    OfferSenderReceiver srRbOffer = new 



OfferSenderReceiver(OfferRestBarTabFragment.this.getActivity(), 
cityQueryRbOffer,urlSearchCityRbOffer,
gvRbOffer,noDataImgRbOffer,noNetworkImgRbOffer);
    srRbOffer.execute();



    svRbOffer.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            OfferSenderReceiver srRbOffer = new 
OfferSenderReceiver(OfferRestBarTabFragment.this.getActivity(), 
query, urlSearchCityRbOffer, gvRbOffer, noDataImgRbOffer, 
noNetworkImgRbOffer);
            srRbOffer.execute();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            OfferSenderReceiver srRbOffer = new OfferSenderReceiver(OfferRestBarTabFragment.this.getActivity(), query, urlSearchCityRbOffer, gvRbOffer, noDataImgRbOffer, noNetworkImgRbOffer);
            srRbOffer.execute();
            return false;
        }
    });




    return vRbOffer;




}

 //SET TITLE FOR THE FRAGMENT


  @Override
  public String toString() {
    return "Rest/ Bar Offer";
  }


}

fragment_offer_rest_bar_tab.xml (xml of the OfferRestBarTabFragment)

 <?xml version="1.0" encoding="utf-8"?>
 <android.support.design.widget.CoordinatorLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@drawable/appbglessblur"
 android:paddingLeft="5dp"
 android:paddingBottom="5dp"
 android:paddingRight="5dp"
 android:paddingTop="5dp"
 app:layout_behavior="@string/appbar_scrolling_view_behavior"

  tools:context=
  "khanduri2.shobhit.myapplication.mLiquorTab.OfferRestBarTabFragment">


   <android.support.v7.widget.SearchView
    android:id="@+id/mSvRestBarOffer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/actionModeBackground"
    app:defaultQueryHint="Search.."></android.support.v7.widget.SearchView>


    <GridView
    android:id="@+id/mGvRestBarOffer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    android:background=
   "@android:drawable/screen_background_light_transparent"
    android:numColumns="2"></GridView>


   <ImageView
    android:id="@+id/noDataOfferImg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    android:contentDescription="@null"
    android:src="@drawable/norecordfound"
    android:layout_gravity="center"
    android:visibility="invisible" />

   <ImageView
    android:id="@+id/noServerOfferImg"
    android:visibility="invisible"
    android:src="@drawable/noserver"
    android:layout_marginTop="50dp"
    android:contentDescription="@null"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>


  </android.support.design.widget.CoordinatorLayout>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Please help stuck in this for the last 5 days – shobhit khanduri Jan 23 '18 at 09:38
  • Does your list has data or its null? – Shivam Oberoi Jan 23 '18 at 09:41
  • 1
    where have you initialised your gridVew – Kapil Parmar Jan 23 '18 at 09:42
  • Its simple, you're trying to set the adapter to a null referred view. You might have not initialized your gridview. – SripadRaj Jan 23 '18 at 09:42
  • I think, there is a problem with your gridView. It may be null. Did you initialize it? – Jyoti JK Jan 23 '18 at 09:43
  • yes i have GridView gvRbOffer = (GridView)vRbOffer.findViewById(R.id.mGvRestBarOffer); @ShivamOberoi – shobhit khanduri Jan 23 '18 at 09:52
  • yes i have GridView gvRbOffer = (GridView)vRbOffer.findViewById(R.id.mGvRestBarOffer); @KapilParmar – shobhit khanduri Jan 23 '18 at 09:54
  • you guys want to me to include that class as well?? where i declared GridView ? if that helps – shobhit khanduri Jan 23 '18 at 09:56
  • Why would you declare it elsewhere? – sHOLE Jan 23 '18 at 09:57
  • hey i updated the question with gridview declaration @ShivamOberoi also if this helps i can see the gridview data which i wanted to display(image and text) on my phone before the app crashes – shobhit khanduri Jan 23 '18 at 10:13
  • hey i updated the question with gridview declaration @KapilParmar also if this helps i can see the gridview data which i wanted to display(image and text) on my phone before the app crashes – shobhit khanduri Jan 23 '18 at 10:15
  • hey i updated the question with gridview declaration @Joe also if this helps i can see the gridview data which i wanted to display(image and text) on my phone before the app crashes – shobhit khanduri Jan 23 '18 at 10:16
  • I am using a fragment with three tabs.... all the tabs have the same gridview so its better to declare in one layout ........hey i updated the question with gridview declaration @sHOLE also if this helps i can see the gridview data which i wanted to display(image and text) on my phone before the app crashes – shobhit khanduri Jan 23 '18 at 10:17
  • check gridview = null while calling OfferParser(). – Kapil Parmar Jan 23 '18 at 10:20
  • @AmitVaghela have searched the web.nothing is working . please share me the link if you think this is duplicate question – shobhit khanduri Jan 23 '18 at 10:21
  • use separate xml file with gridview for each fragment. Declare each as separate. It may work – Jyoti JK Jan 23 '18 at 10:24
  • yes i am doing the same....... 1 Main Activity fragment(1 xml fragment)...... 3 Activity tabs( three fragment xml) file and 1 offergridmodel.xml which is gridview model.... @Joe the same i used for Recycler and it is working – shobhit khanduri Jan 23 '18 at 10:31
  • I changed my codes from if(result==0){ Toast.makeText(context,"Unable to parse ",Toast.LENGTH_SHORT); } //CALL ADAPTER TO BIND DATA TO GRIDVIEW OfferAdapterGv offerAdapter = new OfferAdapterGv(context, getOfferDatas); gv.setAdapter(offerAdapter); to ............... (next comment) – shobhit khanduri Jan 23 '18 at 10:59
  • if(result==0){ Toast.makeText(context,"Unable to parse ",Toast.LENGTH_SHORT); } else{ if(gv==null) { Toast.makeText(context,"grid view is null",Toast.LENGTH_SHORT); }else { //CALL ADAPTER TO BIND DATA TO GRIDVIEW OfferAdapterGv offerAdapter = new OfferAdapterGv(context, getOfferDatas); gv.setAdapter(offerAdapter); } } ......... next comment – shobhit khanduri Jan 23 '18 at 10:59
  • (please see last two comment for full .........) To check if gridview is null or not and to my surprise the error vanished(app is not crashing)...... Can anybody explain me how this happened me ????? seems to be a miracle to me @KapilParmar – shobhit khanduri Jan 23 '18 at 11:00
  • this means your gridview is not initialised when calling OfferParser() can please share your code how you are calling OfferParser() – Kapil Parmar Jan 23 '18 at 11:02
  • @KapilParmar buddy the problem is solved ....... but the question is how ???????? I dint change anything......i just added a IF statement to check if gv is null....... ( if u will check my last comment)....... i coded IF(GV==NULL)..THEN...Toast"gridvies is null"... ELSE .....RUN THE SAME CODE.... gv.setAdapter(new OfferAdapterGv(context, getOfferDatas)); ............ and Android studio decided to run the same code succesfully .....??????????? i dnt do anything ........can u explain how this happened ? it seems i am missing something – shobhit khanduri Jan 23 '18 at 11:12
  • just for your clarity Adroid studio was throwing error on gv.setAdapter(offerAdapter); ...... which(Error) somehow dnt exist when i added an if statement to check if gridview is null............ and the best part is gridview was not null else the program would have Toasted"gridview null" instead it ran gv.setAdapter(offerAdapter); succesfully.... :) @KapilParmar – shobhit khanduri Jan 23 '18 at 11:24
  • greate...enjoy coding – Kapil Parmar Jan 23 '18 at 11:34
  • lol thanks ........... – shobhit khanduri Jan 23 '18 at 11:36

0 Answers0