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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:10:39+00:00 2026-05-27T13:10:39+00:00

I have been trying for hours to figure out why android crashes after loading

  • 0

I have been trying for hours to figure out why android crashes after loading Profile activity. The line that is causing the issue is :

mRowId = extras != null ? extras.getLong(OverLimitDbAdapter.KEY_ROWID): null;

located in Profile.java. so I have firstly

OvertheLimit.java which puts extras via a menu option intent:

package uk.co.obdesign.android.overthelimit;


import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.RadioButton;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class Overthelimit extends ListActivity {
    private OverLimitDbAdapter dbHelper;
    private static final int USER_CREATE = 0;
    private static final int USER_EDIT = 1;
    private Cursor cursor;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        this.getListView();
        dbHelper = new OverLimitDbAdapter(this);
        dbHelper.open();
        fillData();
        registerForContextMenu(getListView());
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        fillData();

    }
    private void fillData() {
        cursor = dbHelper.fetchAllUserDrinks();
        startManagingCursor(cursor);


        String[] from = new String[] { OverLimitDbAdapter.KEY_USERNAME };
        int[] to = new int[] { R.id.label };

        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
                R.layout.user_row, cursor, from, to);
        setListAdapter(notes);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return true;
    } 

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
        case R.id.profile:
            Intent myIntent1 = new Intent(Overthelimit.this, Profile.class);
            myIntent1.putExtra(OverLimitDbAdapter.KEY_ROWID, cursor.getString(cursor.getColumnIndexOrThrow(OverLimitDbAdapter.KEY_ROWID)));
            startActivityForResult(myIntent1, 0);
            return true;
        case R.id.myusual:
            Intent myIntent2 = new Intent(Overthelimit.this, MyUsual.class);
            startActivityForResult(myIntent2, 0);
            return true;
        case R.id.trackme:
            Intent myIntent3 = new Intent(Overthelimit.this, TrackMe.class);
            startActivityForResult(myIntent3, 0);
            return true;
        case R.id.moreinfo:
            Intent myIntent4 = new Intent(Overthelimit.this, MoreInfo.class);
            startActivityForResult(myIntent4, 0);
            return true;


        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (dbHelper != null) {
            dbHelper.close();
        }
    }


}

then selecting the profile menu option takes me to Profile, which crashes trying to get extras.
I have checked data using toast and it’s there. any ideas?

package uk.co.obdesign.android.overthelimit;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;


public class Profile extends Activity{
    private EditText mUserName;
    private RadioGroup mGender;
    private EditText mAge;
    private EditText mHeight;
    private EditText mWeight;
    private Spinner mDrinkerType;
    private Long mRowId;
    private OverLimitDbAdapter mDbHelper;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(final Bundle bundle) {
        super.onCreate(bundle);
        mDbHelper = new OverLimitDbAdapter(this);
        mDbHelper.open();
        setContentView(R.layout.profile);
        mUserName = (EditText) findViewById(R.id.userName);
        mAge = (EditText) findViewById(R.id.age);
        mHeight = (EditText) findViewById(R.id.height);
        mWeight = (EditText) findViewById(R.id.weight);
        mGender = (RadioGroup) findViewById(R.id.gender);


        mDrinkerType = (Spinner) findViewById(R.id.drinkerType);

        Button next = (Button) findViewById(R.id.NextUsualDrinks);


                mRowId = (bundle == null) ? null :
                    (Long) bundle.getSerializable(OverLimitDbAdapter.KEY_ROWID);
                if (mRowId == null) {
                    Bundle extras = getIntent().getExtras();
                    mRowId = extras != null ? extras.getLong(OverLimitDbAdapter.KEY_ROWID)
                                            : null;
                }


            populateFields();

            next.setOnClickListener(new View.OnClickListener() {
             public void onClick(View view) {   
                 setResult(RESULT_OK);
                    //finish();
                Intent myIntent = new Intent(view.getContext(), MyUsual.class);
                startActivityForResult(myIntent, 0);
            }

        });


    }
    private void populateFields() {
        if (mRowId != null) {
            Cursor todo = mDbHelper.fetchUserDrinks(mRowId);
            startManagingCursor(todo);

            mUserName.setText(todo.getString(todo
                    .getColumnIndexOrThrow(OverLimitDbAdapter.KEY_USERNAME)));
            String gender = todo.getString(todo
                    .getColumnIndexOrThrow(OverLimitDbAdapter.KEY_GENDER));


            // Returns an integer which represents the selected radio button's ID
             int selected = mGender.getCheckedRadioButtonId();

            // Gets a reference to our "selected" radio button
             RadioButton b = (RadioButton) findViewById(selected);

            // Now you can get the text or whatever you want from the "selected" radio button
             String bn = (String) b.getText();

             if (bn.equalsIgnoreCase(gender)) {
                 if(gender == "male") 
                            ((RadioButton) findViewById(R.id.male)).setChecked(true);
                 else if (gender == "female")
                            ((RadioButton) findViewById(R.id.female)).setChecked(true);


             }


            mAge.setText(todo.getString(todo
                    .getColumnIndexOrThrow(OverLimitDbAdapter.KEY_AGE)));
            mHeight.setText(todo.getString(todo
                    .getColumnIndexOrThrow(OverLimitDbAdapter.KEY_HEIGHT)));
            mWeight.setText(todo.getString(todo
                    .getColumnIndexOrThrow(OverLimitDbAdapter.KEY_WEIGHT)));
            String drinkerType = todo.getString(todo
                    .getColumnIndexOrThrow(OverLimitDbAdapter.KEY_TYPE));

            for (int i = 0; i < mDrinkerType.getCount(); i++) {

                String s = (String) mDrinkerType.getItemAtPosition(i);
                Log.e(null, s + " " + drinkerType);
                if (s.equalsIgnoreCase(drinkerType)) {
                    mDrinkerType.setSelection(i);
                }
            }
        }
    }

    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        saveState();
        outState.putSerializable(OverLimitDbAdapter.KEY_ROWID, mRowId);
    }

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

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

    private void saveState() {
        String username = mUserName.getText().toString();

        // Returns an integer which represents the selected radio button's ID
         int selected = mGender.getCheckedRadioButtonId();
        // Gets a reference to our "selected" radio button
         RadioButton b = (RadioButton) findViewById(selected);
        // Now you can get the text or whatever you want from the "selected" radio button
        String gender = (String) b.getText();

        String age = mAge.getText().toString();
        String height = mHeight.getText().toString();
        String weight = mWeight.getText().toString();
        String type = (String) mDrinkerType.getSelectedItem();

        if (mRowId == null) {
            long id = mDbHelper.createUserProfile(username, gender, age, height, weight, type);
            if (id > 0) {
                mRowId = id;
            }
        } else {
            mDbHelper.updateUserProfile(mRowId, username, gender, age, height, weight, type);
        }
    }
}
  • 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-27T13:10:39+00:00Added an answer on May 27, 2026 at 1:10 pm

    In your Overthelimit class you set the value with the following line:

    myIntent1.putExtra(OverLimitDbAdapter.KEY_ROWID, cursor.getString(cursor.getColumnIndexOrThrow(OverLimitDbAdapter.KEY_ROWID)));
    

    This puts a String value into the intent extras. Trying to get the same value as a Long value will make you applications crash, as it does not exist as a Long value. If you instead convert the value you get from your cursor object (or gets it directly as a Long from your cursor), your application should not crash anymore. Alternatively, you can get your value from the intent extras by using getString(), not getLong().

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

Sidebar

Related Questions

I have been spending the last hours trying to figure this out and now
Im stuck, been trying to figure this out for 2 hours now. I have
I have been banging my head for hours trying to figure out why this
I've been trying to figure this out for hours. I have a DYNAMIC youtube
I have been looking around for a few hours trying to figure out how
I have been trying for hours to figure this out. I have some JSON
I have been trying for hours now to figure out this regex and it
I have been trying for hours but couldn't figure out why it doesn't show
Ok, I have been staring at this for hours trying to figure out what's
I've been struggling for several hours trying to figure out how to get this

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.