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 8131483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:06:15+00:00 2026-06-06T09:06:15+00:00

I have a code that should get a LinearLayout (with more LinearLayout’s inside), and

  • 0

I have a code that should get a LinearLayout (with more LinearLayout’s inside), and get all the views within them. There are some textviews that have tags, and according to this, it should build 3 strings. The problem is it throws an exception in the first line after the loop. here’s a code sample to explain:

private void insertToDB(final DataBaseHelper db, LinearLayout layout, 
                              String subject, String term, String meaning) 
{
    View v1 = null;
    for(int i=0; i < layout.getChildCount(); i++) {
        try {
            v1 = layout.getChildAt(i);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        if(v1 instanceof LinearLayout)
        {
            insertToDB(db, ((LinearLayout)v1), subject, term, meaning);
        }
        if (v1.getTag() != null) {
            String val = v1.getTag().toString();
            if (val.equals("subject")) {
                subject = ((TextView)v1).getText().toString();
            }
            else if (val.equals("term")) {
                term+=((TextView)v1).getText().toString()+"$";
            }
            else if (val.equals("meaning")) {
                meaning+=((TextView)v1).getText().toString()+"$";
            }

        }
    }
    term = term.substring(0, term.length()-1);
    meaning = meaning.substring(0, meaning.length()-1);
    Card c = new Card(subject, term, meaning);
    db.Insert(c);
} 

Stacktrace:

06-25 20:27:59.332: D/AndroidRuntime(269): Shutting down VM
06-25 20:27:59.332: W/dalvikvm(269): threadid=1: thread exiting with uncaught exception (group=0x4001d800)

06-25 20:28:01.551: E/AndroidRuntime(269): FATAL EXCEPTION: main
06-25 20:28:01.551: E/AndroidRuntime(269): java.lang.StringIndexOutOfBoundsException
06-25 20:28:01.551: E/AndroidRuntime(269):  at java.lang.String.substring(String.java:1579)
06-25 20:28:01.551: E/AndroidRuntime(269):  at com.ronEven.iCards.AddRemove$1.insertToDB(AddRemove.java:78)
06-25 20:28:01.551: E/AndroidRuntime(269):  at com.ronEven.iCards.AddRemove$1.insertToDB(AddRemove.java:62)
06-25 20:28:01.551: E/AndroidRuntime(269):  at com.ronEven.iCards.AddRemove$1.onClick(AddRemove.java:46)
06-25 20:28:01.551: E/AndroidRuntime(269):  at android.view.View.performClick(View.java:2408)
06-25 20:28:01.551: E/AndroidRuntime(269):  at android.view.View$PerformClick.run(View.java:8816)
06-25 20:28:01.551: E/AndroidRuntime(269):  at android.os.Handler.handleCallback(Handler.java:587)
06-25 20:28:01.551: E/AndroidRuntime(269):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-25 20:28:01.551: E/AndroidRuntime(269):  at android.os.Looper.loop(Looper.java:123)
06-25 20:28:01.551: E/AndroidRuntime(269):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-25 20:28:01.551: E/AndroidRuntime(269):  at java.lang.reflect.Method.invokeNative(Native Method)
06-25 20:28:01.551: E/AndroidRuntime(269):  at java.lang.reflect.Method.invoke(Method.java:521)
06-25 20:28:01.551: E/AndroidRuntime(269):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-25 20:28:01.551: E/AndroidRuntime(269):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-25 20:28:01.551: E/AndroidRuntime(269):  at dalvik.system.NativeStart.main(Native Method)
  • 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-06T09:06:18+00:00Added an answer on June 6, 2026 at 9:06 am

    One of your String.substring calls after the loop apparently causes that problem because they are trying to extract a String portion from an empty string.

    Therefore:

    emptyString.length() – 1 = -1

    Which is an illegal index within a String.

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

Sidebar

Related Questions

I frequently have some code that should be run either on a schedule or
So far I have managed to write some code that should print the source
I have some debugging code that if executed while running with GBD attached should
I have got a piece of code, that should countdown some number (in this
I have some C code that should print the entire contents of a file.
I have a code that should get unique string(for example, d86c52ec8b7e8a2ea315109627888fe6228d) from client and
I have a XAML code that should load my UserControl inside the TabControl .
I have some code that should remove the parent row of the clicked td
So I have a query that should get all posts from a table while
I have some PHP code that should cause and catch two exceptions: try{ @$this->connector->connect();

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.