0

Why when I import a Text File to my project it shows me an error?

I need the text file to read some info from it and display it on a ListView. Here is a screenshot of what I am talking about.

enter image description here

Questions
  • 303
  • 5
  • 16

3 Answers3

0

All data files in this directory must be XML format.

There are several kinds of data you can put here. See http://developer.android.com/guide/topics/resources/more-resources.html for details.

For example:

res/values/strings.xml

<string name="prefs">Version</string>

would be referenced in Java code as

String version = context.getResources().getString(R.id.prefs);
EJK
  • 12,332
  • 3
  • 38
  • 55
0

You cannot use a textile to fill a ListView, you should set it on strings.xml, add the String name and his value. @String can be stored and retrieved as resources.

Marckaraujo
  • 7,422
  • 11
  • 59
  • 97
  • I do not know how to work with XML files. I do not want to confuse you, but this Text File contains an Html Code. I am planning to parse from it using Jsoup library. Do you understand what I am trying to do? – Questions Jan 13 '13 at 01:19
0

To open raw resources, you need to use openRawResource().

For example, if you're in an Activity, you can open the raw text file as:

InputStream input = getResources().openRawResource(R.raw.textfile);

This returns an InputStream, which allows you to read from your file.

This SO question provides a nice code sample for basic reading of a raw text file.

Community
  • 1
  • 1
A--C
  • 36,351
  • 10
  • 106
  • 92