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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:02:05+00:00 2026-06-09T09:02:05+00:00

As soon as I open the activity where my database is being opened along

  • 0

As soon as I open the activity where my database is being opened along with a bunch of other stuff, my application crashes with a NullPointerException.

I press a button which opens this activity, WorkoutEdit.java, which immediately crashes.

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class WorkoutEdit extends Activity {

    public TextView mTitleText;
    //private EditText mBodyText;
    private Long mRowId;
    private StrongDbAdapter mDbHelper;
    private ViewFlipper viewFlipper;
    public TextView squats;
    public boolean workoutA;
    public String workoutState;
    //private double rowId = mRowId;
    public String squatLabel;
    public Button confirmButton;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.workout_edit3);

        mDbHelper = new StrongDbAdapter(this);


            mDbHelper.open();


        setTitle(R.string.edit_workout);

        mTitleText = (TextView) findViewById(R.id.workout_row);
        //mBodyText = (EditText) findViewById(R.id.body);
        viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
        squats = (TextView) findViewById(R.id.squatLabel);
        final AlertDialog.Builder alert = new AlertDialog.Builder(this);
        squatLabel = squats.getText().toString();



       confirmButton = (Button) findViewById(R.id.confirmButton);

        mRowId = (savedInstanceState == null) ? null :
            (Long) savedInstanceState.getSerializable(StrongDbAdapter.KEY_ROWID);
        if (mRowId == null) {

            getWorkoutState();
            if(workoutA == true){
                workoutState = "WorkoutA";
            }else{
                workoutState = "WorkoutB";
            }

            Bundle extras = getIntent().getExtras();
            mRowId = extras != null ? extras.getLong(StrongDbAdapter.KEY_ROWID)
                                    : null;
        }


       // populateFields();

        confirmButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                setResult(RESULT_OK);
                finish();
            }

        });



        squats.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                alert.setTitle("Squats");
                alert.setMessage("Message");

                //AlertDialog dialog = alert.create();

                //set an EditText view to get user input
                final EditText input = new EditText(aMethod());
                input.setInputType(InputType.TYPE_CLASS_NUMBER);

                //dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

                alert.setView(input);

                alert.setPositiveButton("Ok", new DialogInterface.OnClickListener(){
                    public void onClick(DialogInterface dialog, int whichButton){
                        String value = input.getText().toString();
                        //Do something with value

                        value = "Squats - " + value;

                        squats.setText(value);

                    }                           
                });

                alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
                    public void onClick(DialogInterface dialog, int whichButton){
                        //Cancelled
                    }
                });

                AlertDialog dialog = alert.create();

                dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);



                //alert.show();
                dialog.show();

            }
        });


        RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radgroup1);




        radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(){
            public void onCheckedChanged(RadioGroup group, int checkedId)
            {
                switch(checkedId)
                {
                    case(R.id.rad2):
                        viewFlipper.setDisplayedChild(1);
                    break;
                    case(R.id.rad3):
                        viewFlipper.setDisplayedChild(2);
                    break;
                    default:
                        viewFlipper.setDisplayedChild(0);
                    break;
                }
            }
        });     

        //saveState();



        if((Long)(mRowId-1) == null){
            squats.setText("Squats - 45");
        }else{
            Cursor note = mDbHelper.fetchNote((Long)(mRowId-1));
            startManagingCursor(note);
            squats.setText(note.getString(
                    note.getColumnIndexOrThrow(StrongDbAdapter.SQUAT_LABEL)));
            String squat = squats.getText().toString();
            int squatsWeight = Integer.parseInt(squat);
            squatsWeight = squatsWeight + 5 ;
            squats.setText("Squats - " + squatsWeight);
        }




//end of onCreate
    }
    /*
    private void populateFields() {
        if (mRowId != null) {
            Cursor note = mDbHelper.fetchNote(mRowId);
            startManagingCursor(note);
            mTitleText.setText(note.getString(
                    note.getColumnIndexOrThrow(StrongDbAdapter.KEY_TITLE)));
            workoutState=(note.getString(
                    note.getColumnIndexOrThrow(StrongDbAdapter.WORKOUT_STATE)));
            squats.setText(note.getString(note.getColumnIndexOrThrow(StrongDbAdapter.SQUAT_LABEL)));
        }
    }
    */


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //saveState();
        //outState.putSerializable(StrongDbAdapter.KEY_ROWID, mRowId);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //saveState();
    }

    @Override
    protected void onResume() {
        super.onResume();
        //populateFields();
    }



    //Saves all the data to the database
    private void saveState() {
        String title = workoutState;
        String squatLabel = squats.getText().toString();


        if (mRowId == null) {
            long id = mDbHelper.createNote(title, squatLabel);
            if (id > 0) {
                mRowId = id;
            }
        } else {
            mDbHelper.updateNote(mRowId, title);
        }
    }       

    public Context aMethod(){
        Context actContext = this;
        return actContext;
    }

    public boolean getWorkoutState(){
        if(workoutA!=false){
            workoutA = true;
        }else{
            workoutA = false;
        }


        return workoutA;

    }




}

Here are my LogCat logs:

08-04 20:12:27.682: E/AndroidRuntime(23360): FATAL EXCEPTION: main
08-04 20:12:27.682: E/AndroidRuntime(23360): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.anapoleon.android.stronglifts/com.anapoleon.android.stronglifts.WorkoutEdit}: java.lang.NullPointerException
08-04 20:12:27.682: E/AndroidRuntime(23360):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at android.app.ActivityThread.access$1500(ActivityThread.java:135)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at android.os.Handler.dispatchMessage(Handler.java)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at android.os.Looper.loop(Looper.java)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at android.app.ActivityThread.main(ActivityThread.java:4385)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at java.lang.reflect.Method.invokeNative(Native Method)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at java.lang.reflect.Method.invoke(Method.java:507)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at dalvik.system.NativeStart.main(Native Method)
08-04 20:12:27.682: E/AndroidRuntime(23360): Caused by: java.lang.NullPointerException
08-04 20:12:27.682: E/AndroidRuntime(23360):    at com.anapoleon.android.stronglifts.WorkoutEdit.onCreate(WorkoutEdit.java:166)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
08-04 20:12:27.682: E/AndroidRuntime(23360):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
08-04 20:12:27.682: E/AndroidRuntime(23360):    ... 11 more
  • 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-09T09:02:06+00:00Added an answer on June 9, 2026 at 9:02 am

    So… your mRowId can be set to null in your code but you don’t check for it’s null status at the line 166.

    Also note that (Long)(mRowId-1) == null will never be true.

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

Sidebar

Related Questions

I want to prevent database connection being open as much as possible, because this
I'm trying to open a modal dialog as soon as a WPF application has
As soon as i open my application i have to play a video, by
As soon as the user clicks the delete button my jQuery script asks the
In my application as soon as an object is dropped on canvas I stored
WPF Application Shuts Down if I open a window and close it, but if
As soon as I open the VS cmd prompt it says ERROR: Cannot determine
I have an EditText in my Activity . As soon as the Activity starts
The new Dreamweaver 5.5 closes the apostrophe as soon as you open it. Is
New to rails, open source and soon ready for deploying to a production environment,

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.