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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:52:54+00:00 2026-06-09T07:52:54+00:00

I have this code public class MainActivity extends Activity { private static final int

  • 0

I have this code

public class MainActivity extends Activity {
    private static final int CAMERA_REQUEST = 1888;
    public ImageView imageView;
    Imagehelper help = new Imagehelper(this);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.imageView = (ImageView) this.findViewById(R.id.imageView1);
        ListView lv = (ListView) findViewById(R.id.fotos);

        Cursor valores = help.getAll();
        startManagingCursor(valores);
        ItemAdapter itemAdapter = new ItemAdapter(this, valores);
        lv.setAdapter(itemAdapter);

        Button B = (Button) this.findViewById(R.id.camera);
        B.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent cameraIntent = new Intent(
                        android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(cameraIntent, CAMERA_REQUEST);
            }
        });
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CAMERA_REQUEST) {
            Bitmap photo = (Bitmap) data.getExtras().get("data");
            imageView.setImageBitmap(photo);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();
            help.insert(byteArray);
        }
    }
}

The adapter class

public class ItemAdapter extends CursorAdapter {

    private LayoutInflater mLayoutInflater;
    private Context mContext;

    public ItemAdapter(Context context, Cursor c) {
        super(context, c);
        mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public void bindView(View v, Context context, Cursor c) {
        Bitmap BM;
        c.moveToFirst();
        byte[] bytes = c.getBlob(c.getColumnIndex("imageblob"));
        BM = BitmapFactory.decodeByteArray(bytes, 0, 0);

        ImageView img = (ImageView) v.findViewById(R.id.imagenes);
        img.setImageBitmap(BM);

    }

    @Override
    public View newView(Context arg0, Cursor arg1, ViewGroup parent) {

        View v = mLayoutInflater.inflate(R.layout.imagen_row, parent, false);
        return v;
    }

}

And the Database

public class Imagehelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "abhi.db";
    private static final int SCHEMA_VERSION = 3;

    public Imagehelper(Context context) {
        super(context, DATABASE_NAME, null, SCHEMA_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("CREATE TABLE Image(_id INTEGER PRIMARY KEY AUTOINCREMENT,imageblob BLOB);");
    }

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

    public Cursor getAll() {
        return (getReadableDatabase().rawQuery("SELECT imageblob FROM Image",
                null));
    }

    public void insert(byte[] bytes) {
        ContentValues cv = new ContentValues();

        cv.put("imageblob", bytes);
        Log.e("inserted", "inserted");
        getWritableDatabase().insert("Image", "imageblob", cv);

    }

    public byte[] getImage(Cursor c) {
        return (c.getBlob(1));
    }
}

But when I run this code the application crashes. What I’m doing bad ???

The portion of the log cat trace is,

08-08 17:32:55.779: E/AndroidRuntime(746): FATAL EXCEPTION: main
08-08 17:32:55.779: E/AndroidRuntime(746): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pruebascamarasqlite/com.example.pruebascamarasqlite.MainActivity}: java.lang.IllegalArgumentException: column '_id' does not exist
08-08 17:32:55.779: E/AndroidRuntime(746):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-08 17:32:55.779: E/AndroidRuntime(746):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
  • 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-09T07:52:55+00:00Added an answer on June 9, 2026 at 7:52 am

    You are using CursorAdapter. From the documentation:

    The Cursor must include a column named “_id” or this class will not
    work.

    You can either change your schema to include “_id” in your db or you can alias SQL’s built-in rowid as _id in your query:

    return (getReadableDatabase().rawQuery("SELECT rowid _id, imageblob FROM Image",
                    null));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code for my soundboard, public class soundboardActivity extends Activity { View
I have this code: public class Window extends JFrame { public Window(){ ... JButton
I have this code that describes a service: public class navigation_web extends Service {
Hello I have this code class Triplets { public: int nVal1; int nVal2; NodeT
I have class where I draw image. This is code: public class CanvasdrawActivity extends
I have following code that displays an Image with letters, public class MainActivity extends
I have this code: public class Area { Texture2D point; Rectangle rect; SpriteBatch _sB;
I have this class called SiteAsyncDownload.cs Here's the code: public class SiteAsyncDownloader { WebClient
I have this sample code for async operations (copied from the interwebs) public class
Best to describe this in code... I have this public class A<T> { public

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.