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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:39:24+00:00 2026-06-16T10:39:24+00:00

I have been trying to populate my list view in a different manner. My

  • 0

I have been trying to populate my list view in a different manner. My database class already has a function defined which returns a cursor.
I would like to know whether my way is possible or not? As of now when I try to get to the ListView, my app crashes.
Here is the code:

public class ProjectExplorer extends ListActivity {

private projectdatabase database;
protected Cursor cursor;
protected ListAdapter adapter;

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

    openDatabase();
}

private void openDatabase() {

    database.open();
    cursor = database.getDataforDisplay();
    adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor, null, null, 0);
    setListAdapter(adapter);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_project_explorer, menu);
    return true;
}     }

Code for the method which returns the cursor:

public Cursor getDataforDisplay () {        

    String[] columns = new String[] {KEY_ROWID, PROJECT_NAME, PROJECT_FINISH_DATE, PROJECT_DIFFICULTY, PROJECT_STATUS};
    Cursor c = projectDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);


    return c;

}

As requested, complete database class code:

public class projectdatabase {

public static final String KEY_ROWID = "_id";
public static final String PROJECT_NAME = "project_name";
public static final String PROJECT_ID = "project_id";
public static final String PROJECT_DIFFICULTY = "project_difficulty";
public static final String PROJECT_STATUS = "project_status";
public static final String PROJECT_START_DATE = "project_start_date";
public static final String PROJECT_FINISH_DATE = "project_finsish_date";

private static final String DATABASE_NAME = "project_db";
static final String DATABASE_TABLE = "project_details";
private static final int DATABASE_VERSION = 1;

private DbHelper ourHelper;
private final Context projectdbContext;
private SQLiteDatabase projectDatabase;

private static class DbHelper extends SQLiteOpenHelper {
    public DbHelper(Context context) {

        super(context, DATABASE_NAME, null, DATABASE_VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub

        db.execSQL("CREATE TABLE "+ DATABASE_TABLE + " (" +
                KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                PROJECT_NAME + " TEXT NOT NULL, " +
                PROJECT_ID + " INTEGER, " +
                PROJECT_START_DATE + " TEXT, " +
                PROJECT_FINISH_DATE + " TEXT, " +
                PROJECT_DIFFICULTY + " TEXT, " +
                PROJECT_STATUS + " TEXT);"
               ); 

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

        db.execSQL("DROP TABLE IF EXIST " + DATABASE_NAME);
        onCreate(db);

    }
}

public projectdatabase (Context c) {                            
     projectdbContext = c;
}

public projectdatabase open() {                                                 //Open database
    ourHelper = new DbHelper(projectdbContext);
    projectDatabase = ourHelper.getWritableDatabase();
    return this;
}

public void close() {                                                           //Close database
    ourHelper.close();
}

public long createEntry(String name, String pid, String startdate, String finishdate, String difficulty) {          //Enter project data into database

    ContentValues cv = new ContentValues();
    cv.put(PROJECT_NAME, name);
    cv.put(PROJECT_ID, pid);
    cv.put(PROJECT_START_DATE, startdate);
    cv.put(PROJECT_FINISH_DATE, finishdate);
    cv.put(PROJECT_DIFFICULTY, difficulty);

    return projectDatabase.insert(DATABASE_TABLE, null, cv);
}

public String getData() {                                                       //Retrieve all project data

    String[] columns = new String[] {KEY_ROWID, PROJECT_NAME, PROJECT_ID, PROJECT_START_DATE, PROJECT_FINISH_DATE, PROJECT_DIFFICULTY, PROJECT_STATUS};
    Cursor c = projectDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
    String result = "";

    int iRow = c.getColumnIndex(KEY_ROWID);
    int iName = c.getColumnIndex(PROJECT_NAME);
    int iID = c.getColumnIndex(PROJECT_ID);
    int iStartDate = c.getColumnIndex(PROJECT_START_DATE);
    int iFinishDate = c.getColumnIndex(PROJECT_FINISH_DATE);
    int iDifficulty = c.getColumnIndex(PROJECT_DIFFICULTY);
    int iStatus = c.getColumnIndex(PROJECT_STATUS);

    for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {

        result = result + c.getString(iRow) + "|" + c.getString(iName) + "|" + c.getString(iID) + "|" + c.getString(iStartDate) + "|" + c.getString(iFinishDate) + "|" + c.getString(iDifficulty) + "|" + c.getString(iStatus) + "\n";

    }

    return result;
}

public Cursor getDataforDisplay () {        //Display selected data for 'User profile' *Incomplete*

    String[] columns = new String[] {KEY_ROWID, PROJECT_NAME, PROJECT_FINISH_DATE, PROJECT_DIFFICULTY, PROJECT_STATUS};
    Cursor c = projectDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);

    c.moveToFirst();
    return c;

}

}

Logcat:

This error comes up when I run the project in the AVD:

12-29 00:35:14.333: E/dalvikvm(4804): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

Then when I open the activity which is supposed to show the ListView but the app crashes:

12-29 00:38:04.245: E/AndroidRuntime(4804): FATAL EXCEPTION: main
12-29 00:38:04.245: E/AndroidRuntime(4804): java.lang.RuntimeException: Unable to start      
activity ComponentInfo{com.kk.project/com.kk.project.ProjectExplorer}:     
java.lang.IllegalArgumentException: column 'name' does not exist
12-29 00:38:04.245: E/AndroidRuntime(4804):     at     
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
android.app.ActivityThread.access$600(ActivityThread.java:123)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at 
android.os.Handler.dispatchMessage(Handler.java:99)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at 
android.os.Looper.loop(Looper.java:137)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at   
android.app.ActivityThread.main(ActivityThread.java:4424)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
java.lang.reflect.Method.invokeNative(Native Method)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
java.lang.reflect.Method.invoke(Method.java:511)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
dalvik.system.NativeStart.main(Native Method)
12-29 00:38:04.245: E/AndroidRuntime(4804): Caused by: 
java.lang.IllegalArgumentException: column 'name' does not exist
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:267)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at 
android.support.v4.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:317)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at 
android.support.v4.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:92)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at   
com.kk.project.ProjectExplorer.openDatabase(ProjectExplorer.java:29)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at   
com.kk.project.ProjectExplorer.onCreate(ProjectExplorer.java:21)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
android.app.Activity.performCreate(Activity.java:4465)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-29 00:38:04.245: E/AndroidRuntime(4804):     at  
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
12-29 00:38:04.245: E/AndroidRuntime(4804):     ... 11 more
  • 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-16T10:39:25+00:00Added an answer on June 16, 2026 at 10:39 am

    You need to initialize the database before trying to use it.

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_project_explorer);
        database=new projectdatabase(ProjectExplorer.this);
        openDatabase();
    } 
    

    EDIT :

    adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor, new String[] { "project_name" }, new int[] { android.R.id.text1 }, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying for almost a week now to create an SQLite database
I have been trying to generate report as per age differences of different months
I have been trying to create a ListView which I can sort using drag
I have been trying to serialize a list that contains arrays and lists. I
I'm building an asp.net MVC 2 app. I have a list view which lists
I have been trying to find out how to populate a dropdown box in
I am trying to populate the following dropdown list with information from MySQL database.
Have been trying to encrypt an xml file to a string so that I
Have have been trying to make a validator for my xml files. I have
I have been trying to setup git for our web development team unsuccessfully. Some

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.