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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:06:40+00:00 2026-06-10T13:06:40+00:00

I am working on a project using a Database that stores specific information. The

  • 0

I am working on a project using a Database that stores specific information. The database works for part of the program, but yet for others it does not. When the user first starts the program they will see information this is pulled from the db, and they also have the option to add new information. The db works fine for both of these.

What I am having issues with is at another spot of adding information. When I go to open the db, my program crashes.
LOGCAT:

08-29 20:22:47.000: E/AndroidRuntime(3022): FATAL EXCEPTION: main
08-29 20:22:47.000: E/AndroidRuntime(3022): java.lang.NullPointerException
08-29 20:22:47.000: E/AndroidRuntime(3022):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
08-29 20:22:47.000: E/AndroidRuntime(3022):     at android.database.sqlite.SQLiteOpenHelper._getWritableDatabase(SQLiteOpenHelper.java:164)
08-29 20:22:47.000: E/AndroidRuntime(3022):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:100)
08-29 20:22:47.000: E/AndroidRuntime(3022):     at peices.DbM.open(DbM.java:173)
08-29 20:22:47.000: E/AndroidRuntime(3022):     at peices.NewStuff.CreateNewUnit(NewStuff.java:27)
08-29 20:22:47.000: E/AndroidRuntime(3022):     at carlson.msum.arch.Site$5.onClick(Site.java:231)
08-29 20:22:47.000: E/AndroidRuntime(3022):     at android.view.View.performClick(View.java:2538)

Code for NewStuff:27(Lines 20-30):

bb=Lon.getText().toString();
            cc=UnitName.getText().toString();
            Log.d("Class",aa);
            Log.d("Class",bb);
            Log.d("Class",cc);
            Log.d("Class",SiteName);
            Log.d("Stuff","Before Open");
            **db.open();**
            Log.d("Stuff","Before Insert/After Open");
            db.InsertUnit(SiteName, cc, aa, bb);
            Log.d("Stuff","Before Close/After Insert");
            db.close();

Code for DbM.java:173(170-176)

public DbM open() throws SQLException
{
    Log.d("BmDb","open");
    **db= DbMh.getWritableDatabase();**
    Log.d("BmDb","Open before return");
    return this;
}

I already know it has somthing to do with the opening of the db, but why would it open and work for other activities, but not this one? I checked out and all activities that would be before this one, and I did close all of the db’s.

this is the start of the class, the DbM initialization is how I do it for all the others.

public class NewStuff extends Activity {
Context context;
**DbM db=new DbM(this);**

One thing it could be, but not sure how to fix it is that this is a class of objects that I am using in other parts of the program. So I am not calling any oncreates or anything like that, would that be causing my issue?

*EDIT*

This is my entire NewStuff class, I must be missing somthing else other then just the context because nothing seems to work.

package peices;
import peices.DbM;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;
import android.app.Activity;
import android.content.Context;

public class NewStuff extends Activity {
Context context;
DbM db;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        db=new DbM(this);
        }
    public void CreateNewUnit(EditText Lat, EditText Lon, EditText UnitName, String SiteName)
    {

            db=new DbM(this);
            Log.d("NewUnit","Start of");
            String aa="";
            String bb="";
            String cc="";

            aa=Lat.getText().toString();
            bb=Lon.getText().toString();
            cc=UnitName.getText().toString();
            Log.d("Class",aa);
            Log.d("Class",bb);
            Log.d("Class",cc);
            Log.d("Class",SiteName);
            Log.d("Stuff","Before Open");
            db.open();
            Log.d("Stuff","Before Insert/After Open");
            db.InsertUnit(SiteName, cc, aa, bb);
            Log.d("Stuff","Before Close/After Insert");
            db.close();     
    }

EDIT

The onclick function that calls NewStuff

ucreate.setOnClickListener(new OnClickListener(){
        public void onClick(View m){
            Log.d("Ubox","Unit Name: "+uname.getText().toString());
            Log.d("Ubox","Unit Longitude: "+ulon.getText().toString());
            Log.d("Ubox","Unit Latitude: "+ulat.getText().toString());
            Log.d("Ubox","Site Name: "+SiteName);
            NewStuff ns= new NewStuff();
            ns.CreateNewUnit(ulat,ulon,uname,SiteName);
            Intent I= new Intent(Site.this, Site.class);
            I.putExtra("SITE", SiteName);
            startActivity(I);
  • 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-10T13:06:42+00:00Added an answer on June 10, 2026 at 1:06 pm

    You cannot initialize DbM as a field, Since the Context would not have been initialized

     DbM db=new DbM(this);
    

    Call

     db=new DbM(this); 
    

    only in or after OnCreate.

    Edit:
    You cannot call

    NewStuff ns= new NewStuff()
    

    This is because if you instantiate yourself , the context for the activity will not be set. So this inside new DbM(this); will have no meaning.

    Mainly you should not usually call a function an activity from another Activity.

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

Sidebar

Related Questions

I'm working on a project that is considering using Cassandra as a database. We
I am working on a project that is using an Oracle database with stored
I am currently working on a project that will store specific financial information about
I'm working on a Java project that incorporates a PostgresSQL 9.0 database tier, using
My team working in a project using Winforms application(c#) & MSSQL 2005 as database.
I'm working on a project using Scala running Selenium tests as part of a
As part of trying to learn hadoop, I'm working on a project using a
I have been working on a web project that stores locations for users. The
Say I have a database that stores table data by year using an identical
I'm working on a little pet project that organizes people's comic books and stores

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.