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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:43:22+00:00 2026-06-04T05:43:22+00:00

This is my MySqlLiteHelper: public class MySQLiteHelper extends SQLiteOpenHelper { public static final String

  • 0

This is my MySqlLiteHelper:

public class MySQLiteHelper extends SQLiteOpenHelper {

    public static final String TABLE_CMBS = "cbs";
    public static final String CMB_ID = "_id";
    public static final String COLUMN_CMB = "cmb";
    public static final String COLUMN_INFO  = "cinfo";
    public static final String COLUMN_URL = "imageurl";


    private static final String DATABASE_NAME = "cmbsdr.db";
    private static final int DATABASE_VERSION = 1;

    // Database creation sql statement

    private static final String DATABASE_CREATE =
        "create table "+ TABLE_CMBS +" (_id integer primary key autoincrement, "
        + "cmb text, cbinfo text,"
        + "imageurl text);";


    public MySQLiteHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase database) {
        database.execSQL(DATABASE_CREATE);
    }

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

}

    This is my Comments class:



public class Comment {
    private long id;
    private String cmb;
    private String cinfo;
    private String imageurl;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getCmb() {
        return cmb;
    }

    public void setCmb(String cmb) {
        this.cmb = cmb;
    }
    public String getCInfo(){
            return cinfo;
    }
    public void setCInfo(String cinfo){
            this.cinfo = cinfo;
    }
    public void setImageUrl(String imageurl){
            this.imageurl = imageurl;
    }
    public String getImageUrl(){
            return imageurl;
    }



}

This is my CommentsDataSource class:

public class CommentsDataSource {

    // Database fields
    private SQLiteDatabase database;
    private MySQLiteHelper dbHelper;
    private String[] allColumns = { MySQLiteHelper.CMB_ID,
            MySQLiteHelper.COLUMN_CMB };

    public CommentsDataSource(Context context) {
        dbHelper = new MySQLiteHelper(context);
    }

    public void open() throws SQLException {
        database = dbHelper.getWritableDatabase();
    }

    public void close() {
        dbHelper.close();
    }

    public Comment createComment(String cmb, String cinfo, String imageurl) {
        ContentValues values = new ContentValues();
        values.put(MySQLiteHelper.COLUMN_CMB, cmb);
        values.put(MySQLiteHelper.COLUMN_INFO, cinfo);
        values.put(MySQLiteHelper.COLUMN_URL, imageurl);

        long insertId = database.insert(MySQLiteHelper.TABLE_CMBS, null,
                values);
        Cursor cursor = database.query(MySQLiteHelper.TABLE_CMBS,
                allColumns, MySQLiteHelper.CMB_ID + " = " + insertId, null,
                null, null, null);
        cursor.moveToFirst();
        Comment newComment = cursorToComment(cursor);
        cursor.close();
        return newComment;
    }

    public void deleteComment(Comment comment) {
        long id = comment.getId();
        System.out.println("Comment deleted with id: " + id);
        database.delete(MySQLiteHelper.TABLE_CMBS, MySQLiteHelper.CMB_ID
                + " = " + id, null);
    }

    public List<Comment> getAllComments() {
        List<Comment> comments = new ArrayList<Comment>();

        Cursor cursor = database.query(MySQLiteHelper.TABLE_CMB,
                allColumns, null, null, null, null,null);

        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            Comment comment = cursorToComment(cursor);
            comments.add(comment);

            cursor.moveToNext();
        }
        // Make sure to close the cursor
        cursor.close();
        return comments;
    }

    private Comment cursorToComment(Cursor cursor) {
        Comment comment = new Comment();
        comment.setId(cursor.getLong(0));
        comment.setCmb(cursor.getString(1));
        comment.setCInfo(cursor.getString(2));
        comment.setImageUrl(cursor.getString(3));
        return comment;
    }
}

I get the error:

05-16 15:07:25.273: E/AndroidRuntime(26017): Caused by: java.lang.IllegalStateException: get field slot from row 0 col 2 failed

when I do this:

dataSource = new CommentsDataSource(this);
        dataSource.open();

        List<Comment> cmbs = dataSource.getAllComments(); 
  • 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-04T05:43:24+00:00Added an answer on June 4, 2026 at 5:43 am

    You body projection string is wrong for your case. You are only querying

    private String[] allColumns = { MySQLiteHelper.CMB_ID,
    MySQLiteHelper.COLUMN_CMB };

    Add your other two column names in the allColumns string array.
    Namely MySQLiteHelper.COLUMN_INFO and MySQLiteHelper.COLUMN_URL

    Correct way:
    private String[] allColumns = { MySQLiteHelper.CMB_ID,
    MySQLiteHelper.COLUMN_CMB, MySQLiteHelper.COLUMN_INFO, MySQLiteHelper.COLUMN_URL };

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

Sidebar

Related Questions

This code won't compile because there is an illegal reference to a static field.
this is what i have so far: type u = {str : string} //some
This is my abstract class which must be derived each time I want to
This is a question that extends from the originally posted here: Link to loading-xaml
This doesn't seem to work (=null): @Resource(name = java:app/AppName) private String appName; But a
This is really just for my own use: I would like to be able
This somehow simple task is not so simple. I can get the number of
This has been a rather problematic issue on numerous occasions. We have alot of
This should be simple, but the answer is eluding me. If I've got a
this is my code that I write it but I want to use LINQ

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.