So I see the NullPointer Exception as a good starting point but I'm
still perplexed.

I created a new project just for testing. And I can't get this to
work:

package com.test;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;

public class main extends Activity {
    /** Called when the activity is first created. */
    EditText justFillIn;

        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        justFillIn = (EditText) findViewById(R.id.ipText);
        justFillIn.setText("charSequence is a string");

        setContentView(R.layout.main);
    }
}

All I want to do is set the value for that EditText and it's just not
working.

Any help?

On Mar 23, 10:55 am, Lovedumplingx <[email protected]> wrote:
> I get a NullPointer Exception when I use the Debug tool.
>
> So you're saying that I haven't successfully read the View probably?
> Ok...that's a great starting point.
>
> On Mar 21, 5:55 am, Tseng <[email protected]> wrote:
>
> > An error message would be helpful.... Otherwise it's hard to help you,
> > other than "guessing" what could be the reasons for it.
>
> > Maybe you haven't set the ID correctly, using a wrong ID (which
> > doesn't even exist in the XML Layout file) or you're using
> > setContentView/setView after you have using "findViewById". This could
> > throw up a NullPointer Exception when you try to access (because
> > findViewById returns 0 if no layout has been set or the View with this
> > ID was not found).
>
> > On Mar 20, 9:00 pm, Lovedumplingx <[email protected]> wrote:
>
> > > That's what I thought too but I crash the task every time the activity
> > > that contains this code is started:
>
> > >EditTextuserText = (EditText) findViewById(R.id.userText);
> > > userText.setText(userParam);
>
> > > This is the basic way I thought to have the value set but it crashes
> > > every time.
>
> > > On Mar 19, 10:53 pm, Isaac Waller <[email protected]> wrote:
>
> > > > A String _is_ a CharSequence. There is no need for a cast.
>
> > > > On Mar 19, 3:35 pm, Will <[email protected]> wrote:
>
> > > > > Cast the String to a CharSequence.
>
> > > > > String x = "foo";
> > > > >EditTextET;
> > > > > ET.setText((CharSequence) x);
>
> > > > > On Mar 19, 10:43 am, Lovedumplingx <[email protected]> wrote:
>
> > > > > > Ok...so I've scoured and scoured and played and fiddled but I can't
> > > > > > figure it out.
>
> > > > > > I want to allow the user to set preferences for an application and I
> > > > > > want the preferences to be displayed in theEditTextarea if/when they
> > > > > > come back to change them again.
>
> > > > > > In my head I'm thinking I would be able to use setText() but 
> > > > > > no...that
> > > > > > takes a CharSequence and I have a string and don't know how to make 
> > > > > > a
> > > > > > CharSequence (which according to what I've read is supposed to be a
> > > > > > read-only thing anyway).
>
> > > > > > So...does anyone know how to put text into anEditTextfield without
> > > > > > relying on the XML?  I really want to do this via application
> > > > > > preferences.
>
> > > > > > Thanks.- Hide quoted text -
>
> > > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to