Home Ask Login Register

Developers Planet

Your answer is one click away!

Puja Garg February 2016

java.lang.RuntimeException: An error occured while executing doInBackground() in Popmovie app

I am beginner in android development . I am trying to make movies app but I got this error . Here is my code

public class MovieFragment extends Fragment {

    public MovieFragment() {
  //  ArrayAdapter<String> movieAdapter;
    MovieAdapter movieAdapter;
    GridView gridView;

    public void onCreate(Bundle savedInstanceState) {
        //Add this line in order for this fragment to handle menu events.

    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // Inflate the menu; this adds items to the action bar if it is present.
        inflater.inflate(R.menu.moviefragment, menu);

    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_refresh) {
            FetchMovieTask movieTask = new FetchMovieTask();
            return true;

        return super.onOptionsItemSelected(item);

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);

     /*   movieAdapter = new ArrayAdapter<String>(getActivity(),
                new ArrayList<String>()); */
        movieAdapter = new MovieAdapter(getActivity());
        gridView = (GridView)rootView.findViewById(R.id.gridview); 

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {


Yazan February 2016

there is an uninitialized arraylist movies in method getMovieDataFromJson()

so when you call movies.add(indexMovie); it cause NPE, to solve this change:

ArrayList<Movie> movies = null;

to this

ArrayList<Movie> movies = new ArrayList<>();

in method getMovieDataFromJson()

Post Status

Asked in February 2016
Viewed 2,910 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life