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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:13:42+00:00 2026-06-03T08:13:42+00:00

I’m making a dream dictionary, i’m reading from a txt file and saving to

  • 0

I’m making a dream dictionary, i’m reading from a txt file and saving to array for displaying it to a listview. But there are some errors from the log cat, can anybody tell me what is wrong.

    05-07 14:29:06.750: E/AndroidRuntime(29135): FATAL EXCEPTION: main
05-07 14:29:06.750: E/AndroidRuntime(29135): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sonovnik.petkovski/com.sonovnik.petkovski.Main}: java.lang.ArrayIndexOutOfBoundsException
05-07 14:29:06.750: E/AndroidRuntime(29135):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at android.app.ActivityThread.access$1500(ActivityThread.java:123)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at android.os.Looper.loop(Looper.java:130)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at android.app.ActivityThread.main(ActivityThread.java:3835)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at java.lang.reflect.Method.invokeNative(Native Method)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at java.lang.reflect.Method.invoke(Method.java:507)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at dalvik.system.NativeStart.main(Native Method)
05-07 14:29:06.750: E/AndroidRuntime(29135): Caused by: java.lang.ArrayIndexOutOfBoundsException
05-07 14:29:06.750: E/AndroidRuntime(29135):    at com.sonovnik.petkovski.Main.readTxt(Main.java:115)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at com.sonovnik.petkovski.Main.initStuff(Main.java:131)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at com.sonovnik.petkovski.Main.onCreate(Main.java:39)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-07 14:29:06.750: E/AndroidRuntime(29135):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
05-07 14:29:06.750: E/AndroidRuntime(29135):    ... 11 more

Here is the code:

    public class Main extends ListActivity {
    private ArrayList<Son> sonovi;
    private EditText filterText = null;
    private SonovnikAdapter adapter;
    private ListView list;
    Translator t = new Translator();
    private Intent intent;
    private ArrayList<Son> temp;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initStuff();

        list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                intent.putExtra("opis", sonovi.get(position).getOpis());
                intent.putExtra("naslov", sonovi.get(position).getNaslov());
                startActivity(intent);

            }
        });
        filterText.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {

                String test = filterText.getText().toString().toUpperCase();
                int dolzina = filterText.length();
                temp = new ArrayList<Son>();
                for (int i = 0; i < sonovi.size(); i++) {
                    if (filterText.getText().toString().toLowerCase().equals(
                                    (String) sonovi.get(i).getLatinicno().toLowerCase()
                                            .subSequence(0, dolzina))) {
                        temp.add(sonovi.get(i));
                    }

                }

                SonovnikAdapter testc = new SonovnikAdapter(Main.this,
                        R.layout.item, temp);
                list.setAdapter(testc);
                testc.notifyDataSetChanged();
                list.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
                        intent.putExtra("opis", temp.get(position).getOpis());
                        intent.putExtra("naslov", temp.get(position)
                                .getNaslov());
                        startActivity(intent);
                    }
                });

            }
        });

    }

    private ArrayList<Son> readTxt() {
        ArrayList<Son> s = new ArrayList<Son>();
        InputStream is = this.getResources().openRawResource(R.raw.sonovnik);
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String str = null;
        String naslov, opis, latinica;
        String[] tmp;
        try {
            while ((str = br.readLine()) != null) {
                tmp = str.split("-");
                naslov = tmp[0].toString();
                opis = tmp[1].toString();

                latinica = tmp[2].toString(); //line 115
                 Log.v("test", latinica);
                s.add(new Son(naslov, opis, latinica));
            }
            is.close();
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    private void initStuff() {
        list = getListView();
        list.setTextFilterEnabled(true);
        sonovi = new ArrayList<Son>();
        sonovi = readTxt(); //line 131
        intent = new Intent(this, Details.class);
        adapter = new SonovnikAdapter(this, R.layout.item, sonovi);
        setListAdapter(this.adapter);
        filterText = (EditText) findViewById(R.id.search_box);
    }

    private class SonovnikAdapter extends ArrayAdapter<Son> {

        private ArrayList<Son> items;

        public SonovnikAdapter(Context context, int textViewResourceId,
                ArrayList<Son> items) {
            super(context, textViewResourceId, items);
            this.items = items;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.list_item, null);
            }
            Son o = items.get(position);
            if (o != null) {
                TextView naslov = (TextView) v.findViewById(R.id.textView1);
                if (naslov != null) {
                    naslov.setText(o.getNaslov().toString());
                }
            }
            return v;

        }
    }
}
  • 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-03T08:13:44+00:00Added an answer on June 3, 2026 at 8:13 am

    Here is your problem:

                tmp = str.split("-");
                naslov = tmp[0].toString();
                opis = tmp[1].toString();
    
                latinica = tmp[2].toString(); //line 115
    

    You split the string using “-” as a delimiter, but you never check into how many pieces it was actually split. Apparently, your input text file contains some line that has only one “-” in it, so it is split into only two pieces, and tmp[2] is out of range.

    Also, there is no need for calling .toString(), since tmp is already an array of strings.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

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.