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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:45:11+00:00 2026-05-15T23:45:11+00:00

Here is my Arrival.java package one.two; import java.io.IOException; import java.util.ArrayList; import java.util.List; import android.app.ListActivity;

  • 0

Here is my Arrival.java

package one.two;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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

public class Arrival extends ListActivity
{
    private ListView listView;


    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState)
    {
        ArrayList<String> retList = new ArrayList<String>();

        System.out.println("Start onCreate Function\n");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
        System.out.println("In onCreate Function\n");
        System.out.println("In of GetData\n");
        DBAdapter db = new DBAdapter(this); 

        System.out.println("DB Open\n");
        db.open();
        System.out.println("DB Opened\n");
        retList = getData();
        System.out.println("Out of GetData\n");
        // force count no. of records in table
        // dump to check index
        int cnt = 2;

        int i=0;
        for (i = 0; i<cnt; i++)
            System.out.println(retList.toString());
        System.out.println("Array 2 String\n");

        Cursor c = db.getCursor();
        String[] from = new String[] {DBAdapter.status};
        int[] to = new int[] {R.id.txt1};


        SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.listtext, c, from, to);
        this.setListAdapter(mAdapter);

        System.out.println("Show List\n");
        db.close();
    }

    public static ArrayList<String> getData()
     {


        ArrayList<String> items = DBAdapter.getAllTitles();
        System.out.println("Return a LIST titles\n");
         return items;
        }


    }

DBAdapter.java

package one.two;

import java.util.List;

import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

import java.util.ArrayList;

public class DBAdapter
{
    public static String status = "status";
    public String id = "id";
    public String arrival = "arrival";
    public String destination = "destination";
    public String ferry = "ferry";
    private static String DB_PATH = "/data/data/one.two/databases/";
    private static final String DATABASE_NAME = "ferry.db";
    private static final String DATABASE_TABLE = "port";
    public static Context context;
    public Cursor c;

    public static SQLiteDatabase DbLib;

        //overloaded non-null constructor
    public DBAdapter(Context context) 
    {
        DbLib = context.openOrCreateDatabase(DATABASE_NAME,  SQLiteDatabase.CREATE_IF_NECESSARY,null);
        System.out.println("OpenOrCreateDB Done");
    }

    public class DatabaseHelper extends SQLiteOpenHelper
    {
        Context context;
        DatabaseHelper(Context context)
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            this.context = context;

        }//end constructor DatabaseHelper

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion,
                int newVersion)
        {
        }//end onUpgrade()

        @Override
        public void onCreate(SQLiteDatabase db)
        {
        }//end onCreate()
    }// end class DatabaseHelper

    private static DatabaseHelper DBHelper;
    //private static SQLiteDatabase DbLib;

    private static final int DATABASE_VERSION = 1;

    //// context brought up /////////////
    //private final Context context;


        /*public void DBAdapter() throws SQLException
        {
            String myPath = DB_PATH + DATABASE_NAME;
            db = SQLiteDatabase.openDatabase(myPath, null,
                    SQLiteDatabase.OPEN_READONLY);
        }//end DBAdapter()*/



        public static ArrayList<String> getAllTitles()
        {

            ArrayList<String> port = new ArrayList<String>();
                Cursor c=null;


                c = DbLib.query("port",
                        new String[] { "status", "id", "arrival",
                                "destination", "ferry" }, null, null,
                        null, null, null);
                try {
                    if (c!=null) { // start - when there is at least 1 record
                        System.out.println("Cursor is NOT NULL");

                        int i =0;
                        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) 

                        {
                                    // Debug Stm
                            System.out.println("Record No. "+i);
                            System.out.println(c.getString(0));
                            System.out.println(c.getString(1));
                            System.out.println(c.getString(2));
                            System.out.println(c.getString(3));
                            System.out.println(c.getString(4));
                            // Assign database cursor.records to arraylist
                            port.add(i,c.getString(0));
                            port.add(i,c.getString(1));
                            port.add(i,c.getString(2));
                            port.add(i,c.getString(3));
                            port.add(i,c.getString(4));
                            i = i + 1;

                        }
                    } // end - where there is at least 1 record


                } finally {
                    if (c!=null) {
                    c.close();
                }

                }   
            return port;
        }//end getAllTitles()

        public void open() {
            //Open the database
            String myPath = DB_PATH + DATABASE_NAME;
            DbLib = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

        }
        public Cursor getCursor(){
            return c;

        }

        public void close()
        {
            DbLib.close();

        }

    }//end class DBAdapter

main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/widget32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ferry Hub"
android:textSize="25sp"
android:textStyle="bold"
android:textColor="#ff009999"
android:layout_x="97px"
android:layout_y="15px"
>
</TextView>
<TextView
android:id="@+id/widget35"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Arrival Time"
android:layout_x="116px"
android:layout_y="48px"
>
</TextView>
<TextView
android:id="@+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_x="200px"
android:layout_y="90px"
>
</TextView>
<Button
android:id="@+id/widget36"
android:layout_width="96px"
android:layout_height="40px"
android:text="Back"
android:layout_x="101px"
android:layout_y="299px"
>
</Button>

<ListView 
    android:layout_width="wrap_content"
    android:layout_y="132dip"
    android:layout_x="150dip"
    android:id="@android:id/list"
    android:layout_height="wrap_content">
</ListView>
</AbsoluteLayout>

Error from logcat:

07-23 07:00:45.625: ERROR/AndroidRuntime(725): Uncaught handler: thread main exiting due to uncaught exception
07-23 07:00:45.654: ERROR/AndroidRuntime(725): java.lang.RuntimeException: Unable to start activity ComponentInfo{one.two/one.two.Departure}: java.lang.ClassCastException: java.util.ArrayList
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at android.os.Looper.loop(Looper.java:123)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at android.app.ActivityThread.main(ActivityThread.java:3948)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at java.lang.reflect.Method.invokeNative(Native Method)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at java.lang.reflect.Method.invoke(Method.java:521)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at dalvik.system.NativeStart.main(Native Method)
07-23 07:00:45.654: ERROR/AndroidRuntime(725): Caused by: java.lang.ClassCastException: java.util.ArrayList
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at one.two.Departure.onCreate(Departure.java:27)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
07-23 07:00:45.654: ERROR/AndroidRuntime(725):     ... 11 more

May i know why isn’t there any data being shown on my ListView?

  • 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-15T23:45:12+00:00Added an answer on May 15, 2026 at 11:45 pm

    There are two errors in your code that I can spot at the moment. The first one should not be a problem. You are creating two ListAdapters and Setting them both.

    setListAdapter(new SimpleCursorAdapter(this, android.R.id.list, c, from, to));
    
    
    SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, android.R.id.list, c, from, to);
    this.setListAdapter(mAdapter);
    

    The next thing is the way you define your SimpleCursorAdapter:

    new SimpleCursorAdapter(this, android.R.id.list, c, from, to)
    

    As seen in the Documentatio the SimpleCursorAdapter expects a id for a layout that will be used as a cell in the List. You are supplying the id of the list itself. The Adapter will now look for a layout file in your project that has the same id as the android list and then try to inflate this layout and find the views that are mentioned in the to array and set the values of the cursor to this values. That can not work. There should be an error visible in Logcat at least.

    Also the to id that you are supplying should not be in your main layout but in the row layout itself. If this isn’t showing an Error are you sure that there is data in your Cursor at all?

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

Sidebar

Related Questions

here is my Arrival.java package one.two; import java.io.IOException; import java.util.ArrayList; import java.util.List; import android.app.ListActivity;
Here is my code for my db class: package one.two; import java.util.List; import android.app.ListActivity;
I have two questions is one here. On Windows, I am familiar with pipes
Here is my code...I have two dimensional matrices A,B. I want to develop the
This is a follow up question to the one answered here: Excluding dates from
Here's an example list: <ul> <li><a href=#>Link 1</a></li> <li><a href=#>Link 2</a></li> <li><a href=#>Link 3</a></li>
My project is to design an Android app that will be fitted in school
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works

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.