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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:17:35+00:00 2026-05-27T04:17:35+00:00

i have a spinner an two buttons on my Android app, the spinner is

  • 0

i have a spinner an two buttons on my Android app,

the spinner is populated dynamicaly from server-side script.

it works last time, but i don’t know why now i’m having a java.NullPointerException problem and i don’t know how to fix it, the log from LogCat said that i’m having null on my spinner

first, this is my complete script on FormPilihLokasiKelompok.class

package com.nigmagrid.jm.demo;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class FormPilihLokasiKelompok extends Activity {

    ArrayList<String> content;
    ArrayAdapter<String> content_adapter;
    Button btn_save, btn_back;
    Context context;
    String selected_value, spinner_prompt, toast_failed, url_retrieval;
    Spinner spinner;

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

        btn_save = (Button) findViewById(R.id.btn_save);
        btn_back = (Button) findViewById(R.id.btn_back);
        spinner = (Spinner) findViewById(R.id.spinner);

        context = FormPilihLokasiKelompok.this;

        selected_value = "";
        spinner_prompt = "Pilih Lokasi";
        toast_failed = "Tidak ada lokasi yang terpilih";

        url_retrieval = VarsUrl.getServerAddress()+"get_list.php?table=kelompok_lokasi";

        content = new ArrayList<String>();

        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                finish();
            }
        });

        btn_save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(selected_value.length() > 1){
                    Intent intent = new Intent(getApplicationContext(), FormPilihLokasiKm.class);
                    intent.putExtra("content", selected_value);
                    startActivity(intent);
                }else{
                    Toast.makeText(getApplicationContext(), toast_failed, Toast.LENGTH_SHORT).show();
                }
            }
        });

        spinner.setPrompt(spinner_prompt);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                String sel_val = spinner.getSelectedItem().toString();
                if(sel_val != null || sel_val.length() > 0){
                    selected_value = spinner.getSelectedItem().toString();
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // do nothing
            }

        });

        new PopulateSpinner().execute(url_retrieval);

    }

    protected class PopulateSpinner extends AsyncTask<String, Void, String>{

        ProgressDialog pd = new ProgressDialog(context);

        protected void onPreExecute(){
            pd.setMessage("Mengambil data...");
        }

        @Override
        protected String doInBackground(String... arg0) {
            try{
                String response = CustomHttpClient.excecuteHttpGet(arg0[0]);
                String res = response.toString().trim();
                return res;             
            }catch (Exception e){
                return e.toString();
            }
        }

        protected void onPostExecute(String res){
            String[] datanya = res.split("#", 0);
            int jumlah_data = datanya.length;
            if(datanya[0].equals("1")){
                try{
                    content.clear();
                    for(int i = 1; i < jumlah_data; i++){
                        content.add(datanya[i]);
                    }

                    content_adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, content);
                    content_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    spinner.setAdapter(content_adapter);

                }catch(Exception e){
                    Toast.makeText(getApplicationContext(), "Terjadi kesalahan sistem\n"+e.toString(), Toast.LENGTH_SHORT).show();
                }
            }else{
                content.add("Tidak ada data untuk ditampilkan");                
            }

            content_adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, content);
            content_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(content_adapter);

            pd.dismiss();
        }
    }

}

Here’s the Log

11-23 12:49:57.179: W/dalvikvm(22610): threadid=1: thread exiting with uncaught exception (group=0x40015578)
11-23 12:49:57.187: E/AndroidRuntime(22610): FATAL EXCEPTION: main
11-23 12:49:57.187: E/AndroidRuntime(22610): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nigmagrid.jm.demo/com.nigmagrid.jm.demo.FormPilihLokasiKelompok}: java.lang.NullPointerException
11-23 12:49:57.187: E/AndroidRuntime(22610):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at android.os.Looper.loop(Looper.java:123)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at android.app.ActivityThread.main(ActivityThread.java:3687)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at java.lang.reflect.Method.invokeNative(Native Method)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at java.lang.reflect.Method.invoke(Method.java:507)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at dalvik.system.NativeStart.main(Native Method)
11-23 12:49:57.187: E/AndroidRuntime(22610): Caused by: java.lang.NullPointerException
11-23 12:49:57.187: E/AndroidRuntime(22610):    at com.nigmagrid.jm.demo.FormPilihLokasiKelompok.onCreate(FormPilihLokasiKelompok.java:68)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-23 12:49:57.187: E/AndroidRuntime(22610):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
11-23 12:49:57.187: E/AndroidRuntime(22610):    ... 11 more

this script was on line 68 : spinner.setPrompt(spinner_prompt);

i’ve change the spinner_prompt to normal string like “test prompt” but it’s still same
so it must be the spinner (cmiiw) and i don’t know where i should fix it.

anybody knows how to fix it?
thanks

update
here’s my layout

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TextView 
            android:text="Lokasi"
            android:padding="5dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <Spinner
            android:id="@+id/spinner"
            android:padding="5dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <Button
            android:id="@+id/btn_save"
            android:text="Lanjutkan"
            android:padding="5dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/btn_back"
            android:text="Kembali"
            android:padding="5dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>
</ScrollView>
  • 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-27T04:17:36+00:00Added an answer on May 27, 2026 at 4:17 am

    perhaps you may need to regenerate your R.java file… using eclipse, go to “Project -> Clean” and select your project. Then build your project again. maybe you even need to restart eclipse during those steps.

    I’ve had this issue happen when it was working just fine before and suddenly stopped working after i did some un-related thing.

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

Sidebar

Related Questions

I have an android spinner that's populated by a list of strings using an
Hello I have question about android spinner I have spinner which is populated by
Hello I have question about android spinner I have spinner which is populated by
I have a problem on Android Spinner.In my application I created two Spinner on
I have been slowing learning and building my first android app. I'm VERY new
I have a custom spinner that uses two custom views, one for the drop
I have 2 spinner, each spinner's data loaded from database using AsyncTask i call
I am a newbie to Android programming. I want two radio buttons that when
I have two spinners in an activity, A and B. Each spinner uses an
Alright so i have been working on this Dynamic load of a spinner from

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.