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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:44:06+00:00 2026-05-20T14:44:06+00:00

EDIT: I believe i may have found the problem. I need to work on

  • 0

EDIT: I believe i may have found the problem. I need to work on my SmartDBHelper class. Will do this and post the results here.

EDIT: Found a link to someone who is having similar problem. Will be checking this to see if it fixes asap. Another Post

EDIT: Updated to reflect some changes made suggested by some of the posters. Problem is still occurring.

THE POST BELOW:

My application need to be able to write to the sqlite3 database that is on the android from 2 different events. One of my events is writing to the database just fine. When the second event tries to write to the database the attached error occurs. I have no clue why this is happening or how to fix it. I have tried numerous things the past couple hours and googled a ton. Can someone please view the code i have below and let me know what you think?

If you need any more information please let me know asap.

Thanks in advance!

//This is the sqliteopenhelper i created
public class SmartDBHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "smart_lite_db.db";
    private static final int DATABASE_VERSION = 2;
    private static final String NOTIFY_TABLE_NAME = "user_notify_data";
    private static final String HR_TABLE_NAME = "user_hr_data";
    private static final String NOTIFY_TABLE_CREATE = 
        "CREATE TABLE " + NOTIFY_TABLE_NAME + 
        " (counter INTEGER PRIMARY KEY, " + 
        "userresponse INTEGER, " + 
        "notifytime INTEGER);";
    private static final String DATA_TABLE_CREATE = 
        "CREATE TABLE " + HR_TABLE_NAME +
        " (counter INTEGER PRIMARY KEY, " +
        "hr INTEGER, " +
        "act INTEGER, " +
        "timestamp INTEGER);";      

    public SmartDBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        Log.v("smartdbhelper", "before creation");
        db.execSQL(NOTIFY_TABLE_CREATE);
        Log.v("smartdbhelper", "middle creation");
        db.execSQL(DATA_TABLE_CREATE);
        Log.v("smartdbhelper", "after creation");
    }

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

    }

}  

//This is the part that is working CORRECTLY
public class DataNotificationSurvey extends Activity {
    private SmartDBHelper dBHelper;
    private Date timeStamp;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.datanotificationlayout);
        Log.v("datanotificationsurvey", "inside datanotificationsurvey");

            dBHelper = new SmartDBHelper(this);
        timeStamp = new Date(DataNotification.when);
        // XML code stuff left out here, was not needed


    }

    public void submitNotify(int tempType, Date tempDate) {
        SQLiteDatabase dBH = dBHelper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("userresponse", tempType);
        values.put("notifytime", (tempDate.getTime()/1000));
        dBH.insert("user_notify_data", null, values);
        dBH.close();
    }
}  

// This is the event that is NOT working correctly
public class DataBuilder extends Activity {
    private List _listeners = new ArrayList();
    private SmartDataObject data;
    Context tThis;
    private SmartDBHelper dBHelper;
    private Date timeStampReference; //for keeping track of the first time

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v("databuilder", "on create");
    dBHelper = new SmartDBHelper(this);
}

    public void prepareData(SmartDataObject temp) {
        submitData(temp);
    }

    public void submitData(SmartDataObject temp) {
        data = temp;
        System.out.println("Where: DB-submitData");
        try {
        SQLiteDatabase dBH = dBHelper.getWritableDatabase(); // CODE FAILS AT THIS POINT
        Log.v("databuilder", "after writable");
        ContentValues values = new ContentValues();
        values.put("hr", data.getHeartRate());
        values.put("act", data.getAct());
        values.put("timestamp", data.getTimeStamp());
        dBH.insert("user_hr_data", null, values);
        Log.v("databuilder", "after insert");
        dBH.close();
        fireDataBuilderEvent(data);
        }
        catch(SQLException e) {
            e.printStackTrace();
        }
        catch(NullPointerException e) {
            e.printStackTrace();
        }
    }
    public synchronized void addDataBuilderListener(DataBuilderListener listener) {
        _listeners.add(listener);
    }
    public synchronized void removeDataBuilderListener(DataBuilderListener listener) {
        _listeners.remove(listener);
    }
    private synchronized void fireDataBuilderEvent(SmartDataObject temp) {
        DataBuilderEvent dRE = new DataBuilderEvent(this, temp);
        Iterator listeners = _listeners.iterator();
        while(listeners.hasNext()) {
            ((DataBuilderListener)listeners.next()).dataBuilderReceived(dRE);
        }
    }
    public interface DataBuilderListener {
        public void dataBuilderReceived(DataBuilderEvent event);
    }
}   

// The error that is occuring.
03-13 17:38:40.130: INFO/System.out(279): Where: DB-submitData
03-13 17:38:40.130: WARN/System.err(279): java.lang.NullPointerException
03-13 17:38:40.151: WARN/System.err(279):     at cpe495.smartapp.DataBuilder.submitData(DataBuilder.java:41)
03-13 17:38:40.151: WARN/System.err(279):     at cpe495.smartapp.DataBuilder.prepareData(DataBuilder.java:34)
03-13 17:38:40.171: WARN/System.err(279):     at cpe495.smartapp.SmartApp$2.dataAnalyzedReceived(SmartApp.java:56)
03-13 17:38:40.171: WARN/System.err(279):     at cpe495.smartapp.DataRobot.fireDataAnalyzedEvent(DataRobot.java:269)
03-13 17:38:40.181: WARN/System.err(279):     at cpe495.smartapp.DataRobot.analyzeData(DataRobot.java:79)
03-13 17:38:40.181: WARN/System.err(279):     at cpe495.smartapp.SmartApp$1.dataReceivedReceived(SmartApp.java:49)
03-13 17:38:40.191: WARN/System.err(279):     at cpe495.smartapp.ConnectDevice.fireDataReceivedEvent(ConnectDevice.java:79)
03-13 17:38:40.201: WARN/System.err(279):     at cpe495.smartapp.ConnectDevice.run(ConnectDevice.java:46)
03-13 17:38:40.211: WARN/System.err(279):     at java.lang.Thread.run(Thread.java:1096)
  • 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-20T14:44:07+00:00Added an answer on May 20, 2026 at 2:44 pm

    A quick guess: change private SmartDBHelper dBHelper = new SmartDBHelper(this); to just private SmartDBHelper dBHelper; and only initialize the new object in onCreate().

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

Sidebar

Related Questions

EDIT: Modified title and added update. UPDATE : We no longer believe this is
I'm having a real trouble to get accents right, and I believe this may
In this I need C++ array class template, which is fixed-size, stack-based and doesn't
Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
EDIT What small things which are too easy to overlook do I need to
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
EDIT Just to clarify, there is no intent of putting this into production. Purely
I need simple way to persist and edit a set of string pairs in

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.