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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:31:03+00:00 2026-06-17T17:31:03+00:00

I found this source code from a tutorial but it crashes when I run

  • 0

I found this source code from a tutorial but it crashes when I run it.

My logcat:

01-25 00:26:30.898: E/AndroidRuntime(2762): FATAL EXCEPTION: main
01-25 00:26:30.898: E/AndroidRuntime(2762): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pinchtapzoom/com.pinchtapzoom.AssignmentTracker}: java.lang.NullPointerException
01-25 00:26:30.898: E/AndroidRuntime(2762):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at android.os.Looper.loop(Looper.java:137)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at android.app.ActivityThread.main(ActivityThread.java:4441)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at java.lang.reflect.Method.invoke(Method.java:511)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at dalvik.system.NativeStart.main(Native Method)
01-25 00:26:30.898: E/AndroidRuntime(2762): Caused by: java.lang.NullPointerException
01-25 00:26:30.898: E/AndroidRuntime(2762):     at com.pinchtapzoom.AssignmentTracker.onCreate(AssignmentTracker.java:70)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at android.app.Activity.performCreate(Activity.java:4465)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-25 00:26:30.898: E/AndroidRuntime(2762):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-25 00:26:30.898: E/AndroidRuntime(2762):     ... 11 more

This is where the code starts to crash:

//---retrieves all the records---

public Cursor getAllRecords() 
{
    db = DBHelper.getWritableDatabase();
     Cursor mCursor = db.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
            KEY_DUEDATE, KEY_COURSE, KEY_NOTES}, null, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

and

//---get all Records---

    db.open();
    Cursor c = db.getAllRecords();
    startManagingCursor(c);
    if (c.moveToFirst())
    {
        do {          
            DisplayRecord(c);
        } while (c.moveToNext());
    }
    db.close();

Here is the code for AssignmentTracker.java:

<code> 

package com.pinchtapzoom;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Toast;

public class AssignmentTracker extends Activity {

        /** Called when the activity is first created. */
 @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);


            setContentView(R.layout.main);

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

                @Override
                public void onClick(View v) {
                    Intent i = new Intent(AssignmentTracker.this, addassignment.class);
                    startActivity(i);
                }
            });


            try {           
                String destPath = "/data/data/" + getPackageName() + "/databases/AssignmentDB.db";
                File f = new File(destPath);            
                if (!f.exists()) {          
                    CopyDB( getBaseContext().getAssets().open("mydb"), 
                        new FileOutputStream(destPath));
                }
            } catch (FileNotFoundException e) {         
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            DBAdapter db = new DBAdapter(this); 
            //---add an assignment---

            db.open();        
            long id = db.insertRecord("Hello World", "2/18/2012", "DPR 224", "First Android Project");        
            id = db.insertRecord("Workbook Exercises", "3/1/2012", "MAT 100", "Do odd numbers");
            db.close();


            //---get all Records---

            db.open();
            Cursor c = db.getAllRecords();
            startManagingCursor(c);
            if (c.moveToFirst())
            {
                do {          
                    DisplayRecord(c);
                } while (c.moveToNext());
            }
            db.close();
            /*

            //---get a Record---
            db.open();
            Cursor c = db.getRecord(2);
            if (c.moveToFirst())        
                DisplayRecord(c);
            else
                Toast.makeText(this, "No Assignments found", Toast.LENGTH_LONG).show();
            db.close();
            */


            //---update Record---
            /*
            db.open();
            if (db.updateRecord(1, "Hello Android", "2/19/2012", "DPR 224", "First Android Project"))
                Toast.makeText(this, "Update successful.", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(this, "Update failed.", Toast.LENGTH_LONG).show();        
            db.close();
            */

            /*
            //---delete a Record---
            db.open();
            if (db.deleteRecord(1))
                Toast.makeText(this, "Delete successful.", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(this, "Delete failed.", Toast.LENGTH_LONG).show();            
            db.close();
            */
        }

        private class DBAdapter extends BaseAdapter {
            private LayoutInflater mInflater;
            public DBAdapter(AssignmentTracker assignmentTracker) {
                // TODO Auto-generated constructor stub
            }

            public Cursor getAllRecords() {
                // TODO Auto-generated method stub
                return null;
            }

            public Cursor getAllRecords(int i, int j) {
                // TODO Auto-generated method stub
                return null;
            }

            //private ArrayList<>

            public void close() {
                // TODO Auto-generated method stub

            }

            public long insertRecord(String string, String string2, String string3,
                    String string4) {
                // TODO Auto-generated method stub
                return 0;
            }

            public void open() {
                // TODO Auto-generated method stub

            }

            @Override
            public int getCount() {

                return 0;
            }

            @Override
            public Object getItem(int arg0) {

                return null;
            }

            @Override
            public long getItemId(int arg0) {

                return 0;
            }

            @Override
            public View getView(int arg0, View arg1, ViewGroup arg2) {

                return null;
            }

        }

        public void CopyDB(InputStream inputStream, OutputStream outputStream) 
        throws IOException {
            //---copy 1K bytes at a time---
            byte[] buffer = new byte[1024];
            int length;
            while ((length = inputStream.read(buffer)) > 0) {
                outputStream.write(buffer, 0, length);
            }
            inputStream.close();
            outputStream.close();
        }

        public void DisplayRecord(Cursor c)
        {
            Toast.makeText(this, 
                    "id: " + c.getString(0) + "\n" +
                    "Title: " + c.getString(1) + "\n" +
                    "Due Date:  " + c.getString(2),
                    Toast.LENGTH_SHORT).show();        
        } 

        public void addAssignment(View view)
        {

            Intent i = new Intent("com.pinchtapzoom.addassignment");
            startActivity(i);
            Log.d("TAG", "Clicked");
        }

    }

Here is the code for DBAdapter.java:

package com.pinchtapzoom;

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

public class DBAdapter {
    public static final String KEY_ROWID = "id";
    public static final String KEY_TITLE = "title";
    public static final String KEY_DUEDATE = "duedate";
    public static final String KEY_COURSE = "course";
    public static final String KEY_NOTES = "notes";
    private static final String TAG = "DBAdapter";

    private static final String DATABASE_NAME = "AssignmentsDB.db";
    private static final String DATABASE_TABLE = "assignments";
    private static final int DATABASE_VERSION = 2;

    private static final String DATABASE_CREATE =
        "create table if not exists assignments (id integer primary key autoincrement, "
        + "title VARCHAR not null, duedate date, course VARCHAR, notes VARCHAR );";

    private final Context context;    

    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;

    public DBAdapter(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) 
        {
            try {
                db.execSQL(DATABASE_CREATE);    
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        @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");
            db.execSQL("DROP TABLE IF EXISTS contacts");
            onCreate(db);
        }
    }    

    //---opens the database---
    public DBAdapter open() throws SQLException 
    {
        db = DBHelper.getWritableDatabase();
        return this;
    }

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

    //---insert a record into the database---
    public long insertRecord(String title, String duedate, String course, String notes) 
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_TITLE, title);
        initialValues.put(KEY_DUEDATE, duedate);
        initialValues.put(KEY_COURSE, course);
        initialValues.put(KEY_NOTES, notes);
        return db.insert(DATABASE_TABLE, null, initialValues);
    }

    //---deletes a particular record---
    public boolean deleteContact(long rowId) 
    {
        return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }

    //---retrieves all the records---
    public Cursor getAllRecords() 
    {
        db = DBHelper.getWritableDatabase();
         Cursor mCursor = db.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
                KEY_DUEDATE, KEY_COURSE, KEY_NOTES}, null, null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }

    //---retrieves a particular record---
    public Cursor getRecord(long rowId) throws SQLException 
    {
        Cursor mCursor =
                db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                KEY_TITLE, KEY_DUEDATE, KEY_COURSE, KEY_NOTES}, 
                KEY_ROWID + "=" + rowId, null, null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }

    //---updates a record---
    public boolean updateRecord(long rowId, String title, String duedate, String course, String notes) 
    {
        ContentValues args = new ContentValues();
        args.put(KEY_TITLE, title);
        args.put(KEY_DUEDATE, duedate);
        args.put(KEY_COURSE, course);
        args.put(KEY_NOTES, notes);
        return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
    }
}

The tutorial is: here

It stops working when I uncommented the code.
There are lots of questions about this question but no clear solution.
I just started learning about SQLite so need some help to find the solution.

Thanks in advance

  • 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-17T17:31:05+00:00Added an answer on June 17, 2026 at 5:31 pm

    The problem is that you have two classes named DBAdapter and you are using the wrong one…
    Simply remove the entire DBAdapter class that starts with:

    private class DBAdapter extends BaseAdapter {
    

    This DBAdapter inside AssignmentTracker does nothing anyway.

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

Sidebar

Related Questions

I have found this macro while digging in the source code of tweejump game.
I am a beginner in C. While reading git's source code, I found this
found this little code snippet that seems to do what i want, but im
I followed this tutorial and the source code : http://blog.objectgraph.com/index.php/2010/04/20/encrypting-decrypting-base64-encode-decode-in-iphone-objective-c/ And then, I downloaded
I found this code snippet in latest Android notepad tutorial link which is using
I'm using the source code found on this site here: http://webtint.net/tutorials/5-star-rating-system-in-php-mysql-and-jquery/comment-page-1/#comment-2562 A fantastic resource,
I found a tutorial for a UITableView – Drill down table view, source code
I found this site/tutorial/demo from another question here on SO. Very nice and clean
I'm trying to include a source code file when I run irb but irb
This is one usage I found in a open source software.And I don't understant

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.