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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:20:45+00:00 2026-06-18T10:20:45+00:00

I have this code: public class SentSMSActivity extends Activity { private Button btnSend; private

  • 0

I have this code:

public class SentSMSActivity extends Activity {

    private Button btnSend;
    private EditText etPlain, etCipher, etDest, key2;
    private String plaintext, tempCipher = null, ciphertext = "";
    private int keyRF, keyCaesar;
    private CheckBox cbEncrypt;
    private String dest, msgSend;
    private Spinner sp;
    private String numbers[];
    private ArrayAdapter<String> adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sentsms_activity);
        btnSend = (Button) findViewById(R.id.btnSent);
        etPlain = (EditText) findViewById(R.id.etPlainSent);
        etDest = (EditText) findViewById(R.id.etDestSent);
        key2 = (EditText) findViewById(R.id.etKey2Sent);
        cbEncrypt = (CheckBox) findViewById(R.id.cbEnc);
        sp = (Spinner) findViewById(R.id.spKey1);
        //      String numbers[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
        //              "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
        //              "20", "21", "22", "23", "24", "25" };

        key2.setEnabled(false);
        keyRF = 2;

        final TextWatcher textWatcher = new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i,
                    int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1,
                    int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {

                for (int k = 0; k < etPlain.length() - 1; k++) {
                    numbers[k] = String.valueOf(k);
                }
            }
        };

        //third, we must add the textWatcher to our EditText

        sp.setClickable(false);
        cbEncrypt
                .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView,
                            boolean isChecked) {
                        if (cbEncrypt.isChecked()) {
                            key2.setEnabled(true);
                            sp.setClickable(true);
                            etPlain.addTextChangedListener(textWatcher);
                            adapter = new ArrayAdapter<String>(
                                    SentSMSActivity.this,
                                    android.R.layout.simple_spinner_item,
                                    numbers);
                            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                            sp.setAdapter(adapter);
                        } else {
                            key2.setText("");
                            key2.setEnabled(false);
                            sp.setClickable(false);
                        }
                    }
                });
    }
}

Which is supposed to make a spinner with numbers from the edittext string, however when run it give an error like this:

02-06 20:02:21.205: E/AndroidRuntime(513): FATAL EXCEPTION: main
02-06 20:02:21.205: E/AndroidRuntime(513): java.lang.NullPointerException
02-06 20:02:21.205: E/AndroidRuntime(513):  at java.util.Arrays$ArrayList.<init>(Arrays.java:47)
02-06 20:02:21.205: E/AndroidRuntime(513):  at java.util.Arrays.asList(Arrays.java:169)
02-06 20:02:21.205: E/AndroidRuntime(513):  at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:125)
02-06 20:02:21.205: E/AndroidRuntime(513):  at com.hery.androidkripto.SentSMSActivity$2.onCheckedChanged(SentSMSActivity.java:97)
02-06 20:02:21.205: E/AndroidRuntime(513):  at android.widget.CompoundButton.setChecked(CompoundButton.java:124)
02-06 20:02:21.205: E/AndroidRuntime(513):  at android.widget.CompoundButton.toggle(CompoundButton.java:86)
02-06 20:02:21.205: E/AndroidRuntime(513):  at android.widget.CompoundButton.performClick(CompoundButton.java:98)
02-06 20:02:21.205: E/AndroidRuntime(513):  at android.view.View$PerformClick.run(View.java:9080)
02-06 20:02:21.205: E/AndroidRuntime(513):  at android.os.Handler.handleCallback(Handler.java:587)
02-06 20:02:21.205: E/AndroidRuntime(513):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-06 20:02:21.205: E/AndroidRuntime(513):  at android.os.Looper.loop(Looper.java:123)
02-06 20:02:21.205: E/AndroidRuntime(513):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-06 20:02:21.205: E/AndroidRuntime(513):  at java.lang.reflect.Method.invokeNative(Native Method)
02-06 20:02:21.205: E/AndroidRuntime(513):  at java.lang.reflect.Method.invoke(Method.java:507)
02-06 20:02:21.205: E/AndroidRuntime(513):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-06 20:02:21.205: E/AndroidRuntime(513):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-06 20:02:21.205: E/AndroidRuntime(513):  at dalvik.system.NativeStart.main(Native Method)

I’m very confused with the error and have been trying to solve it for 3 hours with no progress, so I hope some members can give me a solution.

Problem: spinner with numbers item from the edittext string length

Answer thanks to user vetal-lebed:

public class MyActivity extends Activity {
private ArrayList <String> list = new ArrayList<String>();
private EditText et;
private Spinner spinner;
private ArrayAdapter<String> adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    spinner = (Spinner)findViewById(R.id.spinner);
    et = (EditText)findViewById(R.id.et);
    et.addTextChangedListener(watcher);
    adapter = new ArrayAdapter<String>(MyActivity.this,android.R.layout.simple_spinner_item, list);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
}


private TextWatcher watcher = new TextWatcher() {
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
    public void onTextChanged(CharSequence s, int start, int before, int count) {}

    public void afterTextChanged(Editable s) {
        for (int i = 0; i < s.length(); i ++){
            list.add(String.valueOf(s.charAt(i)));
            adapter.notifyDataSetChanged();
        }
    }
};

}

and thanks to other member aswell

  • 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-18T10:20:47+00:00Added an answer on June 18, 2026 at 10:20 am

    Because you didn’t allocate memory for your array “numbers”. You should do following :

    numbers = new String[0];
    

    And in your afterTextChanged() method you should create new Array with needed length (You can take it from editable). And then you can initialize all of elements of array and call notifyDataSetChanged() from adapter.

    UPD

    public class MyActivity extends Activity {
    private ArrayList <String> list = new ArrayList<String>();
    private EditText et;
    private Spinner spinner;
    private ArrayAdapter<String> adapter;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        spinner = (Spinner)findViewById(R.id.spinner);
        et = (EditText)findViewById(R.id.et);
        et.addTextChangedListener(watcher);
        adapter = new ArrayAdapter<String>(MyActivity.this,android.R.layout.simple_spinner_item, list);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
    }
    
    
    private TextWatcher watcher = new TextWatcher() {
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
        public void onTextChanged(CharSequence s, int start, int before, int count) {}
    
        public void afterTextChanged(Editable s) {
            for (int i = 0; i < s.length(); i ++){
                list.add(String.valueOf(s.charAt(i)));
                adapter.notifyDataSetChanged();
            }
        }
    };
    

    }

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

Sidebar

Related Questions

I have this code: public class VoiceActivity extends Activity implements OnClickListener { private TextView
I have this code public class MainActivity extends Activity { private static final int
I have this code: public class Register extends Activity { private LinearLayout layout; private
I have this code for my soundboard, public class soundboardActivity extends Activity { View
I have this code: public class Chronom extends Activity { Chronometer mChronometer; ProgressBar progre;
I have this code: public class cuemath extends HttpServlet{ /** * */ private static
I have this code: public class Home extends Activity{ @Override public void onCreate(Bundle savedInstanceState)
So i have this code: public class StreamingMp3Player extends Activity implements OnClickListener, OnTouchListener, OnCompletionListener,
I have this code: public class Window extends JFrame { public Window(){ ... JButton
I have this code that describes a service: public class navigation_web extends Service {

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.