由于代码缺陷导致的空指针异常

问题描述 投票:0回答:0

我在 android studio 中遇到这个错误,无法理解 hopw 来解决这个错误。请帮帮我。

错误在这里-

  FATAL EXCEPTION: main java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference at com.pujagoodies.sacred.MandirMainActivity$SwipeListener.getData(MandirMainActivity.java:1230) at com.pujagoodies.sacred.MandirMainActivity$5.onDataChange(MandirMainActivity.java:491) at com.google.firebase.database.Query$1.onDataChange(Query.java:191) at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:75) at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63) at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:210) at android.app.ActivityThread.main(ActivityThread.java:7080) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:523) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:863)

here is the code where it leads on clicking  MandirMainActivity.java- public void getData(ArrayList<MainGods> mg) {

//            mainGods = new ArrayList<>(mg); //            mainGods = new ArrayList<>(); int p = 0, m = 0; while ((p != position.size()) && (m != mg.size())) { if (position.get(p) == m) { mainGods.add(mg.get(m)); p += 1; m += 1; } else { m += 1; } }
nullpointerexception crash
© www.soinside.com 2019 - 2024. All rights reserved.