convert String to CharSequence or char[] in Java (Android 1.6 API)
<p>i've got a String that i need to convert to a CharSequence.  the data MUST necessarily be a String, as it's returned from:</p>

<pre><code>String ip = pref.getString("ip", "0.0.0.0");
</code></pre>

<p>which grabs a user preference String.  the data needs to be passed to any of these functions:</p>

<pre><code>final void setText(int resid)
final void setText(int resid, TextView.BufferType type)
final void setText(char[] text, int start, int len)
void setText(CharSequence text, TextView.BufferType type)
final void setText(CharSequence text)
</code></pre>

<p>i tried using the bottom function first, but you can't pass it a String (even though String implements CharSequence).  it'll compile but it crashes.  casting it to a CharSequence in the function call like this doesn't work either:</p>

<pre><code>ipIn.setText((CharSequence)ip);
</code></pre>

<p>then i tried using the array version by calling:</p>

<pre><code>ipIn.setText(ip.toCharArray(), 0, ip.toCharArray().length-1);
</code></pre>

<p>still crashes.  here's the output from 'adb logcat':</p>

<pre><code>E/AndroidRuntime(16642): FATAL EXCEPTION: main

E/AndroidRuntime(16642): java.lang.NullPointerException

E/AndroidRuntime(16642):    at com.conceptualsystems.android4api.sms.smsMobile.onCreateDialog(smsMobile.java:81)

E/AndroidRuntime(16642):    at android.app.Activity.onCreateDialog(Activity.java:2472)

E/AndroidRuntime(16642):    at android.app.Activity.createDialog(Activity.java:881)

E/AndroidRuntime(16642):    at android.app.Activity.showDialog(Activity.java:2547)

E/AndroidRuntime(16642):    at android.app.Activity.showDialog(Activity.java:2514)

E/AndroidRuntime(16642):    at com.conceptualsystems.android4api.sms.smsMobile.onOptionsItemSelected(smsMobile.java:120)

E/AndroidRuntime(16642):    at android.app.Activity.onMenuItemSelected(Activity.java:2195)

E/AndroidRuntime(16642):    at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)

E/AndroidRuntime(16642):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)

E/AndroidRuntime(16642):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)

E/AndroidRuntime(16642):    at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)

E/AndroidRuntime(16642):    at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)

E/AndroidRuntime(16642):    at android.view.View$PerformClick.run(View.java:8816)

E/AndroidRuntime(16642):    at android.os.Handler.handleCallback(Handler.java:587)

E/AndroidRuntime(16642):    at android.os.Handler.dispatchMessage(Handler.java:92)

E/AndroidRuntime(16642):    at android.os.Looper.loop(Looper.java:123)

E/AndroidRuntime(16642):    at android.app.ActivityThread.main(ActivityThread.java:4627)

E/AndroidRuntime(16642):    at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime(16642):    at java.lang.reflect.Method.invoke(Method.java:521)

E/AndroidRuntime(16642):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

E/AndroidRuntime(16642):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

E/AndroidRuntime(16642):    at dalvik.system.NativeStart.main(Native Method)

W/ActivityManager( 1099):   Force finishing activity
</code></pre>

<p>what's interesting is that it crashes when AlertDialog.Builder.setView(View) is called if i set the text first, but crashes on setText if i call it after setView.  here's some code to put things into context:</p>

<pre><code>final View dialogLayout = inflater.inflate(R.layout.dialog_wifi_pref, null);
builder = new AlertDialog.Builder(this);
builder.setView(dialogLayout);
builder.setTitle(R.string.opt_ip_config);
String ip = pref.getString("ip", "0.0.0.0");
String port = pref.getString("port", "3005");
EditText ipIn = (EditText)findViewById(R.id.wifi_ip_in);
EditText portIn = (EditText)findViewById(R.id.wifi_port_in);
//ipIn.setText(ip.toCharArray(), 0, ip.toCharArray().length-1);
//portIn.setText((CharSequence)port.toString());
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        // change to sqlite /////
        /////////////////////////
        //nothing here yet
        dialog.dismiss();
    }
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        dialog.cancel();
    }
});
dialog = builder.create();
</code></pre>

<p>this is all part of the onCreateDialog override and exists inside a case statement.  'dialog', 'inflater', and 'builder' are defined above (properly).  and like i said, the error changes depending on whether call setView or setText first.  i'm not sure which one i'm actually supposed to do first.</p>

<p>the bottom line: i have to get a String into this EditText box.  how does i?</p>
