Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi,

I keep getting this error while trying to convert to CharSequence[].

The method toArray(CharSequence[]) is undefined for the type String

This is my code
CharSequence[] cs = abbrev.toArray(new CharSequence[abbrev.length()]);

And

Type mismatch: cannot convert from String to CharSequence[]
CharSequence[] abbrevCS = abbrev;


The abbrev is just splitting sentences into its first characters (Hello World --> HW)


C#
String[] result = matches.toString().split("\\s+");
 // The string we'll create

 String abbrev = "";



    // Loop over the results from the string splitting
    for (int i = 0; i < result.length; i++){

        // Grab the first character of this entry
        char c = result[i].charAt(0);

        // If its a number, add the whole number
        if (c >= '0' && c <= '9'){
            abbrev += result[i];
        }

        // If its not a number, just append the character
        else{
            abbrev += c;
        }
    }



I wish to put the abbrev into a alert dialog as follows

Java
 AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
 builder2.setTitle("Make a choice from the list:");
 builder2.setCancelable(false);
 builder2.setItems(cs, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int item) {
     //


     }
 });
 AlertDialog alert2 = builder2.create();
 alert2.show();


Any ideas?
Posted
Comments
Sergey Alexandrovich Kryukov 25-Feb-15 7:25am    
Use only the defined methods... :-)
—SA

This class is not string. Please see: http://docs.oracle.com/javase/7/docs/api/java/lang/CharSequence.html[^].

As all other classes, it has toString() method…

—SA
 
Share this answer
 
See http://developer.android.com/reference/java/lang/String.html[^], the correct method is toCharArray().
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900