1

I am getting this Run Time Error in Logcat:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.parse.ParseFile.getUrl()' on a null object reference
    at com.google.geoplace.MainActivity$RemoteDataTask.doInBackground(MainActivity.java:68)
    at com.google.geoplace.MainActivity$RemoteDataTask.doInBackground(MainActivity.java:36)
    at android.os.AsyncTask$2.call(AsyncTask.java:288)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
    at java.lang.Thread.run(Thread.java:818) 

Here is the MainActivity class

public class MainActivity extends Activity {
    // Declare Variables
    ListView listview;
    List<ParseObject> ob;
    ProgressDialog mProgressDialog;
    ListViewAdapter adapter;
    private List<PlaceFilter> worldpopulationlist = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view from listview_main.xml
        setContentView(R.layout.activity_main);
        // Execute RemoteDataTask AsyncTask
        new RemoteDataTask().execute();
    }

    // RemoteDataTask AsyncTask
    private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a progressdialog
            mProgressDialog = new ProgressDialog(MainActivity.this);
            // Set progressdialog title
            mProgressDialog.setTitle("Parse.com Custom ListView Tutorial");
            // Set progressdialog message
            mProgressDialog.setMessage("Loading...");
            mProgressDialog.setIndeterminate(false);
            // Show progressdialog
            mProgressDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            // Create the array
            worldpopulationlist = new ArrayList<PlaceFilter>();
            try {
                // Locate the class table named "Country" in Parse.com
                ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                        "geo_filters");
                // Locate the column named "ranknum" in Parse.com and order list
                // by ascending
                ob = query.find();
                for (ParseObject geo_filters : ob) {
                    // Locate images in flag column
                    ParseFile image = (ParseFile) geo_filters.get("FilterFile");

                    PlaceFilter map = new PlaceFilter();
                    map.setPlaceName((String) geo_filters.get("PlaceName"));
                    map.setFilterFile(image.getUrl());
                    worldpopulationlist.add(map);
                }
            } catch (ParseException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            // Locate the listview in listview_main.xml
            listview = (ListView) findViewById(R.id.listView);
            // Pass the results into ListViewAdapter.java
            adapter = new ListViewAdapter(MainActivity.this,
                    worldpopulationlist);
            // Binds the Adapter to the ListView
            listview.setAdapter(adapter);
            // Close the progressdialog
            mProgressDialog.dismiss();
        }
    }
}

Here is the PlaceFilter class:

public class PlaceFilter {
    private String PlaceName;
    private String FilterFile;

    public String getPlaceName() {
        return PlaceName;
    }

    public void setPlaceName(String PlaceName) {
        this.PlaceName = PlaceName;
    }

    public String getFilterFile() {
        return FilterFile;
    }

    public void setFilterFile(String FilterFile) {
        this.FilterFile = FilterFile;
    }
}

It was returning the PlaceName from Parse Backend without the image there was some syntax error in the PlaceFilter.java. After correcting the error I am getting the runtime error.

1 Answer 1

1

The immediate cause is that geo_filters.get("FilterFile") returned null. Next step you must do is to check what ParseObjects you have retrieved from "geo_filters" and why some of them have no "FilterFile" values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.