0

I'm developing a app, which works pretty well on the Android Studio Emulator, but when I built a APK and installed on my phone, it closes and crashes. So I decided to run it on my phone, debugging with ADB.

Looks like the problem is in line 67 of that Java code (https://pastebin.com/y8c5yMYj)

for (int i = 0; i < itemlist.size();i++){
        Points item = itemlist.get(i);
        googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(Double.valueOf(item.getPosx()), Double.valueOf(item.getPosy())))
                .snippet(item.getDescription())
                .icon(BitmapDescriptorFactory.fromResource(MarkerChange(item.getType())))
                .title(item.getName()));

    }

.. But I wasn't able to fix that, someone can give me some help with this issue?

Thanks... and sorry for any posting mistake: I am a newbie here in StackOverflow and English isn't my native language.

luksBR2556
  • 11
  • 4
  • hey people, all of that tips that you provided me were worth, the app doesn't crashed anymore, but now, the markers don't show up on the map (in my real phone, with Android 7.0 - Galaxy S6). But everything ever worked/works well on the Android Studio Emulator (despite running the same Android 7.0 as my phone or another version)... – luksBR2556 Sep 10 '18 at 17:05

3 Answers3

0

Solution:

Add this line is your onCreateView()

Itemlist = new ArrayList<>();

Hope it works.

Ümañg ßürmån
  • 9,695
  • 4
  • 24
  • 41
0

You have not initialized your ArrayList.Edit your code

public static ArrayList<Points> itemlist;

with

public static ArrayList<Points> itemlist = new ArrayList<>();

This will solve your issue with "NullPointerException"

Sana
  • 456
  • 3
  • 9
  • hey @Sana, the tips that you provided me were worth, the app doesn't crashed anymore, but now, the markers don't show up on the map (in my real phone, with Android 7.0 - Galaxy S6). But everything ever worked/works well on the Android Studio Emulator (despite running the same Android 7.0 as my phone or another version).. – luksBR2556 Sep 10 '18 at 17:07
  • Hey welcome ! :) That's a android version problem I think.I have not faced it ever.Can you post the error log? – Sana Sep 10 '18 at 17:16
  • And if the tips have worked you can accept the answer or upvote it.This will help other to find the correct answer.Thank you – Sana Sep 10 '18 at 17:18
  • 1
    Hey, thanks for commenting back. I already found a workaround for the last issue and everything looks well after I applied your solution and my workaround. Also thanks for everyone that helped me today, I really admire and enjoy the efforts that people like you do to help the community. – luksBR2556 Sep 10 '18 at 18:32
0

Change your onCreateView() like this.

@Override
 public  View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.geometry_cube, container, false);

    SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
            .findFragmentById(R.id.mapFragment);
    mapFragment.getMapAsync(this);

   itemlist = new ArrayList<>();


    return v;
}

you need to declare your ArrayList<>() as a new ArrayList everytime you load that page

Rubick
  • 296
  • 3
  • 22