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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:09:26+00:00 2026-06-01T06:09:26+00:00

I managed to successfully reload certain settings when the user presses the back button

  • 0

I managed to successfully reload certain settings when the user presses the back button on the phone. When this happens I store their location and the first element in a list. Now the list is generated by pressing an image button. Once the list is generated you can press on any element and it will load a new class.

But when I recall the information from the list and press on it the app crashes giving me a
Null Pointer Exception. I’m aware of what this is but can’t understand why. Here is my code:

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

    // Initialize location
    user_lat_Value = (TextView)findViewById( R.id.lat_Value );
    user_long_Value = (TextView)findViewById( R.id.long_Value );

    // Have not received coordinates yet
    gotCoord = false;

    adapter = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, listItems );
    setListAdapter( adapter );

    SharedPreferences settings = getSharedPreferences( PREFS_NAME,0 );

    if( settings.contains( "ARRAY_LIST_VALUE_0" ) || settings.contains( "LAT" ) )
    {
        user_lat_Value.setText( settings.getString( "LAT", myNewLat ) );
        user_long_Value.setText( settings.getString( "LONG", myNewLon ) );

        listItems.add( settings.getString( "ARRAY_LIST_VALUE_0",tempStore ) );
        adapter.notifyDataSetChanged();
    }

    reload = (Button)findViewById( R.id.reloadTen );
    reload.setOnClickListener( this );

    list = getListView();
    list.setOnItemClickListener( new OnItemClickListener() 
    {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id ) 
        {
            // Start an activity based on what list view item is pressed
            Intent intent = new Intent( newSightings.this, newCompass.class );

            // Pass the data we retrieved to the next activity
            intent.putExtra( "info",data[position]  );
            startActivity( intent );
        }

    });
    list.setTextFilterEnabled( true );  
}

@Override
protected void onStop() 
{
    super.onStop();

    gotCoord = false;

    SharedPreferences settings = getSharedPreferences( PREFS_NAME,0 );
    SharedPreferences.Editor editor = settings.edit();

    // Store the latitude and longitude values and then reload them if known
    editor.putString( "LAT",myNewLat );
    editor.putString( "LONG",myNewLon );

    // Place first element of array list in storage
    if( adapter.getCount() > 0 )
    {
        Toast.makeText( getApplicationContext(), "Leaving Activity, Adapter Size: "+ adapter.getCount()+"\nStoring: "+listItems.get( 0 ).toString(), Toast.LENGTH_SHORT ).show();
        tempStore = listItems.get( 0 ).toString();

        editor.putString( "ARRAY_LIST_VALUE_0",tempStore );

        /**
        for( int i = 0; i < storeList.length; i++ )
        {
            storeList[i] = listItems.get( i ).toString();
            editor.putString( "ARRAY_LIST_VALUE_"+i, listItems.get( i ).toString() );
        }       
        */
    }
    editor.commit();

}

Correct me if I am wrong but because I reload the data into the list adapter and press it shouldn’t it mimic the behaviour of an item in the list if it had just been loaded?

I’m confused..Any words?

Cheers

  • 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-01T06:09:27+00:00Added an answer on June 1, 2026 at 6:09 am

    Based on your comment, it seems that the data variable is null and therefore data[position] throws an exception. Presumably this is data related to the adapter position but not something that is getting reloaded in your onCreate().

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

Sidebar

Related Questions

I have successfully managed to get System.Speech.Synthesis to read English text in arbitrary voices
Have anyone successfully managed to setup a combined Java/C++ project for Eclipse? What I
I've successfully managed to connect to Apple's feedback APNS server but I'm not sure
I have managed to successfully deploy my Symfony2 application to a production web server,
In my application,I successfully managed to encode/decode H264 video and Speex audio using libavcodec
I am trying to use the Google Map API- I've successfully managed to add
I'm building WP7 application using DropNet. I have successfully managed to log in and
I have successfully implemented interop beftween Win32 application and managed .Net dll as described
After much fiddling, I've managed to install the right ODBC driver and have successfully
I've managed to plug away through the YouTube documentation, and have managed to successfully

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.