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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:53:49+00:00 2026-06-10T00:53:49+00:00

I’m having problems with my application.It seem that I can’t open my Activity as

  • 0

I’m having problems with my application.It seem that I can’t open my Activity as well as I can’t insert data from a ListView into database.

But, I can open Activity and insert data into database before I’ve created 5 tables into one DBAdapter class.

But after I’ve created the tables in one DBAdapter, I’m having problems with making my application work. I’ve followed examples which made my application work.

This is my LogCat:

08-21 13:36:27.421: D/AndroidRuntime(543): Shutting down VM
08-21 13:36:27.421: W/dalvikvm(543): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-21 13:36:27.441: E/AndroidRuntime(543): FATAL EXCEPTION: main
08-21 13:36:27.441: E/AndroidRuntime(543): java.lang.RuntimeException: Unable to start activity ComponentInfo{main.page/main.page.PersonalInformation}: java.lang.NullPointerException
08-21 13:36:27.441: E/AndroidRuntime(543):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-21 13:36:27.441: E/AndroidRuntime(543):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-21 13:36:27.441: E/AndroidRuntime(543):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-21 13:36:27.441: E/AndroidRuntime(543):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-21 13:36:27.441: E/AndroidRuntime(543):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 13:36:27.441: E/AndroidRuntime(543):  at android.os.Looper.loop(Looper.java:137)
08-21 13:36:27.441: E/AndroidRuntime(543):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-21 13:36:27.441: E/AndroidRuntime(543):  at java.lang.reflect.Method.invokeNative(Native Method)
08-21 13:36:27.441: E/AndroidRuntime(543):  at java.lang.reflect.Method.invoke(Method.java:511)
08-21 13:36:27.441: E/AndroidRuntime(543):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-21 13:36:27.441: E/AndroidRuntime(543):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-21 13:36:27.441: E/AndroidRuntime(543):  at dalvik.system.NativeStart.main(Native Method)
08-21 13:36:27.441: E/AndroidRuntime(543): Caused by: java.lang.NullPointerException
08-21 13:36:27.441: E/AndroidRuntime(543):  at main.page.BuddyDBAdapter.getAllNames(BuddyDBAdapter.java:37)
08-21 13:36:27.441: E/AndroidRuntime(543):  at main.page.PersonalInformation.onCreate(PersonalInformation.java:41)
08-21 13:36:27.441: E/AndroidRuntime(543):  at android.app.Activity.performCreate(Activity.java:4465)
08-21 13:36:27.441: E/AndroidRuntime(543):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-21 13:36:27.441: E/AndroidRuntime(543):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-21 13:36:27.441: E/AndroidRuntime(543):  ... 11 more
08-21 13:36:27.711: I/dalvikvm(543): threadid=3: reacting to signal 3
08-21 13:36:27.751: I/dalvikvm(543): Wrote stack traces to '/data/anr/traces.txt'
08-21 13:36:28.061: I/dalvikvm(543): threadid=3: reacting to signal 3
08-21 13:36:28.061: I/dalvikvm(543): Wrote stack traces to '/data/anr/traces.txt'

This is the code where I’ve created the 5 tables within one DBAdapter:

 package main.page;


import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class AnniversaryDBAdapter
{

    private static final String DATABASE_NAME = "AllTables";
    private static final int DATABASE_VERSION = 2;

     private static final String CREATE_TABLE_TITLE = "create table titles(title_id integer primary key autoincrement, name text not null, image text not null);";
    private static final String CREATE_TABLE_BUDDIESLIST = "create table buddiesList(name_id integer primary key autoincrement, name text not null);";
    private static final String CREATE_TABLE_LIKES = "create table likes(likes_id integer primary key autoincrement,like text not null, name text not null, FOREIGN KEY(name)REFERENCES "+CREATE_TABLE_BUDDIESLIST+" (name));";
    private static final String CREATE_TABLE_DISLIKES = "create table dislike(dlike_id integer primary key autoincrement, dislike text not null, name text not null, FOREIGN KEY(name)REFERENCES "+CREATE_TABLE_BUDDIESLIST+" (name));";
    private static final String CREATE_TABLE_EVENTS = "create table events(date_id integer primary key autoincrement, date text not null, starttime text not null, endtime text not null, name text not null,title_id integer, desc text not null, alarm text not null, location text not null, FOREIGN KEY(name)REFERENCES "+CREATE_TABLE_BUDDIESLIST+" (name), FOREIGN KEY(title_id)REFERENCES "+CREATE_TABLE_TITLE+" (title_id));";

    private final Context context;
    private static final String TAG = "DBAdapter";

    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;

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




private static class DatabaseHelper extends SQLiteOpenHelper
{

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

    @Override
    public void onCreate(SQLiteDatabase db)
    {
        db.execSQL(CREATE_TABLE_BUDDIESLIST);
        db.execSQL(CREATE_TABLE_LIKES);
        db.execSQL(CREATE_TABLE_EVENTS);
        db.execSQL(CREATE_TABLE_TITLE);
        db.execSQL(CREATE_TABLE_DISLIKES);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        Log.w(TAG, "Upgrading database from version "+oldVersion+" to "+newVersion+", which will destroy all old data");

        onCreate(db);

    }

}


public AnniversaryDBAdapter open() throws SQLException
{
    this.db = this.DBHelper.getWritableDatabase();
    return this;
}

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

}

I’ve followed from these 2 examples

1. http://www.devdaily.com/android/sqlite-foreign-keys-example

2. http://androidforbeginners.blogspot.sg/2010/01/creating-multiple-sqlite-database.html

This is my code which I can’t open in my application:

package main.page;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class PersonalInformation extends Activity
{
    Button btnSave, btnBack, btnView;
    EditText txtDate, txtType, txtLikes, txtDislikes;

    final Context context = this;           
    private int mSpinnerNamesId;            

    LikesDBAdapter likeDB = new LikesDBAdapter(this);
    DislikesDBAdapter dislikeDB = new DislikesDBAdapter(this);


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


        BuddyDBAdapter buddyDB = new BuddyDBAdapter(this);

        buddyDB.open();

        Spinner namesSpinner = (Spinner) findViewById(R.id.nameSpinner);
        Cursor namesCursor = buddyDB.getAllNames();
        startManagingCursor(namesCursor);

        String[] from = new String[] {BuddyDBAdapter.KEY_NAME};
        int[] to = new int[] {android.R.id.text1};

        SimpleCursorAdapter namesSpinnerAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, namesCursor, from, to);
        namesSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        namesSpinner.setAdapter(namesSpinnerAdapter);
        buddyDB.close();

        namesSpinner.setOnItemSelectedListener(new OnItemSelectedListener()
        {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
            {
                Cursor c = (Cursor)parent.getItemAtPosition(pos);
                mSpinnerNamesId = c.getInt(c.getColumnIndexOrThrow(BuddyDBAdapter.KEY_ROWID));
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent)
            {               
            }
        });


        btnSave = (Button) findViewById(R.id.btnSave);
        btnSave.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                likeDB.open();
                long likes_id;
                Spinner nameSpinner = (Spinner) findViewById(R.id.nameSpinner);
                String NameValue = nameSpinner.getSelectedItem().toString();

                EditText txtLikes = (EditText) findViewById(R.id.txtLikes);
                String LikesValue = txtLikes.getText().toString();

                likes_id = likeDB.insertLikes(NameValue, LikesValue);
                likeDB.close();

                dislikeDB.open();
                long dislikes_id;
                Spinner names = (Spinner) findViewById(R.id.nameSpinner);
                String NamesValue = names.getSelectedItem().toString();

                EditText txtDislikes = (EditText) findViewById(R.id.txtDislikes);
                String DislikesValue = txtDislikes.getText().toString();

                dislikes_id = dislikeDB.insertDislikes(NamesValue, DislikesValue);

                Toast.makeText(getBaseContext(), 
                        "Your information is saved successfully!", Toast.LENGTH_SHORT).show();
                dislikeDB.close();
            }
        });

        btnBack = (Button) findViewById(R.id.btnMain);
        btnBack.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                finish();
            }
        });

    }
}

This is BuddyDBAdapter.java which connects to PersonalInformation.java

package main.page;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class BuddyDBAdapter extends AnniversaryDBAdapter
{
    public static final String KEY_ROWID = "name_id";
    public static final String KEY_NAME = "name";
    private static final String TAG = "DBAdapter";
    private static final String CREATE_TABLE_BUDDIESLIST = "buddiesList";

    private SQLiteDatabase db;

    public BuddyDBAdapter(Context ctx)
    {
        super(ctx);
    }

    public long insertNames(String name)
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_NAME, name);
        return db.insert(CREATE_TABLE_BUDDIESLIST, null, initialValues);
    }

    public boolean deleteName(long rowId)
    {
        return db.delete(CREATE_TABLE_BUDDIESLIST, KEY_ROWID + "=" + rowId, null) > 0;
    }

    public Cursor getAllNames()
    {
        return db.query(CREATE_TABLE_BUDDIESLIST, new String[] { KEY_ROWID, KEY_NAME }, null, null, null, null, null);
    }

    public Cursor getName(long rowId) throws SQLException
    {
        Cursor c = db.query(true, CREATE_TABLE_BUDDIESLIST, new String[] { KEY_ROWID, KEY_NAME }, KEY_ROWID + "=" + rowId, null, null, null, null, null);
        if(c != null)
        {
            c.moveToFirst();
        }
        return c;
    }
}

Any help will be appreciated.

  • 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-10T00:53:51+00:00Added an answer on June 10, 2026 at 12:53 am

    Your BuddyDBAdapter class is not using the DatabaseHelper class like your base class. In that DatabaseHelper class, you are actually creating and opening the database.

    In BuddyDBAdapter, db has not been initialized and is throwing the exception. Modify this class to use the functionality written in the base class.

    Hope this helps…

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.