java - Android: NullPointerException when reading a txt file -


i'm trying write translator app android , want read txt file. nullpointerexception trying read file. have put txt file assets folder think app can't find :( code:

(this code of class vocabtrainer line 160: (vocse, vocsg linkedlists , vocmape, vocmapg hasmaps fields of vocabtrainer))

try{         assetmanager manager;         manager = currentcontext.getassets();         inputstream input = manager.open("vocabs.txt");         inputstreamreader inputreader = new inputstreamreader(input);          bufferedreader reader = new bufferedreader(inputreader);         string word = null;          while ((word = reader.readline()) != null) {             //splitts given string when there given " "              string[] wordsplit = word.split(" ");              vocse.add(wordsplit[0]);             vocsg.add(wordsplit[1]);              vocmape.put(wordsplit[0], wordsplit[1]);             vocmapg.put(wordsplit[1], wordsplit[0]);         }         reader.close();     }     catch (ioexception e) {         e.printstacktrace();     } 

and here logcat trace:

04-18 17:24:27.204: e/androidruntime(1736): java.lang.runtimeexception: unable     instantiate activity   componentinfo{de.dbgeppelheim.dbgvocab/de.dbgeppelheim.dbgvocab.trainingactivity}:  java.lang.nullpointerexception 04-18 17:24:27.204: e/androidruntime(1736):     @   android.app.activitythread.performlaunchactivity(activitythread.java:2106) 04-18 17:24:27.204: e/androidruntime(1736):     @    android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 04-18 17:24:27.204: e/androidruntime(1736):     @    android.app.activitythread.access$600(activitythread.java:141) 04-18 17:24:27.204: e/androidruntime(1736):     @     android.app.activitythread$h.handlemessage(activitythread.java:1234) 04-18 17:24:27.204: e/androidruntime(1736):     @    android.os.handler.dispatchmessage(handler.java:99) 04-18 17:24:27.204: e/androidruntime(1736):     @    android.os.looper.loop(looper.java:137) 04-18 17:24:27.204: e/androidruntime(1736):     @     android.app.activitythread.main(activitythread.java:5039) 04-18 17:24:27.204: e/androidruntime(1736):     @    java.lang.reflect.method.invokenative(native method) 04-18 17:24:27.204: e/androidruntime(1736):     @   java.lang.reflect.method.invoke(method.java:511) 04-18 17:24:27.204: e/androidruntime(1736):     @    com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 04-18 17:24:27.204: e/androidruntime(1736):     @    com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 04-18 17:24:27.204: e/androidruntime(1736):     @     dalvik.system.nativestart.main(native method) 04-18 17:24:27.204: e/androidruntime(1736): caused by: java.lang.nullpointerexception 04-18 17:24:27.204: e/androidruntime(1736):     @    android.content.contextwrapper.getresources(contextwrapper.java:89) 04-18 17:24:27.204: e/androidruntime(1736):     @    android.view.contextthemewrapper.getresources(contextthemewrapper.java:78) 04-18 17:24:27.204: e/androidruntime(1736):     @    de.dbgeppelheim.functionality.vocabtrainer.initialise(vocabtrainer.java:167) 04-18 17:24:27.204: e/androidruntime(1736):     @    de.dbgeppelheim.functionality.vocabtrainer.<init>(vocabtrainer.java:40) 04-18 17:24:27.204: e/androidruntime(1736):     @    de.dbgeppelheim.dbgvocab.trainingactivity.<init>(trainingactivity.java:25) 04-18 17:24:27.204: e/androidruntime(1736):     @   java.lang.class.newinstanceimpl(native method) 04-18 17:24:27.204: e/androidruntime(1736):     @    java.lang.class.newinstance(class.java:1319) 04-18 17:24:27.204: e/androidruntime(1736):     @    android.app.instrumentation.newactivity(instrumentation.java:1054) 04-18 17:24:27.204: e/androidruntime(1736):     @    android.app.activitythread.performlaunchactivity(activitythread.java:2097) 04-18 17:24:27.204: e/androidruntime(1736):     ... 11 more 

this question explains how you're trying do. follow steps, come if still doesn't work.

reading simple text file


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -