Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法解析资源android eclipse_Android_Eclipse - Fatal编程技术网

无法解析资源android eclipse

无法解析资源android eclipse,android,eclipse,Android,Eclipse,我是安道尔发展的新手。 我已经创建了我的android第一个项目根据 这是我在创建项目时使用的代码(我没有对代码进行任何更改) 这是图形布局的屏幕截图 现在看起来不错,但是如果我想将文本Hello world更改为,比如说,Hello,那么代码部分看起来像android:text=“@string/Hello”,我会得到错误 注意:此项目包含资源错误,因此aapt未成功,这可能导致渲染失败。首先解决资源问题。 及 无法解析resource@string/hello,图形布局中的文本变为 @

我是安道尔发展的新手。 我已经创建了我的android第一个项目根据

这是我在创建项目时使用的代码(我没有对代码进行任何更改)


这是图形布局的屏幕截图

现在看起来不错,但是如果我想将文本
Hello world
更改为,比如说,
Hello
,那么代码部分看起来像
android:text=“@string/Hello”
,我会得到错误

注意:此项目包含资源错误,因此aapt未成功,这可能导致渲染失败。首先解决资源问题。

无法解析resource@string/hello
,图形布局中的文本变为
@string/hello
,如图所示

但我注意到一件事: 如果在此错误之后,我转到
res/values/strings.xml
并添加带有名称和值的
String
,如

错误消失,我可以在图形布局中看到单词
hello

我已经试过了

  • 像这里描述的那样使用
    ctrl+shift+s
  • 关闭并重新打开Eclipse
  • 清洗、再灌注
  • 删除整个项目并重新创建
  • values
    文件夹确实存在于
    res

    这些问题都没有解决我的问题

    已更新 如果我这样写,android:text=“hello” 我在eclipse中得到这个警告
    硬编码字符串“hello”,应使用@string resource

    我并不是每次想使用诸如android:text=“@string/hello2”之类的字符串时都能得到它,我必须首先在
    strings.xml

    中手动指定
    hello2

    android:text="hello"
    
    @string位表示它是xml中名为
    hello
    的资源

    因此,如果愿意,还可以将资源添加到xml中。众所周知,这是更好的国际化实践。

    您可以使用

    android:text="hello"
    
    @string位表示它是xml中名为
    hello
    的资源


    因此,如果愿意,还可以将资源添加到xml中。众所周知,这是一种更好的国际化实践。

    在res/values/strings.xml中

          <string name="hello">Hello</string>
    
                     or
    
    我想你没有类似的东西。因此,您将获得resource not found异常,因为该资源未在strings.xml中定义

          <string name="hello">Hello</string>
    
                     or
    
    你可以做如下的事情

           <string name="hello_world">hello</string> // change the string in strings.xml      
           android:text="@string/hello_world"  
    
    hello//更改strings.xml中的字符串
    android:text=“@string/hello\u world”
    
    对于评论中的问题


    在res/values/strings.xml中

          <string name="hello">Hello</string>
    
                     or
    
    我想你没有类似的东西。因此,您将获得resource not found异常,因为该资源未在strings.xml中定义

          <string name="hello">Hello</string>
    
                     or
    
    你可以做如下的事情

           <string name="hello_world">hello</string> // change the string in strings.xml      
           android:text="@string/hello_world"  
    
    hello//更改strings.xml中的字符串
    android:text=“@string/hello\u world”
    
    对于评论中的问题



    您应该在strings中输入字符串hello.xml谢谢您的回答,我更新了问题,这是一个lint警告您使用了harcoded字符串。是的,您需要在strings.xml中为您引用的字符串创建一个条目。就像whateverilikeok一样,谢谢@Raghunandan,关于我在eclipse中得到的警告,那么什么是正确的或首选的方法,只需使用
    android:text=“hello”
    ,或者
    android:text=“@string/hello”
    ,并在
    strings.xml
    中指定它。第二种方法是首选方法。皮棉只是警告你。在strings.xml中指定不是错误。您应该在strings.xml中输入字符串hello。谢谢您的回答,我更新了问题,这是一个lint警告您使用了harcoded字符串。是的,您需要在strings.xml中为您引用的字符串创建一个条目。就像whateverilikeok一样,谢谢@Raghunandan,关于我在eclipse中得到的警告,那么什么是正确的或首选的方法,只需使用
    android:text=“hello”
    ,或者
    android:text=“@string/hello”
    ,并在
    strings.xml
    中指定它。第二种方法是首选方法。皮棉只是警告你。在strings.xml中指定不是一个错误。谢谢,还有一个问题,使用
    android:text=“@string/hello”
    ,而不是
    android:text=“hello”
    ,我的意思是,也许将来更容易进行更改,或者可能更具动态性,那么为什么它是首选方法呢?假设您希望在所有文本视图中使用字符串。然后,您将不得不到处硬编码。相反,您可以在strings.xml中创建一个条目,并多次引用同一字符串。那是首选的方式。这正是lint警告您相同的原因。我想我明白了,所以如果我想在所有文本视图中更改它,我只会在
    strings.xml
    中进行更改,对吗?是的,您是对的。您还可以使用android框架中的字符串资源。就像您希望按钮中的ok按钮一样,您可以使用android:text=“@android:string/ok”避免重复。不用使用自己的ok字符串,您可以使用Framework中定义的ok字符串,明白了,非常感谢您的帮助和时间,我非常感谢。再次感谢!!谢谢,还有一个问题,使用
    android:text=“@string/hello”
    ,而不是
    android:text=“hello”
    ,有什么更好的地方,我的意思是,也许将来更容易进行更改,或者它更具动态性,那么为什么它是首选方式呢?假设您希望在所有文本视图中使用字符串。然后,您将不得不到处硬编码。相反,您可以在strings.xml中创建一个条目,并多次引用同一字符串。那是首选的方式。这正是lint警告您相同的原因。我想我明白了,所以如果我想在所有文本视图中更改它,我只会在
    strings.xml
    中进行更改,对吗?是的,您是ri