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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:53:27+00:00 2026-06-10T05:53:27+00:00

I’m trying to do something like endless adapter but not able to accomplish it

  • 0

I’m trying to do something like endless adapter but not able to accomplish it and as a result my app is crashing.
What i tried to do is that initially i wanted loaded 10items in listview and add foorterview at the end of listview.If user clicks on the footerview than 10 more item is loaded in the listview.

But when i start that activity only footerview appears and after few seconds application crashes.
I have posted the relevant code below:

int questionsPerPage = 10;
boolean loadingMore = false;
ArrayList<DataHolder> myquestionsResults;
QuestionListViewAdapter adapter;

//in onCreate
lv = (ListView) findViewById(R.id.lv_questions);
    // add the footer before adding the adapter, else the footer will not
    // load!
    View footerView = ((LayoutInflater) this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
            R.layout.listfooter, null, false);
    footerView.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            Thread thread = new Thread(null, loadMoreListItems);
            thread.start();
        }
    });
    lv.addFooterView(footerView);
    myquestionsResults = new ArrayList<DataHolder>();
    adapter = new QuestionListViewAdapter(this, myquestionsResults);
    lv.setAdapter(adapter);
    lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> a, View v, int position,
                long id) {
            Object o = lv.getItemAtPosition(position);
            DataHolder fullObject = (DataHolder) o;
            Intent intent = new Intent(getApplicationContext(),
                    ViewMyQuestion.class);
            intent.putExtra("id", fullObject.getId());
            startActivity(intent);

        }

    });

    // Load the first 10 items
    Thread thread = new Thread(null, loadMoreListItems);
    thread.start();
}// End of onCreate

private ArrayList<DataHolder> GetMyQuestionsResult() {
    ArrayList<DataHolder> myquestionInfo = new ArrayList<DataHolder>();
    HashMap<String, String> hm = new HashMap<String, String>();
    db = new DatabaseHandler(getApplicationContext());
    db.getReadableDatabase();
    hm = db.getUserDetails();
    db.close();
    String un = hm.get("username");

    uf = new UserFunctions();
    JSONArray json = uf.getQuestionsByUsername(un);
    int x = json.length();
    try {
        if (x > 0) {
            for (int i = 0; i < x; i++) {
                ja = json.getJSONArray(i);
                id = ja.getString(0);
                userName = ja.getString(1);
                question = ja.getString(2);
                tag1 = ja.getString(3);
                tag2 = ja.getString(4);
                tag3 = ja.getString(5);
                posted_on = ja.getString(6);
                DataHolder qih = new DataHolder();
                qih.setId(id);
                qih.setUserName(userName);
                qih.setQuestion(question);
                qih.setTag1(tag1);
                qih.setTag2(tag2);
                qih.setTag3(tag3);
                qih.setQuestionPostedOn(posted_on);
                myquestionInfo.add(qih);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();

    }
    return myquestionInfo;
}
// Runnable to load the items
private Runnable loadMoreListItems = new Runnable() {
    public void run() {
        // Set flag so we cant load new items 2 at the same time
        loadingMore = true;

        // Reset the array that holds the new items


        // Get 10 new listitems
        for (int i = 0; i < questionsPerPage; i++) {
            // Fill the item with some bogus information
            myquestionsResults.add(GetMyQuestionsResult().get(i));

        }

        // Done! now continue on the UI thread
        runOnUiThread(returnRes);

    }
};

// Since we cant update our UI from a thread this Runnable takes care of
// that!
private Runnable returnRes = new Runnable() {
    @SuppressWarnings("unchecked")
    public void run() {

        // Tell to the adapter that changes have been made, this will cause
        // the list to refresh
        ((BaseAdapter) lv.getAdapter()).notifyDataSetChanged();

        // Done loading more.
        loadingMore = false;
    }
};

Below is my logcat messages:

08-27 06:00:03.799: E/AndroidRuntime(280): FATAL EXCEPTION: main
08-27 06:00:03.799: E/AndroidRuntime(280): java.lang.ClassCastException:    android.widget.HeaderViewListAdapter
08-27 06:00:03.799: E/AndroidRuntime(280):  at com.vervecoders.cuqu.MyQuestions$3.run(MyQuestions.java:275)
08-27 06:00:03.799: E/AndroidRuntime(280):  at android.os.Handler.handleCallback(Handler.java:587)
08-27 06:00:03.799: E/AndroidRuntime(280):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-27 06:00:03.799: E/AndroidRuntime(280):  at android.os.Looper.loop(Looper.java:123)
08-27 06:00:03.799: E/AndroidRuntime(280):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-27 06:00:03.799: E/AndroidRuntime(280):  at java.lang.reflect.Method.invokeNative(Native Method)
08-27 06:00:03.799: E/AndroidRuntime(280):  at java.lang.reflect.Method.invoke(Method.java:521)
08-27 06:00:03.799: E/AndroidRuntime(280):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-27 06:00:03.799: E/AndroidRuntime(280):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-27 06:00:03.799: E/AndroidRuntime(280):  at dalvik.system.NativeStart.main(Native Method)

After updating code it crashed again.Following are the new logcat messages:

08-27 07:38:47.751: I/dalvikvm(349): "main" prio=5 tid=1 RUNNABLE
08-27 07:38:47.751: I/dalvikvm(349):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001d8e0 self=0xccb0
08-27 07:38:47.751: I/dalvikvm(349):   | sysTid=349 nice=0 sched=0/0 cgrp=default handle=-1345026008
08-27 07:38:47.751: I/dalvikvm(349):   | schedstat=( 33038897911 15262681460 1352 )
08-27 07:38:47.751: I/dalvikvm(349):   at java.util.ArrayList.add(ArrayList.java:~123)
08-27 07:38:47.765: I/dalvikvm(349):   at com.vervecoders.cuqu.MyQuestions$3.run(MyQuestions.java:267)
08-27 07:38:47.765: I/dalvikvm(349):   at android.os.Handler.handleCallback(Handler.java:587)
08-27 07:38:47.771: I/dalvikvm(349):   at android.os.Handler.dispatchMessage(Handler.java:92)
08-27 07:38:47.771: I/dalvikvm(349):   at android.os.Looper.loop(Looper.java:123)
08-27 07:38:47.771: I/dalvikvm(349):   at android.app.ActivityThread.main(ActivityThread.java:4627)
08-27 07:38:47.785: I/dalvikvm(349):   at java.lang.reflect.Method.invokeNative(Native Method)
08-27 07:38:47.785: I/dalvikvm(349):   at java.lang.reflect.Method.invoke(Method.java:521)
08-27 07:38:47.785: I/dalvikvm(349):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-27 07:38:47.785: I/dalvikvm(349):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-27 07:38:47.785: I/dalvikvm(349):   at dalvik.system.NativeStart.main(Native Method)
08-27 07:38:47.811: D/AndroidRuntime(349): Shutting down VM
08-27 07:38:47.811: W/dalvikvm(349): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-27 07:38:47.845: E/AndroidRuntime(349): FATAL EXCEPTION: main
08-27 07:38:47.845: E/AndroidRuntime(349): java.lang.OutOfMemoryError
08-27 07:38:47.845: E/AndroidRuntime(349):  at java.util.ArrayList.add(ArrayList.java:123)
08-27 07:38:47.845: E/AndroidRuntime(349):  at com.vervecoders.cuqu.MyQuestions$3.run(MyQuestions.java:267)
08-27 07:38:47.845: E/AndroidRuntime(349):  at android.os.Handler.handleCallback(Handler.java:587)
08-27 07:38:47.845: E/AndroidRuntime(349):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-27 07:38:47.845: E/AndroidRuntime(349):  at android.os.Looper.loop(Looper.java:123)
08-27 07:38:47.845: E/AndroidRuntime(349):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-27 07:38:47.845: E/AndroidRuntime(349):  at java.lang.reflect.Method.invokeNative(Native Method)
08-27 07:38:47.845: E/AndroidRuntime(349):  at java.lang.reflect.Method.invoke(Method.java:521)
08-27 07:38:47.845: E/AndroidRuntime(349):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-27 07:38:47.845: E/AndroidRuntime(349):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-27 07:38:47.845: E/AndroidRuntime(349):  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-10T05:53:29+00:00Added an answer on June 10, 2026 at 5:53 am
    ((ArrayList<DataHolder>) lv.getAdapter()).add(myquestionsResults.get(i));
    

    Why are you casting the adapter to an ArrayList? This probably causes the ClassCastException

    Try adding the new items to your myquestionsResults, and then notifying the adapter.

    Better yet, you can add a method add() (or even addAll()) to your implementation of QuestionListViewAdapter, that will add the items to the list and invoke notifyDataSetChanged(). In that case you could make your adapter a member variable and use it directly, and not getting it from the cached ListView.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.