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

  • SEARCH
  • Home
  • 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 8067789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:26:38+00:00 2026-06-05T12:26:38+00:00

I am getting an ArrayOutOfBounds exception when I am using my custom array adapter.

  • 0

I am getting an ArrayOutOfBounds exception when I am using my custom array adapter.

I am wondering if there are any coding errors I have overlooked.

Here is the error log:

06-10 20:21:53.254: E/AndroidRuntime(315): FATAL EXCEPTION: main
06-10 20:21:53.254: E/AndroidRuntime(315): java.lang.RuntimeException: Unable to start activity ComponentInfo{alex.android.galaxy.tab.latest/alex.android.galaxy.tab.latest.Basic_db_output}: java.lang.ArrayIndexOutOfBoundsException
06-10 20:21:53.254: E/AndroidRuntime(315):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-10 20:21:53.254: E/AndroidRuntime(315):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-10 20:21:53.254: E/AndroidRuntime(315):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-10 20:21:53.254: E/AndroidRuntime(315):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-10 20:21:53.254: E/AndroidRuntime(315):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 20:21:53.254: E/AndroidRuntime(315):  at android.os.Looper.loop(Looper.java:123)
06-10 20:21:53.254: E/AndroidRuntime(315):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-10 20:21:53.254: E/AndroidRuntime(315):  at java.lang.reflect.Method.invokeNative(Native Method)
06-10 20:21:53.254: E/AndroidRuntime(315):  at java.lang.reflect.Method.invoke(Method.java:521)
06-10 20:21:53.254: E/AndroidRuntime(315):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-10 20:21:53.254: E/AndroidRuntime(315):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-10 20:21:53.254: E/AndroidRuntime(315):  at dalvik.system.NativeStart.main(Native Method)
06-10 20:21:53.254: E/AndroidRuntime(315): Caused by: java.lang.ArrayIndexOutOfBoundsException
06-10 20:21:53.254: E/AndroidRuntime(315):  at alex.android.galaxy.tab.latest.Basic_db_output.onCreate(Basic_db_output.java:44)
06-10 20:21:53.254: E/AndroidRuntime(315):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-10 20:21:53.254: E/AndroidRuntime(315):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

I am basing my code example on this: How to use ArrayAdapter<myClass>.

ArrayList<Question> list = new ArrayList<Question>();

for(int i=1; i <= 3; i++)
{       
    path = getAssets().open("quiz"+i+".txt");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Reader reader = new ResultsReader(path);
    reader.read();

    String str = ((ResultsReader)reader).getInput();
    String data[] = str.split("<.>");

    Question q = new Question();

    q.question = data[0];
    q.answer = Integer.parseInt(data[1]);
    q.choice1 = data[2];
    q.choice2 = data[3];
    q.choice3 = data[4];
    list.add(q);
}
  • 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-06-05T12:26:40+00:00Added an answer on June 5, 2026 at 12:26 pm

    When you do

     String data[] = str.split("<.>");
    

    it is going to return you an array of uncertain length, unless you know the input is correct all the time you are going to run into issues when you do the below:

        q.question = data[0];
        q.answer = Integer.parseInt(data[1]);
        q.choice1 = data[2];
        q.choice2 = data[3];
        q.choice3 = data[4];
    

    Perhaps you should think of another technique where you don’t rely on calling explicit index’s of your array.

    For example:

    if(data.length == 4){
            q.question = data[0];
            q.answer = Integer.parseInt(data[1]);
            q.choice1 = data[2];
            q.choice2 = data[3];
            q.choice3 = data[4];
    } else {
       Log.e("YourApp", "Data was not split from file correctly");
    }
    

    or add some more debug before you use the split data array:

    for(int i=0; i < data.length; i++){
       Log.d("YourApp", "DataReceived:"+data[i];
    }
    

    Edit

    Oh yeah the issue will be the emulator / your phone hasn’t got a clue what

     C:/
    

    is.

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

Sidebar

Related Questions

I am trying to create custom array indexed from 1 using subscript operator. Getting
getting errors when trying to write into a SQL database using the 2 following
Getting started with TDD and the repository pattern, I'm wondering if it makes any
Getting an Undefined Offset error here -- apparently from the $newval array. Note that
Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
Getting java.io.EOFException while sending a large java object using AciveMQ. Below is the large
Getting No Data Access Object for AudienceManagerProfile when I make any OE API calls.
Getting some odd behavior from google custom search that I can't seem to suss
Getting started with NHibernate How can I generate identity fields in nHibernate using Hilo
Getting Invalid Application Path error. Here are the steps I've taken. Right click on

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.