Jump to content

Hello, I'm making a Guild Wars 2 app. In the code below I get the different WvWvW matches. The api returns them but when I call "DatabaseHelper.loadWorldNames(matches)". It gives me a nullpointer exeption. So I've been debugging and I saw that in the DatabaseHelper the program doesn't go to Application.getDatabaseHelper().getWorldDao(). The code is provided below.

 

Backgroundloader:

public class MatchLoader extends BackgroundTaskLoader<List<Match>>{    public MatchLoader(Context context)    {        super(context);    }   @[member=OverRide]    public List<Match> loadInBackground() {        try {            HttpsURLConnection connection =                    (HttpsURLConnection) new URL("https://api.guildwars2.com/v1/wvw/matches.json").openConnection();            List<Match> matches = new Gson().fromJson(new InputStreamReader(connection.getInputStream()),                    Response.class).wvw_matches;            DatabaseHelper.loadWorldNames(matches);            Collections.sort(matches, new Comparator<Match>() {                @[member=OverRide]                public int compare(Match match, Match match2) {                    return match.wvw_match_id.compareTo(match2.wvw_match_id);                }            });            return matches;        } catch (Exception e) {            Log.e(Application.Constants.LOG_TAG, "Error loading matches", e);            return null;        }    }    private class Response {        public List<Match> wvw_matches;    }}

DatabaseHelper:

 public static void loadWorldNames(List<Match> matches) throws Exception {        if (Application.getDatabaseHelper().getWorldDao().queryForAll().size() == 0) {            HttpsURLConnection connection =                    (HttpsURLConnection) new URL("https://api.guildwars2.com/v1/world_names.json").openConnection();            final List<world> worlds =                    new Gson().fromJson(new InputStreamReader(connection.getInputStream()),                            new TypeToken<List<world>>() {                            }.getType());            Application.getDatabaseHelper().getEventNameDao().callBatchTasks(new Callable<Object>() {                @[member=OverRide]                public Object call() throws Exception {                    for (world world : worlds) {                        Application.getDatabaseHelper().getWorldDao().create(world);                    }                    return null;                }            });        }        for (Match match : matches) {            match.redWorld = Application.getDatabaseHelper().getWorldDao().queryForId(match.red_world_id);            match.greenWorld = Application.getDatabaseHelper().getWorldDao().queryForId(match.green_world_id);            match.blueWorld = Application.getDatabaseHelper().getWorldDao().queryForId(match.blue_world_id);        }    }    public Dao<world, Integer> getWorldDao() throws Exception {        if (worldDao == null) {            worldDao = DaoManager.createDao(getConnectionSource(), world.class);        }        return worldDao;    }

Anyone who can help? 

 

sorry if I made any spelling errors, english isn't my native language.

Link to comment
https://linustechtips.com/topic/323646-android-ormlite-problem/
Share on other sites

Link to post
Share on other sites

Here you go

03-07 20:18:02.201    1279-1320/be.dimitrikozakiewiez.gw2companion E/GW2 Companion﹕ Error loading matches    java.lang.NullPointerException            at be.dimitrikozakiewiez.gw2companion.database.DatabaseHelper.loadWorldNames(DatabaseHelper.java:53)            at be.dimitrikozakiewiez.gw2companion.background.MatchLoader.loadInBackground(MatchLoader.java:32)            at be.dimitrikozakiewiez.gw2companion.background.MatchLoader.loadInBackground(MatchLoader.java:20)            at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)            at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)            at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:57)            at android.os.AsyncTask$2.call(AsyncTask.java:288)            at java.util.concurrent.FutureTask.run(FutureTask.java:237)            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)            at java.lang.Thread.run(Thread.java:841)

Info: 

Line 53 in DatabastHelper.java is 

if (Application.getDatabaseHelper().getWorldDao().queryForAll().size() == 0) {

Line 32 in Matchloader.java is:

DatabaseHelper.loadWorldNames(matches);

If you want I can send you the android studio project.

Link to comment
https://linustechtips.com/topic/323646-android-ormlite-problem/#findComment-4400916
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×