{"id":5279,"date":"2014-03-30T20:17:27","date_gmt":"2014-03-30T20:17:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-do-i-read-my-txt-file-into-a-list-view-collection-of-common-programming-errors\/"},"modified":"2014-03-30T20:17:27","modified_gmt":"2014-03-30T20:17:27","slug":"how-do-i-read-my-txt-file-into-a-list-view-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-do-i-read-my-txt-file-into-a-list-view-collection-of-common-programming-errors\/","title":{"rendered":"how do i read my .txt file into a list view-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to read lines stored in a separate txt file into my android application and have each line show up in the list view. The problem is though i cannot get anything to appear despite the fact my code says their are not errors in it. As you read this code, i will clarify right now that my list view is named &#8220;addresslist&#8221; and the file im reading from is named &#8220;myaddress.txt&#8221;. I appriciate any help i can get. Thank you.<\/p>\n<p>ListView listView= (ListView) findViewById(R.id.addresslist);<\/p>\n<pre><code>    try{\n        InputStream instream = openFileInput(\"myaddress.txt\");\n\n            InputStreamReader inputreader = new InputStreamReader(instream);\n            BufferedReader buffreader = new BufferedReader(inputreader);\n\n\n            ArrayList lines = new ArrayList();\n            boolean hasNextLine =true;\n            while (hasNextLine){\n                String line =  buffreader.readLine();\n                lines.add(line);\n                hasNextLine = line != null;\n\n            }\n            ArrayAdapter adapter = new ArrayAdapter(this,R.id.addresslist,lines);\n\n            listView.setAdapter(adapter);\n\n        instream.close();\n\n    }\n    catch(java.io.FileNotFoundException e){\n\n    }catch(java.io.IOException e){\n\n    }\n\n}\n<\/code><\/pre>\n<p>with the log erros<\/p>\n<p>12-08 01:21:30.394: E\/Trace(1500): [ 12-08 01:21:30.864 1500: 1500 V\/Home to School 4828 N. Crescent Norridge IL 60706, 5500 N St Louis Avenue Chicago IL 60625; Home to School 4828 N. Crescent Norridge IL 60706, 5500 N St Louis Avenue Chicago IL 60625; 12-08 01:21:30.864: D\/AndroidRuntime(1500): Shutting down VM 12-08 01:21:30.924: W\/dalvikvm(1500): threadid=1: thread exiting with uncaught exception (group=0xb3e92288) 12-08 01:21:30.944: E\/AndroidRuntime(1500): FATAL EXCEPTION: main 12-08 01:21:30.944: E\/AndroidRuntime(1500): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tripapp\/com.tripapp.Frontpage}: java.lang.NullPointerException: println needs a message 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.app.ActivityThread.access$600(ActivityThread.java:130) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.os.Handler.dispatchMessage(Handler.java:99) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.os.Looper.loop(Looper.java:137) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.app.ActivityThread.main(ActivityThread.java:4745) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at java.lang.reflect.Method.invokeNative(Native Method) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at java.lang.reflect.Method.invoke(Method.java:511) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at dalvik.system.NativeStart.main(Native Method) 12-08 01:21:30.944: E\/AndroidRuntime(1500): Caused by: java.lang.NullPointerException: println needs a message 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.util.Log.println_native(Native Method) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.util.Log.v(Log.java:117) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at com.tripapp.Frontpage.onCreate(Frontpage.java:61) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.app.Activity.performCreate(Activity.java:5008) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 12-08 01:21:30.944: E\/AndroidRuntime(1500): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 12-08 01:21:30.944: E\/AndroidRuntime(1500): &#8230; 11 more<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am trying to read lines stored in a separate txt file into my android application and have each line show up in the list view. The problem is though i cannot get anything to appear despite the fact my code says their are not errors in it. As you read this code, i will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5279","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5279"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5279\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}