简体   繁体   English

我键入的每个字符的Android string.xml错误

[英]Android string.xml error for every character I type

I am going through the android hello world tutorial, and have been stuck when trying to create an XML UI. 我正在阅读android hello world教程,并且在尝试创建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. 由于某些原因,即使在新程序中,我也没有更改默认版本,在我键入的每个字符之后都会给出错误java.lang.NullPointerException。 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. 但是,即使使用全新的构建,也没有更改,而我只是尝试更改xml标记内的文本,它仍然会给出错误。 What do I need to do to allow it to let me type? 我需要怎么做才能让我输入? I am using the eclips IDE and the android sdk. 我正在使用eclips IDE和android sdk。 I was able to do the first part of the tutorial that doesn't involve XML. 我能够完成本教程的第一部分,该部分不涉及XML。

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 . 无需在res/values/strings.xml创建引用。

If this is the case, go to strings.xml and edit the proper string there, for example 在这种情况下,请转到strings.xml并在其中编辑适当的字符串,例如

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

becomes 变成

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

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 我必须如下添加元素xmlns:android

<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. 我不确定为什么会弹出错误,但是程序仍然可以在我的avd上编译并正确运行。 Oh well, if you have this error add the element and it goes away 哦,好吧,如果您遇到此错误,请添加该元素,它就会消失

I think in your typing contain UTF-8 not pure ASCII. 我认为您输入的内容中包含UTF-8而不是纯ASCII。 You can change in eclipse by in Ecipse IDE Window> preference> Under General tab, select workspace. 您可以通过Ecipse IDE窗口>首选项>常规选项卡下的工作区来更改eclipse。 In text file encoding choose other, in these choose UTF-8 . 在文本文件编码中选择其他,在这些中选择UTF-8。 It will be ok 一切都会安好的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM