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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:10:57+00:00 2026-05-23T06:10:57+00:00

I am not sure I am doing this right, with my limited knowledge of

  • 0

I am not sure I am doing this right, with my limited knowledge of this programming language… or any for that matter. Let’s see if I can make this make sense so I can get some help.

I am running a query against my database to pull out all entries in the database

Part of DBAdapter.java:

//***RETRIEVES ALL THE FINALSCORES***//
public Cursor getAllFinalscores()
{
    return db.query(DATABASE_TABLE, new String[] {
            KEY_ROWID,
            KEY_DATE,
            KEY_FINALSCORE,
            KEY_HOLESPLAYED},
            null, null, null, null, null);
}

I have then created a separate class which extends ListActivity (because I want all of the contents to be displayed in a listview.

PastGames.java

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class PastGames extends ListActivity {

@Override

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



    DBAdapter db = new DBAdapter(this);

    db.open();
    Cursor c = db.getAllFinalscores();
    if (c.moveToFirst())
    {
        do {
            String[] listData = new String [] {c.getString(1),
                    c.getString(2), c.getString(3)};
            this.setListAdapter(new ArrayAdapter<String>(this,
                    R.layout.pastgames, listData));
        }
        while (c.moveToNext());
    }
    db.close();


}

}

and then I am calling that from my Main activity (which just to note, does not extend ListActivity

    @Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
case R.id.past_games:
            Intent intentListGames = new Intent().setClass( this, PastGames.class );
            this.startActivityForResult( intentListGames, 0 );
            return true;
   }
        return true;
    }

So, if I understand this correctly, I am calling PastGames.java from my main activity (which then launches PastGames.java) and within PastGames.java – onCreate I am opening the db, running my query, closing and hopefully putting into listview

I get the following in LogCat when I run that option in emulator:

06-13 22:10:36.581: ERROR/AndroidRuntime(204): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.deckert/com.deckert.PastGames}: java.lang.ClassCastException: android.widget.TextView
06-13 22:10:36.581: ERROR/AndroidRuntime(204):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
06-13 22:10:36.581: ERROR/AndroidRuntime(204):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-13 22:10:36.581: ERROR/AndroidRuntime(204):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)

Could someone please help me understand why this isnt working?

Thank you in advance and I apologize for the huge post!

  • 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-05-23T06:10:59+00:00Added an answer on May 23, 2026 at 6:10 am

    You are using the same layout in both your ArrayAdapter and your PastGames Activity root view. I imagine that you do not want to use the ListView‘s layout for your Activities layout. I think this is what is causing the ClassCastException, because your ListView‘s layout is probably defined to use just a simple TextView, and the Activity is blowing up saying that it cannot cast a ListView to a TextView.

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

Sidebar

Related Questions

Im not sure if I'm doing this right. I have an action that I
Not too sure if I'm doing this right. It looks a bit more convoluted
I'm not sure if I'm doing this the right way. I have table which
am not sure if I'm doing this right, but I'm trying to create a
I am not sure if I am doing this right but just wanted to
Not sure if I'm doing this right: /(https?:\/\/\S+)(\s|(& nbsp;))?/g; This should match a URL
I'm not 100% sure I'm doing this right, but I think I've found an
Not sure if I am doing this right. Reading: http://devcenter.heroku.com/articles/cron#frequently-asked-questions If I have cron
I'm not sure I'm doing this the right way, so I'm open to other
I am not sure if I am doing this right. I have a list

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.