• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

[Newbie]How to Split a String ?

androgaga

Newbie
Apr 8, 2013
14
0
Hi there,

Here I try to send the "message" string ("Lorem,Ipsum,Dolor,Amet") :
Code:
    public void dbInsertWords(View view) {
    	Intent intent = new Intent(this, DbInsertWords.class);
    	String message = "Lorem,Ipsum,Dolor,Amet" ;
    	intent.putExtra(EXTRA_MESSAGE, message);	
    	startActivity(intent);
    }

And here I try to fetch this "message" string :
Code:
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	Intent intent = getIntent();
	String message = intent.getStringExtra(DbInsertWords.EXTRA_MESSAGE);

        [B]String[] array = message.split(",");   <=== *** this line crashes ***
[/B]    		
        WordsBDD wordBdd = new WordsBDD(this);
        Word word = new Word(array[0], array[1], array[2], array[3]);

But it seems that "message" is not a string, or there's something wrong with it, because String[] array = message.split(","); just makes my program crash.

However I noticed that the following would not crash :
Code:
String[] array = "Lorem,Ipsum,Dolor,Amet".split(",");

Could someone please give me an advice ?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones