views:

189

answers:

4

I am going through the android hello world tutorial, and have been stuck when trying to create an XML UI. For some reason, even on a new program, in which I have made no changes to the default build, it gives the error java.lang.NullPointerException after every character I type. I can't figure out why it is doing this, as I am just trying to edit the text between the Text I want to set it to say something other than what is set by default. However, even with a fresh build, no changes, and I just try to change the text within the xml tags, it still gives the error. What do I need to do to allow it to let me type? I am using the eclips IDE and the android sdk. I was able to do the first part of the tutorial that doesn't involve XML.

A: 

Just guessing, but I suspect you are doing something like the following:

<TextView android:text="@string/hello" />

and you are editing it to

<TextView android:text="@string/helloWorld" />

without creating a reference in res/values/strings.xml .

If this is the case, go to strings.xml and edit the proper string there, for example

<string name="hello">Hello World!</string>

becomes

<string name="hello">Hello everybody!</string>
klez
I didn't edit the main.xml file at all. I also didn't edit the actual name element either. All I attempted to do was change the text between the <string name="hello"> and </string> tags. It pops up the error with each character I type.
Dusty Lew
Actually, I noticed it doesn't matter where I type in this file, it will pop up the same error no matter where I type.
Dusty Lew
A: 

Ok, I finally found the answer somewhere else, it was something wrong with how the file was created by default. I have to add the element xmlns:android as follows

<resources xmlns:android="http://schemas.android.com/apk/res/android" />
Interestingly enough, the file will work if I type it one character at a time, dismissing the pop up with each keystroke. However the new element eliminates the pop ups. I am not sure why the error would pop up, yet the program still compile and run correctly on my avd. Oh well, if you have this error add the element and it goes away

Dusty Lew
A: 

Hi Dusty I am suffering from the same problem and it been driving me nuts. I’m new to android development and am a little lost as to where you add this code could you be a little more specific. I did notice the link already in the manifest file any help would be greatly appreciated.

Scotty65
Sorry it took me so long to get back to you, but yes I can explain! At the top of string.xml, under <?xml version="1.0" encoding="utf-8"?>, you place the tag info I provided in my answer. I hope this helps!
Dusty Lew
A: 

I think in your typing contain UTF-8 not pure ASCII. You can change in eclipse by in Ecipse IDE Window> preference> Under General tab, select workspace. In text file encoding choose other, in these choose UTF-8 . It will be ok

aemon