Skip to content Skip to sidebar Skip to footer

Attempt To Invoke Interface Method 'int Java.util.list.size()

FATAL EXCEPTION: main Attempt to invoke interface method 'int java.util.List.size()' on a null object reference I try to find nearby place .... this kind of error I get.... help

Solution 1:

The error is quite explanatory:

java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
                    at com.example.admin.newmapplace.MapsActivity$ParserTask.onPostExecute(MapsActivity.java:245)
                    at com.example.admin.newmapplace.MapsActivity$ParserTask.onPostExecute(MapsActivity.java:215)

If you check in the ParserTask onPostExecute, that line (215 or 245) should be:

for(int i=0;i<list.size();i++){

And the issue is that, that method receives a null "list" item, which is taken from the method parameter:

protectedvoidonPostExecute(List<HashMap<String,String>> list){

It is null because your "doInBackground" method returns a null object, looking at your code:

@OverrideprotectedList<HashMap<String,String>> doInBackground(String... jsonData) {

        List<HashMap<String, String>> places = null;
        PlaceJSONParser placeJsonParser = newPlaceJSONParser();

        try{
            jObject = newJSONObject(jsonData[0]);

            /** Getting the parsed data as a List construct */
            places = placeJsonParser.parse(jObject);

        }catch(Exception e){
            Log.d("Exception",e.toString());
        }
        return places;
    }

It seems that an exception is raised and then "places" is not set, leading to a null object returned. If you check the log (you set Debug, it's better to do Log.e in this cases), you should se a line with "Exception" and the text of the exception. An alternative for logging exception:

Log.e(TAGOFMESSAGE,"Raised an exception during doInBackground Method",e);

This will log an error and will put the stack trace of the exception in the log, helping you understanding what raised the exception.

Post a Comment for "Attempt To Invoke Interface Method 'int Java.util.list.size()"