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

  • Home
  • SEARCH
  • 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 7742691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:20:24+00:00 2026-06-01T09:20:24+00:00

I have an activity that lets the user load some data when they press

  • 0

I have an activity that lets the user load some data when they press a button. That data is passed to a list and each list item has different data stored in it. When they click on the list item it launches an intent which passes them to a new class.

But when I store the first value returned from pressing this button, i.e. using the onStop() and using SharedPreferences, and click on it I get an error. I think it may be something to do with the intent – the list item just isn’t attaching to it. Here is part of the code:

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

    list = getListView();
    list.setOnItemClickListener( this );

    if( settings.contains( "ARRAY_LIST_VALUE_0" ) )
    {
        listItems.add( 0, settings.getString( "ARRAY_LIST_VALUE_0",tempStore ) );   
        adapter.notifyDataSetChanged();
    }
    reload = (Button)findViewById( R.id.reloadTen );
    reload.setOnClickListener( this );

    // Original onItemClicked was in here
    list.setTextFilterEnabled( true );  
}


@Override
public void onItemClick(AdapterView<?> arg0, View listItem, int position, long arg3) 
{
    // 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 );
}

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

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

    if( usrPrssdBtn )
    {   
            // 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 );
                editor.putString( "DATA",data[arryTrckr] );  
            }
    }
    editor.commit();

}

So – when I run the activity and then press back, then go back to the activity the stored list item is there. Problem is when I click it it crashes the app. What’s the problem? I get a NullPointerException at this line:

intent.putExtra( "info",data[position] ); 
  • 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-01T09:20:25+00:00Added an answer on June 1, 2026 at 9:20 am

    adapter = new ArrayAdapter( this, android.R.layout.simple_list_item_1, listItems );

    in the above line you are using listitems array to sidplay the data.
    where as onItemclick event you are using

    data[position] to fetch the data according to me when you are displaying data from listitems array the you must use listitems[position] to fetch the data

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

Sidebar

Related Questions

I have an activity that lets a user upload a photo to the web
I have an activity that has a TabHost containing a set of TabSpecs each
I have an activity that contains several user editable items (an EditText field, RatingBar,
i have created a workflow activity that do give the item creater of a
I have JavaScript that is doing activity periodically. When the user is not looking
I have an application that have three activities, lets call they A, B and
Lets say you have a web app related Android app that requires the user
I have a simple user signup form with a checkbox that lets users get
I have a Activity ItemList.java . When user click on item, it starts new
I have a ListView that opens another activity when an item row is clicked

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.