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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:05:17+00:00 2026-06-02T19:05:17+00:00

Like the title says ocasionally my application crashes and I am not sure why

  • 0

Like the title says ocasionally my application crashes and I am not sure why it does it.

Here is the code:

This is the where I get the input:
public class SearchActivity extends Activity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);

    final EditText edittext = (EditText) findViewById(R.id.edittext);
    edittext.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Perform action on key press
                String query = edittext.getText().toString();
                // gets the text and makes sure its a string
                Intent intent = new Intent(SearchActivity.this,
                        DissertationActivity.class);
                intent.putExtra("query1", query);
                startActivity(intent);

                return true;
            }
            return false;
        }
    });

    final Button button = (Button) findViewById(R.id.searchButton);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String query = edittext.getText().toString();
            // gets the text and makes sure its a string

            Intent intent = new Intent(SearchActivity.this,
                    DissertationActivity.class);
            intent.putExtra("query1", query);
            startActivity(intent);

        }
    });

}
 }

// Second activity that does the retrieving of the results

         public class DissertationActivity extends ListActivity {
/** Called when the activity is first created. */

public ArrayList<String> book_Array = new ArrayList<String>();
ArrayAdapter<String> adapter;

String href = "";
String href1 = "";
String search_Word = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle extras = getIntent().getExtras();
    search_Word = extras.getString("query1");

    adapter = new ArrayAdapter<String>(this, R.layout.list_item_1,
            book_Array);
    setListAdapter(adapter);

    new LoadingProgressBar().execute();

}

class LoadingProgressBar extends AsyncTask<String, Integer, String> {

    ProgressDialog pDialog = new ProgressDialog(DissertationActivity.this);

    protected void onPreExecute() {
        this.pDialog.setMessage("Loading");
        this.pDialog.show();

    }

    @Override
    protected String doInBackground(String... params) {

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        try {
            Document doc = null;
            Document guestLink = null;

            guestLink = Jsoup.connect("https://aulib.abdn.ac.uk:443/F")
                    .get();
            Element link = guestLink.select("p > a").first();
            href1 = link.attr("href");
            href = href1.substring(0, href1.length() - 2); // removes -0
                                                            // from
                                                            // the

            // href_Array.add(href); //adds href to the array because string
            // wont add to the public var.
            doc = Jsoup.connect(
                    href + "&request=" + search_Word
                            + "&find_code=WRD&adjacent=N&x=0&y=0").get();
            // System.out.println(doc);
            Elements headings = doc.select("td:eq(3)");
            // System.out.println(headings);
            for (Element heading : headings) {
                // System.out.println(heading.text());
                String j = heading.text();

                book_Array.add(j);

            }

        } catch (IOException e) {
            e.printStackTrace();

        }

        book_Array.remove(0);
        book_Array.remove(1);
        book_Array.remove(2);
        book_Array.remove("Search");
        book_Array.remove(" | ");
        book_Array.remove(0);

        pDialog.dismiss();

        lv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> a, View v, int position,
                    long id) {

                int query = position;

                Intent intent = new Intent(DissertationActivity.this,
                        FullDetailsActivity.class);
                intent.putExtra("href", href);
                intent.putExtra("query1", (int) query);
                intent.putExtra("search_Word", search_Word);

                startActivity(intent);

            }

        });
        return null;
    }

}

}

Here is the stack trace (sorry I don’t know how to format this):

04-26 17:17:20.722: E/WindowManager(8576):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
04-26 17:19:41.679: E/AndroidRuntime(8608): FATAL EXCEPTION: AsyncTask #5
04-26 17:19:41.679: E/AndroidRuntime(8608): java.lang.RuntimeException: An error occured while executing doInBackground()
04-26 17:19:41.679: E/AndroidRuntime(8608):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at java.lang.Thread.run(Thread.java:1019)
04-26 17:19:41.679: E/AndroidRuntime(8608): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
04-26 17:19:41.679: E/AndroidRuntime(8608):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at java.util.ArrayList.remove(ArrayList.java:406)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at com.library_app.DissertationActivity$LoadingProgressBar.doInBackground(DissertationActivity.java:102)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at com.library_app.DissertationActivity$LoadingProgressBar.doInBackground(DissertationActivity.java:1)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-26 17:19:41.679: E/AndroidRuntime(8608):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
04-26 17:19:41.679: E/AndroidRuntime(8608):     ... 4 more
04-26 17:19:41.879: E/WindowManager(8608): Activity com.library_app.DissertationActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@407aadc8 that was originally added here
04-26 17:19:41.879: E/WindowManager(8608): android.view.WindowLeaked: Activity com.library_app.DissertationActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@407aadc8 that was originally added here
04-26 17:19:41.879: E/WindowManager(8608):  at android.view.ViewRoot.<init>(ViewRoot.java:259)
04-26 17:19:41.879: E/WindowManager(8608):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
04-26 17:19:41.879: E/WindowManager(8608):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-26 17:19:41.879: E/WindowManager(8608):  at android.view.Window$LocalWindowManager.addView(Window.java:465)
04-26 17:19:41.879: E/WindowManager(8608):  at android.app.Dialog.show(Dialog.java:241)
04-26 17:19:41.879: E/WindowManager(8608):  at com.library_app.DissertationActivity$LoadingProgressBar.onPreExecute(DissertationActivity.java:59)
04-26 17:19:41.879: E/WindowManager(8608):  at android.os.AsyncTask.execute(AsyncTask.java:391)
04-26 17:19:41.879: E/WindowManager(8608):  at com.library_app.DissertationActivity.onCreate(DissertationActivity.java:49)
04-26 17:19:41.879: E/WindowManager(8608):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-26 17:19:41.879: E/WindowManager(8608):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
04-26 17:19:41.879: E/WindowManager(8608):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
04-26 17:19:41.879: E/WindowManager(8608):  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2953)
04-26 17:19:41.879: E/WindowManager(8608):  at android.app.ActivityThread.access$1600(ActivityThread.java:123)
04-26 17:19:41.879: E/WindowManager(8608):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
04-26 17:19:41.879: E/WindowManager(8608):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 17:19:41.879: E/WindowManager(8608):  at android.os.Looper.loop(Looper.java:130)
04-26 17:19:41.879: E/WindowManager(8608):  at android.app.ActivityThread.main(ActivityThread.java:3835)
04-26 17:19:41.879: E/WindowManager(8608):  at java.lang.reflect.Method.invokeNative(Native Method)
04-26 17:19:41.879: E/WindowManager(8608):  at java.lang.reflect.Method.invoke(Method.java:507)
04-26 17:19:41.879: E/WindowManager(8608):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
04-26 17:19:41.879: E/WindowManager(8608):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
04-26 17:19:41.879: E/WindowManager(8608):  at dalvik.system.NativeStart.main(Native Method)

It will only crash sometimes. It is always after I search for something. I have also noticed that if I go back using the button on the phone and try to search for something again it crashes, not all times but only some times.

What would be causing the crash? How would I fix it?

Thanks!

  • 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-02T19:05:18+00:00Added an answer on June 2, 2026 at 7:05 pm
    "Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0"
    

    shows you that you are trying to access an array that has a size of 0 (empty)

    "at java.util.ArrayList.remove"
    

    tells me that its being caused by you trying to remove items from your array.

    Likely, one of these lines:

    book_Array.remove(0);
    book_Array.remove(1);
    book_Array.remove(2);
    book_Array.remove("Search");
    book_Array.remove(" | ");
    book_Array.remove(0);
    

    is causing it since you aren’t checking anywhere to make sure your book_array actually has those values.

    at com.library_app.DissertationActivity$LoadingProgressBar.doInBackground(DissertationActivity.java:102)
    

    gives you the exact line that is causing your exception so you can check that line and make sure you validate your values prior to executing it. (Double click that line in logcat and it will take you to that line of code if you’re using Eclipse)

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

Sidebar

Related Questions

Like the title says, my code basically does this: set proxy, test proxy, do
Like the title says, I can't get Canvas/CanvasLayer working in PlayN. My sample code
So, just like the title says, I need to create an application that gets
Like the title says, I want to parse XML in my iPhone application, but
Like the title says, I have the following exception: Description: Event code: 3005 Event
Like the title says, what's the best way in JavaScript to get all radio
Like the title says, should I still be designing my application around a 16
i want to do what the title says like this: int number1; cin>>number1; num1len=log10(number1)+1;
As the title says I have a string like this: $string = "Hello World<br>hello
Like the title says Where and How (i.e. if encrypted, with what method) does

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.