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

  • Home
  • SEARCH
  • 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 8503773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:50:54+00:00 2026-06-11T01:50:54+00:00

I have written the code to insert the data into SQLite database at that

  • 0

I have written the code to insert the data into SQLite database at that time I am getting nullpointer exception at the line return db.insert("userdetails", null, initialValues);

public class DBUserAdapter {

            private static final String DATABASE_NAME = "users"; 
            private static final int DATABASE_VERSION = 1; 

            private static final String USERDETAILS=
                    "create table userdetails(usersno integer primary key autoincrement,photo BLOB,date text not null);";

            private Context context = null; 
            private DatabaseHelper DBHelper; 
            private SQLiteDatabase db; 


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


            public DBUserAdapter(SampleViewBase sampleViewBase) {

                 DBHelper = new DatabaseHelper(context);
            }


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

                public void onCreate(SQLiteDatabase db) {
                     db.execSQL(USERDETAILS);

                }

                public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                    // TODO Auto-generated method stub
                      db.execSQL("DROP TABLE IF EXISTS users"); 
                        onCreate(db); 
                } 

        }
             public void open() throws SQLException 
                { 
                    db = DBHelper.getWritableDatabase(); 
                } 

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

                public long insert(byte[] photo, String date) 
                { 
                     ContentValues initialValues = new ContentValues(); 
                     initialValues.put("photo", photo); 
                     initialValues.put("date", date); 
                    // initialValues.put(KEY_TIME, time); 
                     Log.d("inotvaluessssssssss",initialValues.toString());
                     return db.insert("userdetails", null, initialValues);

                } 

My main Activity

public abstract class SampleViewBase extends SurfaceView implements SurfaceHolder.Callback, Runnable {
    private static final String TAG = "Sample-ImageManipulations::SurfaceView";
    DBUserAdapter dbUser= null ;


    private SurfaceHolder       mHolder;
    private VideoCapture        mCamera;
    byte[] photo;
    //  Mat mRgba;
    Mat mRgba = new Mat(); 
    Mat mRgba1= new Mat(); 
    // private FpsMeter            mFps;
    int[] intArray = new int[50];
//  int[] y;
//  int check=0;
    int cod=0;


    public SampleViewBase(Context context) {
        super(context);
        mHolder = getHolder();
        mHolder.addCallback(this);
        // mFps = new FpsMeter();
        Log.i(TAG, "Instantiated new " + this.getClass());
                                          }

    public boolean openCamera() {
        Log.i(TAG, "openCamera");
        synchronized (this) {
            releaseCamera();
            mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID);
            if (!mCamera.isOpened()) {
                mCamera.release();
                mCamera = null;
                Log.e(TAG, "Failed to open native camera");
                return false;
            }
        }
        return true;
    }

    public void releaseCamera() {
        Log.i(TAG, "releaseCamera");
        synchronized (this) {
            if (mCamera != null) {
                mCamera.release();
                mCamera = null;
            }
        }
    }

    public void setupCamera(int width, int height) {
        Log.i(TAG, "setupCamera("+width+", "+height+")");
        synchronized (this) {
            if (mCamera != null && mCamera.isOpened()) {
                List<Size> sizes = mCamera.getSupportedPreviewSizes();
                int mFrameWidth = width;
                int mFrameHeight = height;

                // selecting optimal camera preview size
                {
                    double minDiff = Double.MAX_VALUE;
                    for (Size size : sizes) {
                        if (Math.abs(size.height - height) < minDiff) {
                            mFrameWidth = (int) size.width;
                            mFrameHeight = (int) size.height;
                            minDiff = Math.abs(size.height - height);
                        }
                    }
                }

                mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
                mCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
            }
        }

    }

    public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
        Log.i(TAG, "surfaceChanged");
        setupCamera(width, height);
    }

    public void surfaceCreated(SurfaceHolder holder) {
        Log.i(TAG, "surfaceCreated");
        (new Thread(this)).start();
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        Log.i(TAG, "surfaceDestroyed");
        releaseCamera();
    }

    protected abstract Bitmap processFrame(VideoCapture capture);

    public void run() {
        Log.i(TAG, "Starting processing thread");
        //mFps.init();

        while (true) {
            Bitmap bmp = null;

            synchronized (this) {
                if (mCamera == null) {
                    Log.i(TAG, "mCamera == null");
                    break;
                }

                if (!mCamera.grab()) {
                    Log.e(TAG, "mCamera.grab() failed");
                    break;
                                   }
                 bmp = processFrame(mCamera);
                 String i1=bmp.toString();
                 dbUser = new DBUserAdapter(SampleViewBase.this);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String dateTime = sdf.format(Calendar.getInstance().getTime()); // reading local time in the system


                //    mRgba= (Mat)processFrame(mCamera);



                ByteArrayOutputStream blob = new ByteArrayOutputStream();
                bmp.compress(CompressFormat.PNG, 100 /*ignored for PNG*/, blob);
                photo = blob.toByteArray();
                dbUser.insert(photo, dateTime);
                Log.d("bitmapdataaaaaaaaaaaaaaaaaaaaaaa",""+photo);
                Bitmap bmp32 = bmp.copy(Bitmap.Config.ARGB_8888, true);

                Utils.bitmapToMat(bmp32,mRgba); 
                Utils.bitmapToMat(bmp32,mRgba1); 
        //      Log.d("lengthhhhhhhhhhhh",""+bitmapdata.length);
                //              for(int k=0;k<bitmapdata.length;k++)
                //              {
                //                  
                //              }
                bmp = processFrame(mCamera);
                int i= bmp.getWidth();
                int j=bmp.getHeight();
                Log.d("Coming outoutttttttttttt ","Coming outputtttttttt");
                intArray=FindFeatures(mRgba1.getNativeObjAddr(),mRgba.getNativeObjAddr());
                Log.d("valueeeeeeeeee",""+intArray[0]);
                Log.d("valueeeeeeeeee",""+intArray[1]);
                Log.d("valueeeeeeeeee",""+intArray[2]);
                Log.d("valueeeeeeeeee",""+intArray[3]);
                Log.d("valueeeeeeeeee",""+intArray[3]);
            //  Log.d("Coming outo-----------------------==========","hjhjhj");
                //    mRgba=(Mat)bitmapdata;
                //  mFps.measure();
            //   Utils.matToBitmap(mRgba, bmp);

            }

            if (bmp != null)
            {
                Canvas canvas = mHolder.lockCanvas();
                if (canvas != null) 
                {
                    //Log.d("Coming outo---454545--------------------==========","hjhjhj");
                    canvas.drawBitmap(bmp, (canvas.getWidth() - bmp.getWidth()) / 2, (canvas.getHeight() - bmp.getHeight()), null);
                    // mFps.draw(canvas, (canvas.getWidth() - bmp.getWidth()) / 2, 0);

                    mHolder.unlockCanvasAndPost(canvas);
                }
                bmp.recycle();
                }

            //FindFeatures(bitmapdata,j,i);
        }

        Log.i(TAG, "Finishing processing thread");
    }
    //   public native void FindFeatures(final byte[] bitmapdata,long m,int height,int width);
    public native int[] FindFeatures(long n,long m);
    static {
    //  Log.d("Coming hereeeeeee","Coming hereeeeeeeeeeeeee");
        System.loadLibrary("mixed_sample");

    }

    public class Demo
    {
        int[] x;
        int[] y;
        int check=0;
        int cod=0;
    }
}
  • 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-11T01:50:56+00:00Added an answer on June 11, 2026 at 1:50 am

    In your mainactivity, do this modification doing dbUser.open() before calling insert and doing dbUser.close() after insert is done.

    This is the modification:

                    dbUser = new DBUserAdapter(SampleViewBase.this);
                    dbUser.open(); // <<<<<<<<<<<<<<<<<< look at this modification too
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String dateTime = sdf.format(Calendar.getInstance().getTime()); // reading local time in the system
    
    
                    //    mRgba= (Mat)processFrame(mCamera);
    
    
    
                    ByteArrayOutputStream blob = new ByteArrayOutputStream();
                    bmp.compress(CompressFormat.PNG, 100 /*ignored for PNG*/, blob);
                    photo = blob.toByteArray();
                    dbUser.insert(photo, dateTime);
                    dbUser.close(); // <<<<<<<<<<<<<<<<<< look at this modification too
                    Log.d("bitmapdataaaaaaaaaaaaaaaaaaaaaaa",""+photo);
                    Bitmap bmp32 = bmp.copy(Bitmap.Config.ARGB_8888, true);
    

    This is the MainActivity code with modifications:

        public abstract class SampleViewBase extends SurfaceView implements SurfaceHolder.Callback, Runnable {
        private static final String TAG = "Sample-ImageManipulations::SurfaceView";
        DBUserAdapter dbUser= null ;
    
    
        private SurfaceHolder       mHolder;
        private VideoCapture        mCamera;
        private Context mContext;
        byte[] photo;
        //  Mat mRgba;
        Mat mRgba = new Mat(); 
        Mat mRgba1= new Mat(); 
        // private FpsMeter            mFps;
        int[] intArray = new int[50];
    //  int[] y;
    //  int check=0;
        int cod=0;
    
    
        public SampleViewBase(Context context) {
            super(context);
            this.mContext = context;
            mHolder = getHolder();
            mHolder.addCallback(this);
            // mFps = new FpsMeter();
            Log.i(TAG, "Instantiated new " + this.getClass());
                                              }
    
        public boolean openCamera() {
            Log.i(TAG, "openCamera");
            synchronized (this) {
                releaseCamera();
                mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID);
                if (!mCamera.isOpened()) {
                    mCamera.release();
                    mCamera = null;
                    Log.e(TAG, "Failed to open native camera");
                    return false;
                }
            }
            return true;
        }
    
        public void releaseCamera() {
            Log.i(TAG, "releaseCamera");
            synchronized (this) {
                if (mCamera != null) {
                    mCamera.release();
                    mCamera = null;
                }
            }
        }
    
        public void setupCamera(int width, int height) {
            Log.i(TAG, "setupCamera("+width+", "+height+")");
            synchronized (this) {
                if (mCamera != null && mCamera.isOpened()) {
                    List<Size> sizes = mCamera.getSupportedPreviewSizes();
                    int mFrameWidth = width;
                    int mFrameHeight = height;
    
                    // selecting optimal camera preview size
                    {
                        double minDiff = Double.MAX_VALUE;
                        for (Size size : sizes) {
                            if (Math.abs(size.height - height) < minDiff) {
                                mFrameWidth = (int) size.width;
                                mFrameHeight = (int) size.height;
                                minDiff = Math.abs(size.height - height);
                            }
                        }
                    }
    
                    mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
                    mCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
                }
            }
    
        }
    
        public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
            Log.i(TAG, "surfaceChanged");
            setupCamera(width, height);
        }
    
        public void surfaceCreated(SurfaceHolder holder) {
            Log.i(TAG, "surfaceCreated");
            (new Thread(this)).start();
        }
    
        public void surfaceDestroyed(SurfaceHolder holder) {
            Log.i(TAG, "surfaceDestroyed");
            releaseCamera();
        }
    
        protected abstract Bitmap processFrame(VideoCapture capture);
    
        public void run() {
            Log.i(TAG, "Starting processing thread");
            //mFps.init();
    
            while (true) {
                Bitmap bmp = null;
    
                synchronized (this) {
                    if (mCamera == null) {
                        Log.i(TAG, "mCamera == null");
                        break;
                    }
    
                    if (!mCamera.grab()) {
                        Log.e(TAG, "mCamera.grab() failed");
                        break;
                                       }
                     bmp = processFrame(mCamera);
                     String i1=bmp.toString();
                     dbUser = new DBUserAdapter(mContext);
                     dbUser.open(); // <<<<<<<<<<<<<<<<<< look at this modification too
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String dateTime = sdf.format(Calendar.getInstance().getTime()); // reading local time in the system
    
    
                    //    mRgba= (Mat)processFrame(mCamera);
    
    
    
                    ByteArrayOutputStream blob = new ByteArrayOutputStream();
                    bmp.compress(CompressFormat.PNG, 100 /*ignored for PNG*/, blob);
                    photo = blob.toByteArray();
                    dbUser.insert(photo, dateTime);
                    dbUser.close(); // <<<<<<<<<<<<<<<<<< look at this modification too
                    Log.d("bitmapdataaaaaaaaaaaaaaaaaaaaaaa",""+photo);
                    Bitmap bmp32 = bmp.copy(Bitmap.Config.ARGB_8888, true);
    
                    Utils.bitmapToMat(bmp32,mRgba); 
                    Utils.bitmapToMat(bmp32,mRgba1); 
            //      Log.d("lengthhhhhhhhhhhh",""+bitmapdata.length);
                    //              for(int k=0;k<bitmapdata.length;k++)
                    //              {
                    //                  
                    //              }
                    bmp = processFrame(mCamera);
                    int i= bmp.getWidth();
                    int j=bmp.getHeight();
                    Log.d("Coming outoutttttttttttt ","Coming outputtttttttt");
                    intArray=FindFeatures(mRgba1.getNativeObjAddr(),mRgba.getNativeObjAddr());
                    Log.d("valueeeeeeeeee",""+intArray[0]);
                    Log.d("valueeeeeeeeee",""+intArray[1]);
                    Log.d("valueeeeeeeeee",""+intArray[2]);
                    Log.d("valueeeeeeeeee",""+intArray[3]);
                    Log.d("valueeeeeeeeee",""+intArray[3]);
                //  Log.d("Coming outo-----------------------==========","hjhjhj");
                    //    mRgba=(Mat)bitmapdata;
                    //  mFps.measure();
                //   Utils.matToBitmap(mRgba, bmp);
    
                }
    
                if (bmp != null)
                {
                    Canvas canvas = mHolder.lockCanvas();
                    if (canvas != null) 
                    {
                        //Log.d("Coming outo---454545--------------------==========","hjhjhj");
                        canvas.drawBitmap(bmp, (canvas.getWidth() - bmp.getWidth()) / 2, (canvas.getHeight() - bmp.getHeight()), null);
                        // mFps.draw(canvas, (canvas.getWidth() - bmp.getWidth()) / 2, 0);
    
                        mHolder.unlockCanvasAndPost(canvas);
                    }
                    bmp.recycle();
                    }
    
                //FindFeatures(bitmapdata,j,i);
            }
    
            Log.i(TAG, "Finishing processing thread");
        }
        //   public native void FindFeatures(final byte[] bitmapdata,long m,int height,int width);
        public native int[] FindFeatures(long n,long m);
        static {
        //  Log.d("Coming hereeeeeee","Coming hereeeeeeeeeeeeee");
            System.loadLibrary("mixed_sample");
    
        }
    
        public class Demo
        {
            int[] x;
            int[] y;
            int check=0;
            int cod=0;
        }
    }
    

    Modify DBUserAdapter constructor:

     public DBUserAdapter(Context context) {
                this.context = ctx; 
                DBHelper = new DatabaseHelper(context); 
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a code to insert the data to SQL LITE database as
I have written a database app that imports data from an excel file into
I have written code that opens 16 figures at once. Currently, they all open
I have written code to perform a function that could take a while to
I have written some code that loads an XML document using an XmlDocument object
I have written a code for taking JSON data from a PHP and putting
I have written a application that parses the html code of some web pages.
I am relatively new to Perl.I have been trying to insert data to database
I have written a code for store the current date & time value. It
I've recently written a custom API for inserting data into my database from multiple

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.