Android NullPointerException when adding items to ArrayList<>

I am stuck at this point and have no idea how to solve this NullPointerException… I did not change much but after the few code changes I had these problems and I now cannot figure where the error comes from…
Code:

public class Levelhandler {
    public BoardElement[][] matrix;
    private int levelNr = 1;
    private ArrayList<Wall> allWalls;
    private ArrayList<Character> allCharacters;
    private ArrayList<Finish> allFinishes;

    // context
    private Context context;

    public Levelhandler(Context context) {
        this.context = context;
        matrix = new BoardElement[12][22];
        allWalls = new ArrayList<Wall>();
        Log.v("init", "done init");
        allCharacters = new ArrayList<Character>();
        allFinishes = new ArrayList<Finish>();

        for (int i = 0; i < 12; i++) {
            for (int j = 0; j < 22; j++) {
                matrix[j] = null;
            }
        }
    }

..........

public void loadWalls() {
        allWalls = null;
        Scanner s = null;

        try {
            s = new Scanner(context.getAssets().open(
                    "lev" + levelNr + "/walls.txt"));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ArrayList<String> list = new ArrayList<String>();
        while (s.hasNext()) {
            list.add(s.next());
        }
        s.close();
        for (String line : list) {
            allWalls.add(new Wall(context,
                    Integer.valueOf(line.split("\\;")[0]), Integer.valueOf(line
                            .split("\\;")[1])));
            matrix[Integer.valueOf(line.split("\\;")[0])][Integer.valueOf(line
                    .split("\\;")[1])] = new Wall(context, Integer.valueOf(line
                    .split("\\;")[0]), Integer.valueOf(line.split("\\;")[1]));
        }
    }

Error:

04-04 14:33:37.970: E/AndroidRuntime(10193): FATAL EXCEPTION: main
04-04 14:33:37.970: E/AndroidRuntime(10193): Process: com.paulk.pacman, PID: 10193
04-04 14:33:37.970: E/AndroidRuntime(10193): java.lang.NullPointerException
04-04 14:33:37.970: E/AndroidRuntime(10193):    at com.paulk.pacman.Levelhandler.loadCharacters(Levelhandler.java:121)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at com.paulk.pacman.PacManView.onDraw(PacManView.java:58)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.draw(View.java:15397)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14291)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14333)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.draw(View.java:15111)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.drawChild(ViewGroup.java:3318)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3155)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14286)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14333)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.draw(View.java:15111)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.drawChild(ViewGroup.java:3318)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3155)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14286)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14333)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.draw(View.java:15111)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.drawChild(ViewGroup.java:3318)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3155)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14286)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14333)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.draw(View.java:15111)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.drawChild(ViewGroup.java:3318)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3155)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14286)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14333)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.draw(View.java:15111)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.drawChild(ViewGroup.java:3318)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3155)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14286)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14333)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.draw(View.java:15111)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.drawChild(ViewGroup.java:3318)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3155)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.draw(View.java:15400)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.widget.FrameLayout.draw(FrameLayout.java:472)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2583)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14291)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.View.getDisplayList(View.java:14333)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1585)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1457)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2779)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2645)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2213)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1256)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6635)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:813)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.Choreographer.doCallbacks(Choreographer.java:613)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.Choreographer.doFrame(Choreographer.java:583)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:799)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.os.Handler.handleCallback(Handler.java:733)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.os.Handler.dispatchMessage(Handler.java:95)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.os.Looper.loop(Looper.java:146)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at android.app.ActivityThread.main(ActivityThread.java:5593)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at java.lang.reflect.Method.invokeNative(Native Method)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at java.lang.reflect.Method.invoke(Method.java:515)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
04-04 14:33:37.970: E/AndroidRuntime(10193):    at dalvik.system.NativeStart.main(Native Method)


Download android.nullpointerexception.when.adding.items.to.arraylist.zip
Direct Link


Download


Download android.nullpointerexception.when.adding.items.to.arraylist.zip
Mediafire


Download


Download android.nullpointerexception.when.adding.items.to.arraylist.zip
EASY-SHARE


Download

Both comments and pings are currently closed.

Comments are closed.