Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3393326
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:02:15+00:00 2026-05-18T04:02:15+00:00

I have a text file that I am pulling from my SD card which

  • 0

I have a text file that I am pulling from my SD card which contains an array in plain text format. Here are the contents of that file …

http://www.oddree.com/rayhaque/android1.jpg,http://www.oddree.com/rayhaque/android2.jpg,http://www.oddree.com/rayhaque/android3.jpg,http://www.oddree.com/rayhaque/android4.jpg,http://www.oddree.com/rayhaque/android5.jpg

I am trying to import that text file into a String, convert that String to an array, and then load that array into a list adapter. If I try to split up readString or a trimmed result of readString, I get a forced close every time. If I copy the contents of the file into a String and then use that … everything works as expected.

So what is the difference between loading this stuff from a text file, and loading it from an included string? Is it a byte conversion issue?

Here is my code. I have noted what works and what fails.

public class MainActivity extends Activity {

ListView list;
LazyAdapter adapter;
List<String> strings = new ArrayList<String>();
String readString = new String();
String arrayNBOW;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    try{
     File f = new File(Environment.getExternalStorageDirectory()+"/LazyList/gkindex.txt");
     FileInputStream fileIS = new FileInputStream(f);
     BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));

     while((readString = buf.readLine())!= null){
      String arrayNBOW = readString.trim();
      Toast.makeText(MainActivity.this, "STARTUPPULL: "+arrayNBOW, Toast.LENGTH_LONG).show();
     }
  } catch (FileNotFoundException e) {
   Toast.makeText(MainActivity.this, "FAIL: "+e, Toast.LENGTH_LONG).show();
   e.printStackTrace();
  } catch (IOException e){
   Toast.makeText(MainActivity.this, "FAIL: "+e, Toast.LENGTH_LONG).show();
   e.printStackTrace();
  }

    setContentView(R.layout.main);
    list=(ListView)findViewById(R.id.list);

    String testArray = "http://www.oddree.com/rayhaque/android1.jpg,http://www.oddree.com/rayhaque/android2.jpg,http://www.oddree.com/rayhaque/android3.jpg";

    // THIS FAILS
    // String[] testArraySplit = TextUtils.split(arrayNBOW, ",");

    // THIS WORKS
    String[] testArraySplit = TextUtils.split(testArray, ",");

    adapter=new LazyAdapter(this, testArraySplit);
 list.setAdapter(adapter);

    Button b=(Button)findViewById(R.id.button1);
    b.setOnClickListener(listener);

    Button c=(Button)findViewById(R.id.button2);
    c.setOnClickListener(loadtext);

}

Thank you in advance for any advice or assistance you can offer me! 🙂

SOLUTION CREATED FROM EMANNUEL’S SUGGESTION:

public class MainActivity extends Activity {

ListView list;
LazyAdapter adapter;
List<String> strings = new ArrayList<String>();
String readString = new String();
String arrayNBOW;
String[] nardsArray;
String nards;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

// New Solution

  File sdcard = Environment.getExternalStorageDirectory();
  File file = new File(sdcard,"/LazyList/gkindex.txt");
  StringBuilder text = new StringBuilder();

  try {
      BufferedReader br = new BufferedReader(new FileReader(file));
      String line;

      while ((line = br.readLine()) != null) {
          text.append(line);
          text.append('\n');
          nards = text.toString();
          nardsArray = TextUtils.split(nards, ",");
      }
  }
  catch (IOException e) {
      Toast.makeText(MainActivity.this, "FAIL: "+e, Toast.LENGTH_LONG).show();
  }

// End New Solution

    Toast.makeText(MainActivity.this, "FILE-READ: "+nardsArray, Toast.LENGTH_LONG).show();

    setContentView(R.layout.main);
    list=(ListView)findViewById(R.id.list);

    adapter=new LazyAdapter(this, nardsArray);
    list.setAdapter(adapter);

    Button b=(Button)findViewById(R.id.button1);
    b.setOnClickListener(listener);

    Button c=(Button)findViewById(R.id.button2);
    c.setOnClickListener(loadtext);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:02:15+00:00Added an answer on May 18, 2026 at 4:02 am

    I suspect your reading didn’t work. First thing I noticed is that there’s no finally clause for closing streams. Second is you’re looping until the end of the file. What if you had an empty line there? Check for empty “” lines. Also you should break on the first line that has contents.

    Also, I prefer to use a FileReader like this:

    Does this help?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.