【问题标题】:Android code throwing errorsAndroid代码抛出错误
【发布时间】:2015-08-24 12:23:50
【问题描述】:

这是一个应用程序的一些代码,它只会将 hello world 打印到我的手机上。但是,当我尝试在 Android 工作室中将文本从“@string/hello_world”更改为其他内容(例如“@string/hello”)时,它会引发错误。有人可以帮忙吗?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

【问题讨论】:

  • 你是否在strings.xml 中添加了字符串hello?转到strings.xml 中的res -&gt; values -&gt;strings.xml 打开它。在那里你找到一行&lt;string name="hello_world"&gt;Hello world!&lt;/string&gt;
  • 那是什么(我第一次用这个)
  • 如果你的意思是在这个
  • 请阅读此文档developer.android.com/samples/BasicNetworking/res/values/…developer.android.com/guide/topics/resources/… 并了解String Resources 的用途并尝试一下。它将帮助您走得更远。在 TextView 上按住 CTRL + CLICK "@string/hello_world" 将带你到 strings.xml 那里你可以创建和修改 String Resources
  • 这表示如果你想给android:text="@string/myapp",那么在strings.xml 中应该有&lt;string name="myapp"&gt;Hey, This is My App&lt;/string&gt;。所以在TextView 它显示Hey, This is My App

标签: android compiler-errors


【解决方案1】:

转到您的 res 文件夹 -> 值 -> strings.xml。

在该文件中,您可以找到字符串名称和值。

只需更改您想要的名称和值,然后在布局中给出该名称。

<string name="Hello_world">Hello World</string>

<string name="Hello">My First Application</string>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 2019-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多