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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:45:32+00:00 2026-05-15T14:45:32+00:00

06-29 01:24:15.882: ERROR/AndroidRuntime(747): Uncaught handler: thread main exiting due to uncaught exception 06-29 01:24:15.922:

  • 0
06-29 01:24:15.882: ERROR/AndroidRuntime(747): Uncaught handler: thread main exiting due to uncaught exception
06-29 01:24:15.922: ERROR/AndroidRuntime(747): java.lang.RuntimeException: Unable to start activity ComponentInfo{one.two/one.two.Arrival}: java.lang.NullPointerException
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at android.os.Looper.loop(Looper.java:123)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at android.app.ActivityThread.main(ActivityThread.java:3948)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at java.lang.reflect.Method.invokeNative(Native Method)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at java.lang.reflect.Method.invoke(Method.java:521)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at dalvik.system.NativeStart.main(Native Method)
06-29 01:24:15.922: ERROR/AndroidRuntime(747): Caused by: java.lang.NullPointerException
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at one.two.DBAdapter.getAllTitles(DBAdapter.java:167)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at one.two.Arrival.getData(Arrival.java:35)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at one.two.Arrival.onCreate(Arrival.java:21)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
06-29 01:24:15.922: ERROR/AndroidRuntime(747):     ... 11 more

My Class to call the database

package one.two;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Arrival extends ListActivity
{
    private ListView listView;
    DBAdapter db = new DBAdapter(this);

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        getData();
        // db.open();
        listView = (ListView) findViewById(android.R.id.list);
        // db.close();
    }

    private void getData()
    {
        // show some display that you are going to open db
        db.open();
        // show some display that you have opened

        // redundant see below statement ---- List<String> items = new ArrayList<String>();
        // call the DBAdapter method to getAllTitles()
        List<String> items = DBAdapter.getAllTitles();
        // iterate through the items one by one thru display statement or show
        // on layout
        // check how to do that

        ArrayAdapter<String> titles = new ArrayAdapter<String>(this,
                R.layout.main, items);

        db.close();
    }

}

My DBAdapter.java

package one.two;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import java.util.ArrayList;

public class DBAdapter extends ListActivity
{
    private static String DB_PATH = "/data/data/one.two/databases/";
    private static final String DATABASE_NAME = "ferry.db";
    private static final String DATABASE_TABLE = "port";
    public static Context context;

    public String status = "status";
    public String id = "id";
    public String arrival = "arrival";
    public String destination = "destination";
    public String ferry = "ferry";

    //null constructor
    public DBAdapter()
    {

    }

    //overloaded non-null constructor
    public DBAdapter(Context context)
    {

    }

    public class DatabaseHelper extends SQLiteOpenHelper
    {
        Context context;
        DatabaseHelper(Context context)
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            this.context = context;

        }//end constructor DatabaseHelper

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

        @Override
        public void onCreate(SQLiteDatabase db)
        {
            boolean dbExist = checkDatabase();

            if (dbExist)
            {
            }
            else
            {
                this.getReadableDatabase();
                try
                {
                    copyDataBase();
                }
                catch (IOException e)
                {
                    throw new Error("Error copying database");
                }
            }
        }//end onCreate()
    }// end class DatabaseHelper

    private static DatabaseHelper DBHelper;
    private static SQLiteDatabase db;

    private static final int DATABASE_VERSION = 1;

    //// context brought up /////////////
    //private final Context context;


        private boolean checkDatabase()
        {
            SQLiteDatabase checkDB = null;
            try
            {
                String myPath = DB_PATH + DATABASE_NAME;
                checkDB = SQLiteDatabase.openDatabase(myPath, null,
                        SQLiteDatabase.OPEN_READONLY);
            }
            catch (SQLiteException e)
            {

                // database doesn't exist yet
            }
            if (checkDB != null)
            {

                checkDB.close();
            }
            return checkDB != null ? true : false;
        }//end checkDatabase()

        private void copyDataBase() throws IOException
        {

            // Open your local db as the input stream
            InputStream myInput = context.getAssets().open(DATABASE_NAME);

            // Path to the just created empty db
            String outFileName = DB_PATH + DATABASE_NAME;

            // Open the empty db as the output stream
            OutputStream myOutput = new FileOutputStream(outFileName);

            // transfer bytes from the inputfile to the outputfile
            byte[] buffer = new byte[1024];
            int length;
            while ((length = myInput.read(buffer)) > 0)
            {
                myOutput.write(buffer, 0, length);
            }

            // Close the streams
            myOutput.flush();
            myOutput.close();
            myInput.close();

        }//end copyDataBase()

        public void DBAdapter() throws SQLException
        {
            String myPath = DB_PATH + DATABASE_NAME;
            db = SQLiteDatabase.openDatabase(myPath, null,
                    SQLiteDatabase.OPEN_READONLY);
        }//end DBAdapter()
        public void open()
        {
            //Open the database
            String myPath = DB_PATH + DATABASE_NAME;
            db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

        }
        // ---closes the database---
        public void close()
        {
            DBHelper.close();
        }//end close()

        public static List<String> getAllTitles()
        {

            List<String> titles = new ArrayList<String>();

                Cursor c=null;
                c = db.query("port",
                        new String[] { "status", "id", "arrival",
                                "destination", "ferry" }, null, null,
                        null, null, null);
                try {
                    if (c!=null) {
                        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) 
                        {
                            DBAdapter title = new DBAdapter(context);
                            title.status = c.getString(0);
                            title.id = c.getString(1);
                            title.arrival = c.getString(2);
                            title.destination = c.getString(3);
                            title.ferry = c.getString(4);
                        }
                    }
                } finally {
                    if (c!=null) {
                    c.close();
                }

        }
            return titles;
        }//end getAllTitles()
    }//end class DBAdapter
  • 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-15T14:45:32+00:00Added an answer on May 15, 2026 at 2:45 pm

    You never call open() on your object. You are using a static call in your code, but that static call depends on nonstatic methods being called to set up the static data members. So when you call db.query() db is null, hence the null pointer exception. Your overall architecture is fundamentally flawed. You need to instantiate your DBAdapter object and call several methods such as open from within your static method. However, inside your static method, you are relying on the context object being set. However, you don’t set that until you call the constructor. You need to make sure that your references are set before attempting to operate on them. I would suggest not attempting to make a static call like this unless you want to pass it a Context object. From there you will need to instantiate the DBAdapter object and call the appropriate setup methods (like open) before you can interact with the database.

    Edit

    Based on rereading your code, change your database adapter class to remove the static method:

    package one.two;
    
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.List;
    
    import android.app.ListActivity;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteException;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.util.Log;
    import java.util.ArrayList;
    
    public class DBAdapter extends ListActivity
    {
        private static String DB_PATH = "/data/data/one.two/databases/";
        private static final String DATABASE_NAME = "ferry.db";
        private static final String DATABASE_TABLE = "port";
        public static Context context;
    
        public String status = "status";
        public String id = "id";
        public String arrival = "arrival";
        public String destination = "destination";
        public String ferry = "ferry";
    
        //null constructor
        public DBAdapter()
        {
    
        }
    
        //overloaded non-null constructor
        public DBAdapter(Context context)
        {
    
        }
    
        public class DatabaseHelper extends SQLiteOpenHelper
        {
            Context context;
            DatabaseHelper(Context context)
            {
                super(context, DATABASE_NAME, null, DATABASE_VERSION);
                this.context = context;
    
            }//end constructor DatabaseHelper
    
            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion,
                    int newVersion)
            {
            }//end onUpgrade()
    
            @Override
            public void onCreate(SQLiteDatabase db)
            {
                boolean dbExist = checkDatabase();
    
                if (dbExist)
                {
                }
                else
                {
                    this.getReadableDatabase();
                    try
                    {
                        copyDataBase();
                    }
                    catch (IOException e)
                    {
                        throw new Error("Error copying database");
                    }
                }
            }//end onCreate()
        }// end class DatabaseHelper
    
        private static DatabaseHelper DBHelper;
        private static SQLiteDatabase db;
    
        private static final int DATABASE_VERSION = 1;
    
        //// context brought up /////////////
        //private final Context context;
    
    
            private boolean checkDatabase()
            {
                SQLiteDatabase checkDB = null;
                try
                {
                    String myPath = DB_PATH + DATABASE_NAME;
                    checkDB = SQLiteDatabase.openDatabase(myPath, null,
                            SQLiteDatabase.OPEN_READONLY);
                }
                catch (SQLiteException e)
                {
    
                    // database doesn't exist yet
                }
                if (checkDB != null)
                {
    
                    checkDB.close();
                }
                return checkDB != null ? true : false;
            }//end checkDatabase()
    
            private void copyDataBase() throws IOException
            {
    
                // Open your local db as the input stream
                InputStream myInput = context.getAssets().open(DATABASE_NAME);
    
                // Path to the just created empty db
                String outFileName = DB_PATH + DATABASE_NAME;
    
                // Open the empty db as the output stream
                OutputStream myOutput = new FileOutputStream(outFileName);
    
                // transfer bytes from the inputfile to the outputfile
                byte[] buffer = new byte[1024];
                int length;
                while ((length = myInput.read(buffer)) > 0)
                {
                    myOutput.write(buffer, 0, length);
                }
    
                // Close the streams
                myOutput.flush();
                myOutput.close();
                myInput.close();
    
            }//end copyDataBase()
    
            public void DBAdapter() throws SQLException
            {
                String myPath = DB_PATH + DATABASE_NAME;
                db = SQLiteDatabase.openDatabase(myPath, null,
                        SQLiteDatabase.OPEN_READONLY);
            }//end DBAdapter()
            public void open()
            {
                //Open the database
                String myPath = DB_PATH + DATABASE_NAME;
                db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
    
            }
            // ---closes the database---
            public void close()
            {
                DBHelper.close();
            }//end close()
    
            public List<String> getAllTitles()
            {
    
                List<String> titles = new ArrayList<String>();
    
                    Cursor c=null;
                    c = db.query("port",
                            new String[] { "status", "id", "arrival",
                                    "destination", "ferry" }, null, null,
                            null, null, null);
                    try {
                        if (c!=null) {
                            for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) 
                            {
                                DBAdapter title = new DBAdapter(context);
                                title.status = c.getString(0);
                                title.id = c.getString(1);
                                title.arrival = c.getString(2);
                                title.destination = c.getString(3);
                                title.ferry = c.getString(4);
                            }
                        }
                    } finally {
                        if (c!=null) {
                        c.close();
                    }
    
            }
                return titles;
            }//end getAllTitles()
        }//end class DBAdapter
    

    And change your Arrival class to use the nonstatic method:

    package one.two;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import android.app.ListActivity;
    import android.os.Bundle;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    
    public class Arrival extends ListActivity
    {
        private ListView listView;
        DBAdapter db = new DBAdapter(this);
    
        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            getData();
            // db.open();
            listView = (ListView) findViewById(android.R.id.list);
            // db.close();
        }
    
        private void getData()
        {
            // show some display that you are going to open db
            db.open();
            // show some display that you have opened
    
            // redundant see below statement ---- List<String> items = new ArrayList<String>();
            // call the DBAdapter method to getAllTitles()
            List<String> items = db.getAllTitles();
            // iterate through the items one by one thru display statement or show
            // on layout
            // check how to do that
    
            ArrayAdapter<String> titles = new ArrayAdapter<String>(this,
                    R.layout.main, items);
    
            db.close();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a bizarre error here: 882 Segmentation fault ./a.out The segment of code:
im gettting the following error org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
ISQL-SE 4.10.DD6 (DOS 6.22): BCHECK C-ISAM B-tree Checker version 4.10.DD6 C-ISAM File: c:\dbfiles.dbs\*.* ERROR:
Why is it that when I convert a string with value 22.882 to double,
<select id=sel> <option value=123 selected=selected>text1</option> <option value=44>text2</option> <option value=882>text3</option> ... </select> How to get
When I query my database I keep getting an error saying SQLException: no such
I use tryCatch a lot to capture potential error messages in my R code,
I want to format a number, e.g. 279388242 . Output: 2,793,882.42 How can I
One of the testers in my company found an error on my ASP.Net MVC
I'm not that familiar with all the behavior of Java so sorry if I'm

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.