AssetManager to parse local JSON file returns NullPointer : <p>I have red many topics and questions about it, but can't find any solution. I am also very new to Android and Java.</p>

<p>What I was trying to do is to parse my local JSON file and to set an adapter to view my Strings in a ListView. Shouldn't be too complicated, but I got this error:</p>

<pre><code>01-10 10:04:38.109 29962-29962/com.thkoeln.stucked E/AndroidRuntime: FATAL EXCEPTION: main
                                                                 Process: com.thkoeln.stucked, PID: 29962
                                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com../com...MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.content.Context.getAssets()' on a null object reference
                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                     at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                     at android.os.Looper.loop(Looper.java:148)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.content.Context.getAssets()' on a null object reference
                                                                     at android.content.ContextWrapper.getAssets(ContextWrapper.java:81)
                                                                     at com.thkoeln.stucked.JSONParser.loadJSONFromAsset(JSONParser.java:28)
                                                                     at com.thkoeln.stucked.JSONParser.parseJson(JSONParser.java:52)
                                                                     at com.thkoeln.stucked.MainActivity.onCreate(MainActivity.java:24)
                                                                     at android.app.Activity.performCreate(Activity.java:6237)
                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                     at android.os.Looper.loop(Looper.java:148) 
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
</code></pre>

<p>And here is my MainActivity.java :</p>

<pre><code>package com.thkoeln.stucked;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;

public class MainActivity extends AppCompatActivity {

ListView activityList;


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

    activityList = (ListView) findViewById(R.id.activityList);

    String fromArray[] = {"uid", "uname", "ustart"};
    int to[] = {R.id.uid, R.id.uname, R.id.ustart};

    JSONParser jp = new JSONParser();
    jp.parseJson();
    /*ListAdapter adapter = new SimpleAdapter(this, jp.userList, R.layout.user_item, fromArray, to);
    activityList.setAdapter(adapter);*/

    }


}
</code></pre>

<p>And this is my JSONParser.java :</p>

<pre><code>package com.thkoeln.stucked;

import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ListView;

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

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;


public class JSONParser extends AppCompatActivity {

ArrayList&lt;HashMap&lt;String, String&gt;&gt; userList;

public String loadJSONFromAsset() {
    String json = null;
    try {
        InputStream is = getAssets().open("users.json");

        int size = is.available();

        byte[] buffer = new byte[size];

        is.read(buffer);

        is.close();

        json = new String(buffer, "UTF-8");

    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return json;

}

public JSONObject parseJson() {

    //ArrayList&lt;HashMap&lt;String, String&gt;&gt; userList
    try {

        JSONObject reader = new 
       JSONObject(String.valueOf(loadJSONFromAsset()));

        JSONArray users = reader.getJSONArray("users");
        Log.d("AnzahlUser", String.valueOf(users.length()));

        for (int i = 0; i &lt; users.length(); i++) {
            JSONObject u = users.getJSONObject(i);
            Log.d("Details--&gt;", u.toString());
            String uid = u.getString("uid");
            String uname = u.getString("uname");
            String ustart = u.getString("ustart");
            //String uend = u.getString("u.end");

            HashMap&lt;String, String&gt; user = new HashMap&lt;&gt;();

            user.put("uid", uid);
            user.put("uname", uname);
            user.put("ustart", ustart);
            //user.put("u.end", uend);

            userList.add(user);




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

    return null;
    }
}
</code></pre>

<p>I would be so thankful, if someone could help me with these ...</p>
