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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:38:50+00:00 2026-06-17T16:38:50+00:00

After sorting out my code I keep getting a null on my second screen

  • 0

After sorting out my code I keep getting a null on my second screen when i hit the submit button having trouble spotting my mistake any help would be appreciated.

first class

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Spinner;

public class IwiSelect extends Activity {

Spinner spinner1, spinner2, spinner3, spinner4, spinner5;
Button btnSubmit; 
String iwi1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_iwiselect);

    addListenerOnButton();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_iwi_select, menu);
    return true;
}




// get the selected drop down list value
  public void addListenerOnButton() {

    spinner1 = (Spinner) findViewById(R.id.spinner1);
    spinner2 = (Spinner) findViewById(R.id.spinner2);
    spinner3 = (Spinner) findViewById(R.id.spinner3);
    spinner4 = (Spinner) findViewById(R.id.spinner4);
    spinner5 = (Spinner) findViewById(R.id.spinner5);

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

    btnSubmit.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {

            String text = spinner1.getSelectedItem().toString();
            //Starting a new Intent
            Intent intent = new Intent();
            intent.putExtra("spinnerText", text);
            Intent nextScreen = new Intent(IwiSelect.this, SecondScreenActivity.class);

            //Sending data to another Activity
            nextScreen.putExtra("USERNAME", iwi1);
            //nextScreen.putExtra(spinner2.getContext().toString(), false);





            // starting new activity
            startActivity(nextScreen);




}
    });

  }
  }

this first class the user selects from a spinner (will have 5 spinners in total)

second class

public class SecondScreenActivity extends Activity {

TextView FirstIwi;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.selected_iwi);





    FirstIwi = (TextView) findViewById(R.id.textView1);

     Intent intent = getIntent();


    String text = intent.getStringExtra("spinnerText");
    //Spinner spinnername2 = (Spinner) findViewById(R.id.spinner2);



    FirstIwi.setText("First Iwi  " + text);


}

}

this activity is for selecting an option from a spinner

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".IwiSelect" >

 <Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:entries="@array/IwiList"
    android:prompt="@string/Iwi_prompt" />

 <Spinner
 android:id="@+id/spinner4"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignBottom="@+id/spinner5"
 android:layout_alignParentLeft="true"
 android:layout_marginBottom="70dp"
 android:entries="@array/IwiList"
 android:prompt="@string/Iwi_prompt" />

 <Spinner
 android:id="@+id/spinner3"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_below="@+id/spinner5"
 android:layout_marginTop="24dp"
 android:entries="@array/IwiList"
 android:prompt="@string/Iwi_prompt" />

 <Spinner
 android:id="@+id/spinner5"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_below="@+id/spinner1"
 android:layout_marginTop="90dp"
 android:entries="@array/IwiList"
 android:prompt="@string/Iwi_prompt" />

 <Spinner
 android:id="@+id/spinner2"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_below="@+id/spinner3"
 android:layout_marginTop="14dp"
 android:entries="@array/IwiList"
 android:prompt="@string/Iwi_prompt" />

 <Button
 android:id="@+id/btnSubmit"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentBottom="true"
 android:layout_centerHorizontal="true"
 android:onClick="onClick"
 android:text="Submit" />

</RelativeLayout>

and this activity is for displaying the selected options

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".IwiSelect" >

 <TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="TEXT"/>



</RelativeLayout>
  • 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-17T16:38:51+00:00Added an answer on June 17, 2026 at 4:38 pm

    You do this:

    nextScreen.putExtra("USERNAME", iwi1);
    

    Then start the second Activity using the nextScreen Intent. You never use the intent Intent, which has the "spinnerText" key.

    Then, when you get the extra in the second Activity, you are doing

    String text = intent.getStringExtra("spinnerText");
    

    Which references a non-existent key for the intent (nextScreen), and so, text will be null. On screen you most likely see First Iwi null.

    Consider changing it to:

    String text = intent.getStringExtra("USERNAME"); 
    

    instead.

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

Sidebar

Related Questions

i am having trouble finding out problem in my jtable sorting mechanism ,when ever
I am trying to use MPI to sort digits, after sorting by the different
After following the RoR getting started tutorial, I added another model as: $ rails
After I click update in the grid view, the code works successfully. But when
I am trying to figure out how to code in a clean way the
Setup I have a piece of code that is sorting a DataGridView using a
UPDATE - New code at the bottom I'm trying to figure out how to
I've just been sorting out some memory leaks in my WPF application. To do
I have a requirement where I need to filter out the null values from
I have the following code for sorting. Can this be improved? import java.util.*; class

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.