Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RadarView crashes with NPE if there is no worldListType = 0 #75

Open
gb96 opened this issue Jul 6, 2015 · 0 comments
Open

RadarView crashes with NPE if there is no worldListType = 0 #75

gb96 opened this issue Jul 6, 2015 · 0 comments

Comments

@gb96
Copy link

gb96 commented Jul 6, 2015

java.lang.NullPointerException
    at com.beyondar.android.plugin.radar.RadarView.drawRadarPoints(RadarView.java:69)
    at com.beyondar.android.plugin.radar.RadarView.onDraw(RadarView.java:60)

Looking at RadarView.java I see the code is attempting to iterate over worldListType using an int counter starting at zero, causing the NPE if there is no worldListType=0 defined. Safer to just use Java collection iterator (or for-each loop) here, the int counters are not required.

// in RadarView#drawRadarPoints(Canvas):
for (int i = 0; i < mRadarPlugin.getWorld().getBeyondarObjectLists().size(); i++) {
    BeyondarObjectList list = mRadarPlugin.getWorld().getBeyondarObjectList(i);
    for (int j = 0; j < list.size(); j++) { // line 69, NPE here when list == null
        BeyondarObject beyondarObject = list.get(j);
        RadarPointPlugin radarPointPlugin = (RadarPointPlugin) beyondarObject
                .getFirstPlugin(RadarPointPlugin.class);

Easily fixed (and more elegant) using Java for-each loop instead of dodgy int indexes like this:

// in RadarView#drawRadarPoints(Canvas):
for (BeyondarObjectList list : mRadarPlugin.getWorld().getBeyondarObjectLists()) {
    for (BeyondarObject beyondarObject : list) {
        RadarPointPlugin radarPointPlugin = (RadarPointPlugin) beyondarObject
                .getFirstPlugin(RadarPointPlugin.class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant