Nick Lopez
Nick Lopez

Reputation: 27

NullPointerException on Kindle Fire devices

I am continually getting these crash reports and I can't figure out why. This comes from a Kindle Fire, and they seem to be the only devices I am having errors on. I don't have one to test, but does anybody know why this NullPointerException only happens on Kindle Fire? Is it not compatible with SQLite? I never have any issues on my own test device or any crash reports from other Android devices. Any insight would be appreciated.

Also, fyi there is nothing I can identify from the code that should be causing this NullPointerException so I don't know what is making it happen only on a Kindle Fire..

java.lang.RuntimeException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2060)
    at android.app.ActivityThread.access$600(ActivityThread.java:127)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1181)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4558)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
    at org.orman.dbms.ResultList$ResultRow.getColumn(ResultList.java:31)
    at org.orman.mapper.ReverseMapping.map(ReverseMapping.java:51)
    at org.orman.mapper.Model.fetchQuery(Model.java:439)
    at com.appsbydesign.soundfxfree.helpers.SQLiteHelper.getSounds(SQLiteHelper.java:23)
    at com.appsbydesign.soundfxfree.SoundsActivityGrid.onStartSoundsActivityGrid (SoundsActivityGrid.java:260)
    at com.appsbydesign.soundfxfree.SoundsActivityGrid.onStart(SoundsActivityGrid.java)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
    at android.app.Activity.performStart(Activity.java:4646)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2008)
    ... 11 more

Here is part of the code from my SQLite Helper class that the error log says the issue is coming from:

public class SQLiteHelper {

        public static List<Category> getCategories() {
            return Model.fetchAll(Category.class);
        }

        public static List<Sound> getSounds(long categoryId) {
            Query query = ModelQuery.select().from(Sound.class)
                .where(C.eq(Sound.Columns.CATEGORY, categoryId)).getQuery();
            return Model.fetchQuery(query, Sound.class);
        }

Line 23 is this one: return Model.fetchQuery(query, Sound.class);

Here is part of the code from my SoundActivityGrid class that is also called in the error log. Line 260 is case 1: sounds = SQLiteHelper.getSounds(categoryId); in the code:

@Override
protected void onStart() {
    super.onStart();
    switch (activityName) {
    case 1:
        sounds = SQLiteHelper.getSounds(categoryId);
        break;

    case 2:
        sounds = SQLiteHelper.getRecordedCategory(categoryId);
        break;

    case 3:
        sounds = SQLiteHelper.getFavouriteSounds(categoryId);
        break;

    case 5:
        List<Sound> timedSounds = SQLiteHelper.getSounds(categoryId);
        sounds = new ArrayList<Sound>();
        for (Sound sound : timedSounds) {
            EntityList<Sound, Timer> timers = sound.getTimers();
            if (timers.size() > 0) {
                sounds.add(sound);
            }
        }
        break;
    case 7:
        List<Sound> timedSoundsGrid = SQLiteHelper.getSounds(categoryId);
        sounds = new ArrayList<Sound>();
        for (Sound sound : timedSoundsGrid) {
            EntityList<Sound, Timer> timers = sound.getTimers();
            if (timers.size() > 0) {
                sounds.add(sound);
            }
        }
        break;
    case 6:
        sounds = SQLiteHelper.getwidgetPlaySound(categoryId);
        break;

    }

I don't have access to org.orman.dbms.

Edit:

I was able to access the ResultList code in the orman dbms and this is what it said:

public class ResultList {
private String[] columnNames;
private Map<String, Integer> columnNameMap;


private Object[][] records;


public final class ResultRow {
    private Map<String, Integer> columnNameMap;
    private Object[] row;


    private ResultRow(Map<String, Integer> columnNameMap, Object[] row) {
        this.columnNameMap = columnNameMap;
        this.row = row;
    }


    public Object getColumn(String columnName) {
        return row[columnNameMap.get(columnName)]; // TODO if column does not exist throw xceptn
    }
}

Line 31 is:

return row[columnNameMap.get(columnName)]; // TODO if column does not exist throw xceptn

I don't know why it thinks a column does not exist. I do not fully understand how the database code works.

Upvotes: 0

Views: 361

Answers (1)

indivisible
indivisible

Reputation: 5012

Something is null when something else tries to use it.

Caused by: java.lang.NullPointerException
    at org.orman.dbms.ResultList$ResultRow.getColumn(ResultList.java:31)

I would start looking there.
Or if that is not a package you own then:

at com.appsbydesign.soundfxfree.helpers.SQLiteHelper.getSounds(SQLiteHelper.java:23)

Without seeing the code surrounding these locations all anyone can do it make wild guesses.

What I can possibly surmise from the stacktrace though is that you may be swallowing/catching too many Exceptions without logging the errors. If you get a null ResultSet or ResultRow I'd expect that you should see a complaint from somewhere earlier down the line.


Edit:

You are making it very difficult on yourself. It's incredibly tough to pinpoint exactly which object or what method is letting you down because you have so many condensed on each line.

My best guess would be

Query query = ModelQuery.select().from(Sound.class)
            .where(C.eq(Sound.Columns.CATEGORY, categoryId)).getQuery();

But what you should do right now is go back to your code and split it apart so that you only perform one action per line. Then if/when it crashes again you will have a much better idea of exactly which bit is causing the difficulty.

Update your code and stacktrace with the new versions and we'll see where we stand then.

Upvotes: 1

Related Questions