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

NullPointerException on queryBuilder #14

Closed
alexsilva opened this issue Jun 27, 2014 · 3 comments
Closed

NullPointerException on queryBuilder #14

alexsilva opened this issue Jun 27, 2014 · 3 comments

Comments

@alexsilva
Copy link

In Google Analytics I have the following records:

...
    2.  NullPointerException (@PlayList:getDatabaseAlbum:386) {Thread-108}
    3.  NullPointerException (@PlayList:getDatabaseAlbum:386) {Thread-11086}    
    4.  NullPointerException (@PlayList:getDatabaseAlbum:386) {Thread-11189}    
    5.  NullPointerException (@PlayList:getDatabaseAlbum:386) {Thread-1125} 
    6.  NullPointerException (@PlayList:getDatabaseAlbum:386) {Thread-1194} 
    7.  NullPointerException (@PlayList:getDatabaseAlbum:386) {Thread-1204}

On Google Play the following:

java.lang.NullPointerException
    at es.hol.soundmedia.PlayList.getDatabaseAlbum(PlayList.java:386)
    at es.hol.soundmedia.PlayList.access$200(PlayList.java:31)
    at es.hol.soundmedia.PlayList$3.run(PlayList.java:458)
    at java.lang.Thread.run(Thread.java:856)

User Reports:

Android 4.1 3 75,0%
Hoje, 00:09 (APP 4.2.7) DROID RAZR i (smi) (PT-BR - dando erro quando escolhe musica)

Android 4.3 1 25,0%
2 de jun 11:31 (APP 4.2.4) Galaxy S3 (d2usc) Great application.

Beginning of the implementation is to get to the error:

    public void checkAll(final Group group, final Album album,
                         final List<Music> musics, final OnCheckListener callback){
        new Thread(new Runnable() {
            @Override
            public void run() {
                Handler handler = new Handler(Looper.getMainLooper());
                final Map<Integer,Boolean> map = new HashMap<Integer, Boolean>();
                Album _album = getDatabaseAlbum(group, album);
                if (!_album.hasValidId()) {
                    for (int index=0; index < musics.size(); index++)
                        map.put(index, false);
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            callback.onCheckResult(map);
                        }
                    });
                    return;
                }
                for (int index=0; index < musics.size(); index++){
                    map.put(index, hasValidId(getDatabaseMusic(_album, musics.get(index))));
                }
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        callback.onCheckResult(map);
                    }
                });
            }
        }).start();
    }

Location of the error:

383    private Album getDatabaseAlbum(Group group, Album album){
384     QueryBuilder<Album, Integer> db = mAlbumDao.queryBuilder();
385     try {
386            Where<Album,Integer> where = db.where()
387                    .eq(Album.GROUP_ID_FIELD, group.getId()).and()
                    .eq(Album.ARTIST_FIELD, new SelectArg(album.getArtist())).and()
                    .eq(Album.URL_FIELD, new SelectArg(album.getUrl()));
            Album _album  = where.queryForFirst();

            if (hasValidId(_album))
                album = _album;
            else
                album.invalidateId();
        } catch (SQLException e) {
            Log.d(MainActivity.TAG, "Music", e);
            album.invalidateId();
        }
        return album;
    }

I see no other possibility besides 'queryBuilder'(var db) be returning null. Any idea why the error ?

384     QueryBuilder<Album, Integer> db = mAlbumDao.queryBuilder();
385     try {
386            Where<Album,Integer> where = db.where()

APP https://play.google.com/store/apps/details?id=es.hol.soundmedia

@j256
Copy link
Owner

j256 commented Jun 27, 2014

2.  NullPointerException (@PlayList:getDatabaseAlbum:386) {Thread-108}

Careful about assigning too much weight to the specific line number.

I see no other possibility besides 'queryBuilder'(var db) be returning null. Any idea why the error ?

I think it is more likely that your DAO is null. There is no way for the dao.queryBuild(...) method to return null:

public QueryBuilder<T, ID> queryBuilder() {
    checkForInitialized();
    return new QueryBuilder<T, ID>(databaseType, tableInfo, this);
}

gray

On Jun 27, 2014, at 1:25 PM, Alex Sandro notifications@github.com wrote:

In Google Analytics I have the following records:

...
2. NullPointerException (@playlist:getDatabaseAlbum:386) {Thread-108}
3. NullPointerException (@playlist:getDatabaseAlbum:386) {Thread-11086}
4. NullPointerException (@playlist:getDatabaseAlbum:386) {Thread-11189}
5. NullPointerException (@playlist:getDatabaseAlbum:386) {Thread-1125}
6. NullPointerException (@playlist:getDatabaseAlbum:386) {Thread-1194}
7. NullPointerException (@playlist:getDatabaseAlbum:386) {Thread-1204}

On Google Play the following:

java.lang.NullPointerException
at es.hol.soundmedia.PlayList.getDatabaseAlbum(PlayList.java:386)
at es.hol.soundmedia.PlayList.access$200(PlayList.java:31)
at es.hol.soundmedia.PlayList$3.run(PlayList.java:458)
at java.lang.Thread.run(Thread.java:856)

User Reports:

Hoje, 00:09 (ANDROID 4.2.7) DROID RAZR i (smi) (PT-BR - dando erro quando escolhe musica)
2 de jun 11:31 (ANDROID 4.2.4) Galaxy S3 (d2usc) Great application.

Beginning of the implementation is to get to the error:

public void checkAll(final Group group, final Album album,
                     final List<Music> musics, final OnCheckListener callback){
    new Thread(new Runnable() {
        @Override
        public void run() {
            Handler handler = new Handler(Looper.getMainLooper());
            final Map<Integer,Boolean> map = new HashMap<Integer, Boolean>();
            Album _album = getDatabaseAlbum(group, album);
            if (!_album.hasValidId()) {
                for (int index=0; index < musics.size(); index++)
                    map.put(index, false);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        callback.onCheckResult(map);
                    }
                });
                return;
            }
            for (int index=0; index < musics.size(); index++){
                map.put(index, hasValidId(getDatabaseMusic(_album, musics.get(index))));
            }
            handler.post(new Runnable() {
                @Override
                public void run() {
                    callback.onCheckResult(map);
                }
            });
        }
    }).start();
}

Location of the error:

383 private Album getDatabaseAlbum(Group group, Album album){
384 QueryBuilder<Album, Integer> db = mAlbumDao.queryBuilder();
385 try {
386 Where<Album,Integer> where = db.where()
387 .eq(Album.GROUP_ID_FIELD, group.getId()).and()
.eq(Album.ARTIST_FIELD, new SelectArg(album.getArtist())).and()
.eq(Album.URL_FIELD, new SelectArg(album.getUrl()));
Album _album = where.queryForFirst();

        if (hasValidId(_album))
            album = _album;
        else
            album.invalidateId();
    } catch (SQLException e) {
        Log.d(MainActivity.TAG, "Music", e);
        album.invalidateId();
    }
    return album;
}

I see no other possibility besides 'queryBuilder'(var db) be returning null. Any idea why the error ?

384 QueryBuilder<Album, Integer> db = mAlbumDao.queryBuilder();
385 try {
386 Where<Album,Integer> where = db.where()

APP https://play.google.com/store/apps/details?id=es.hol.soundmedia


Reply to this email directly or view it on GitHub.

@alexsilva
Copy link
Author

To avoid boot daos null pointer, I capture the error:

    public void initialize() {
        databaseHelper = getHelper();
        try {
            mGroupDao = databaseHelper.getDao(Group.class);
            mAlbumDao = databaseHelper.getDao(Album.class);
            mMusicDao = databaseHelper.getDao(Music.class);
        } catch (SQLException e){
            throw new AssertionError(e.getMessage());
        }
        getDefaultGroup(); // initializes the default group.
    }

Since you mentioned that the line number may be wrong, I will give attention to other things, as:

.eq(Album.GROUP_ID_FIELD, group.getId()).and()

Maybe "group" is the cause of the null pointer.

@j256
Copy link
Owner

j256 commented Jan 29, 2015

I'm going to close this issue. Feel free to disagree and reopen if you have some more information that this is a bug in ORMLite. Thanks.

@j256 j256 closed this as completed Jan 29, 2015
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

2 participants