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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:14:59+00:00 2026-06-17T23:14:59+00:00

I am working with android. Now i got a problem with it. I created

  • 0

I am working with android. Now i got a problem with it. I created a progrm that will get the strings from user via an alert-dialog box. And add it into the spinner. But it shows some exceptions in logcat. Please any one help me to fix this.Here is my code

**MainActivity.java**

package com.example.picker;

import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class MainActivity extends Activity {
   Button add_button;

   Editable value;
   String inserted_value;
   AlertDialog.Builder alert;
   Spinner spinner;

   /** Items entered by the user is stored in this ArrayList variable */
   ArrayList<String> list = new ArrayList<String>();

   /** Declaring an ArrayAdapter to set items to ListView */
   ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        add_button = (Button)findViewById(R.id.addbutton);
        alert = new AlertDialog.Builder(this);
        final EditText input = new EditText(this);

         /** Getting a reference to Spinner object of the resource activity_main */
        spinner = (Spinner) findViewById(R.id.spin1);

        add_button.setOnClickListener(new View.OnClickListener() {

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

                alert.setTitle("Picker");
                alert.setMessage("Enter a string...");

                // Set an EditText view to get user input 

                alert.setView(input);

                alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
if(inserted_value !=null){

                       Log.d("GOT_TEXT",inserted_value);
                       list.add(input.getText().toString());
                     }
                    else{
                        Log.d("GOT_TEXT","inserted_value is null"); 
                     }


                    /** Setting the adapter to the ListView */
                    spinner.setAdapter(adapter);

                    /** Adding radio buttons for the spinner items */
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

                  }
                });

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

                alert.show();

            }
        });

    }

    @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_main, menu);
        return true;
    }

}

logcat

    01-28 13:45:56.138: E/AndroidRuntime(701): FATAL EXCEPTION: main
01-28 13:45:56.138: E/AndroidRuntime(701): java.lang.NullPointerException
01-28 13:45:56.138: E/AndroidRuntime(701):  at com.example.picker.MainActivity$1$1.onClick(MainActivity.java:76)
01-28 13:45:56.138: E/AndroidRuntime(701):  at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
01-28 13:45:56.138: E/AndroidRuntime(701):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 13:45:56.138: E/AndroidRuntime(701):  at android.os.Looper.loop(Looper.java:123)
01-28 13:45:56.138: E/AndroidRuntime(701):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-28 13:45:56.138: E/AndroidRuntime(701):  at java.lang.reflect.Method.invokeNative(Native Method)
01-28 13:45:56.138: E/AndroidRuntime(701):  at java.lang.reflect.Method.invoke(Method.java:521)
01-28 13:45:56.138: E/AndroidRuntime(701):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-28 13:45:56.138: E/AndroidRuntime(701):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-28 13:45:56.138: E/AndroidRuntime(701):  at dalvik.system.NativeStart.main(Native Method)
  • 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-17T23:15:00+00:00Added an answer on June 17, 2026 at 11:15 pm

    try as :

    if(inserted_value !=null){
    
       Log.d("GOT_TEXT",inserted_value); 
     }
    else{
        Log.d("GOT_TEXT","inserted_value is null"); 
     }
    

    because inserted_value is NULL when you are trying to Log it

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

Sidebar

Related Questions

I am now working on changing android theme style at runtime, when the user
I have an android application and web-server working together. Now I want user log
I am working with a Google map oriented android project now i got a
I am working android application that required login, Now I want After successfully login
I'm working on android app and trying to get created_time from facebook JSON .
I'm working through some android tutorials right now in preparation for a two week
I am working on Android Application. Now I have requirement of search the entered
I am new to android development,now I am working on C2DM implementation for android
I am now working on a program for Android which is something related to
I'm having an Android GPS project for my CS class. Right now I'm working

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.