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

The Archive Base Latest Questions

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

Can someone please tell me how can I easily display every record from sqllite

  • 0

Can someone please tell me how can I easily display every record from sqllite in ListActivity tab? I’m kinda confused with this. Do I have to create db from my helper class in TabActivity or ListActivity or both? My db helper class is as follow:

package tabs.app;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBAdapter 
{

 private static String DB_PATH = "/data/data/tabs.app/databases/";

    public static final String KEY_ROWID = "_id";
    public static final String KEY_LATITUDE = "latitude";
    public static final String KEY_LONGITUDE = "longitude";
    private static final String TAG = "DBAdapter";

    private static final String DATABASE_NAME = "coords";
    private static final String DATABASE_TABLE = "coordsStorages";
    private static final int DATABASE_VERSION = 2;

   /* private static final String DATABASE_CREATE =
        "create table coordsStorage (_id integer primary key autoincrement, latitude integer not null, longitude integer not null)";
     */   
    public Context context; 

    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;

    public DBAdapter(Context ctx) 
    {
        this.context = ctx;
        DBHelper = new DatabaseHelper(context);
    }

    private static class DatabaseHelper extends SQLiteOpenHelper 
    {
        DatabaseHelper(Context context) 
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) 
        {
            db.execSQL("create table coordsStorages (_id integer primary key autoincrement, latitude integer not null, longitude integer not null)");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, 
        int newVersion) 
        {
            Log.w(TAG, "Upgrading database from version " + oldVersion 
                    + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS titles");
            onCreate(db);
        }
    }    

    //---opens the database---
    public DBAdapter open() throws SQLException 
    {
        db = DBHelper.getWritableDatabase();
        return this;
    }

    //---closes the database---    
    public void close() 
    {
        DBHelper.close();
    }

    //---insert a title into the database---
    public long insertCoords(int latitude, int longitude) 
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_LATITUDE, latitude);
        initialValues.put(KEY_LONGITUDE, longitude);
        return db.insert(DATABASE_TABLE, null, initialValues);
    }

    public void openDataBase() throws SQLException{

        //Open the database
        String myPath = DB_PATH + DATABASE_NAME;
        db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

    }


    //---deletes a particular title---
    public boolean deleteTitle(long rowId) 
    {
        return db.delete(DATABASE_TABLE, KEY_ROWID + 
          "=" + rowId, null) > 0;
    }

    //---retrieves all the titles---
    public Cursor getAllTitles() 
    {
        return db.query(DATABASE_TABLE, new String[] {
          KEY_ROWID, 
          KEY_LATITUDE,
          KEY_LONGITUDE}, 
                null, 
                null, 
                null, 
                null, 
                null);
    }

    //---retrieves a particular title---
    public Cursor getTitle(long rowId) throws SQLException 
    {
        Cursor mCursor =
                db.query(true, DATABASE_TABLE, new String[] {
                  KEY_ROWID,
                  KEY_LATITUDE, 
                  KEY_LONGITUDE}, 
                  KEY_ROWID + "=" + rowId, 
                  null,
                  null, 
                  null, 
                  null, 
                  null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }

    //---updates a title---
    /*public boolean updateTitle(long rowId, int latitude, 
    int longitude) 
    {
        ContentValues args = new ContentValues();
        args.put(KEY_LATITUDE, latitude);
        args.put(KEY_LONGITUDE, longitude);
        return db.update(DATABASE_TABLE, args, 
                         KEY_ROWID + "=" + rowId, null) > 0;
    }*/
}

And Im trying to retrieve the records in TabActivity like this:

public class Areas extends ListActivity {

 DBAdapter db;
 SimpleCursorAdapter mAdapter;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.areas_layout);

          db = new DBAdapter(this);
          db.open();
          Cursor c = db.getAllTitles();
          startManagingCursor(c);

          String[] display = new String[] { db.KEY_LATITUDE };      
          int[] to = new int[] { R.id.row_latitude};
        /*
          String[] display2 = new String[] { db.KEY_LONGITUDE };      
          int[] to2 = new int[] { R.id.row_longitude};*/

          mAdapter = new SimpleCursorAdapter(this, R.layout.areas_layout, c, display, to);
          setListAdapter(mAdapter);

       /*   mAdapter2 = new SimpleCursorAdapter(this, R.layout.areas_layout, c, display2, to2);
          setListAdapter(mAdapter2);*/

          db.close();



 }
/*
 private void fillData() {

     // Get all of the rows from the database and create the item list
     Cursor c = db.getAllTitles();
     startManagingCursor(c);


 }*/

}

Whenever I’m trying to do that the error log outputs this:

06-07 09:51:56.529:
ERROR/AndroidRuntime(2034): Uncaught
handler: thread main exiting due to
uncaught exception

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):
java.lang.RuntimeException: Unable to
start activity
ComponentInfo{tabs.app/tabs.app.Areas}:
java.lang.RuntimeException: Your
content must have a ListView whose id
attribute is 'android.R.id.list'

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.app.ActivityThread.startActivityNow(ActivityThread.java:2242)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:631)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.widget.TabHost.setCurrentTab(TabHost.java:317)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:127)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:346)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.View.performClick(View.java:2344)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.View.onTouchEvent(View.java:4133)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.View.dispatchTouchEvent(View.java:3672)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:850)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(    oneWindow.java:1712)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.app.Activity.dispatchTouchEvent(Activity.java:1987)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(    oneWindow.java:1696)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.view.ViewRoot.handleMessage(ViewRoot.java:1658)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.os.Handler.dispatchMessage(Handler.java:99)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.os.Looper.loop(Looper.java:123)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.app.ActivityThread.main(ActivityThread.java:4203)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
java.lang.reflect.Method.invokeNative(Native
Method)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
java.lang.reflect.Method.invoke(Method.java:521)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
dalvik.system.NativeStart.main(Native
Method)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034): Caused by:
java.lang.RuntimeException: Your
content must have a ListView whose id
attribute is 'android.R.id.list'

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.app.ListActivity.onContentChanged(ListActivity.java:236)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.app.Activity.setContentView(Activity.java:1620)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
tabs.app.Areas.onCreate(Areas.java:18)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)

06-07 09:51:56.559:
ERROR/AndroidRuntime(2034):     ... 30
more

06-07 09:51:56.619: INFO/Process(51):
Sending signal. PID: 2034 SIG: 3

06-07 09:51:56.619:
INFO/dalvikvm(2034): threadid=7:
reacting to signal 3

06-07 09:51:56.619:
ERROR/dalvikvm(2034): Unable to open
stack trace file
'/data/anr/traces.txt': Permission
denied

Can someone please tell me what I’m doing wrong? Help greatly appreciated!

  • 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-15T08:54:11+00:00Added an answer on May 15, 2026 at 8:54 am
    java.lang.RuntimeException: Your
    content must have a ListView whose id
    attribute is 'android.R.id.list'
    

    This error is complaining that the ListView in your view file (R.layout.areas_layout) has not been given the correct id. Your ListView XML must look like this:

    <ListView
      android:id="@android:id/list"…
    

    Try doing that and see if it solves your problem:

    ****************Edit**************************************

    Thanks for sharing your layout code, the problem seems to be that you have your list row xml layout in the same layout file as your main content view. You need to keep them seperate.

    In your R.layout.areas_layout file just have your linearlayout and your listview then have a seperate xml file for your row which would look something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      >
      <TextView 
        android:id="@+id/row_latitude" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        />
    </LinearLayout>
    

    You would then pass the list row to your SimpleCursorAdapter:

    mAdapter = new SimpleCursorAdapter(this, R.layout.my_list_row, c, display, to);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please tell me where these extra characters are coming from? This is
Can someone please tell me what this means: 07-04 09:54:38.048: I/DetailActivity(15496): Title that is
Can someone please tell me what's wrong with this sp. The logic seems to
Can someone please tell me why this doesn't work? I'm trying to show and
Can someone please tell me how to show all privileges/rules from a specific user
Can someone please tell me whats wrong with this code. I'm not getting complete
Can someone please tell me how I can hide this button after pressing it
can someone please tell me how i can backup emails from cpanel without having
Can someone please tell me why this won't work? NSAppleScript* playPause = [[NSAppleScript alloc]
Can someone please tell me how to invoke a method from the codeigniter controller

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.