TextView Android在实际字符串下显示“null”

TextView Android在实际字符串下显示“null”,android,android-layout,Android,Android Layout,有没有任何想法,潜在的空字可能来自哪里?这只出现在某些设备上,我测试过的大多数设备都没有这个基本单词。下面是部分屏幕截图,显示了“我的布局”中“空”一词的问题: 编辑:以下是xml: <TextView android:id="@+id/day" android:layout_width="wrap_content" android:layout_height="wrap_content" android:e

有没有任何想法,潜在的空字可能来自哪里?这只出现在某些设备上,我测试过的大多数设备都没有这个基本单词。下面是部分屏幕截图,显示了“我的布局”中“空”一词的问题:

编辑:以下是xml:

        <TextView 
        android:id="@+id/day"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:text="DAY: "
        style="@style/ForecastLayout.Detail.DayTextSizeBold"/>
我对上传的屏幕图像底部的标题也做了同样的处理:

// headings
            // precip
            tv = (TextView)v.findViewById(R.id.precip_title);
            tv.setText(mContext.getApplicationContext().getResources().getString(R.string.precip).toUpperCase());

            // day
            tv = (TextView)v.findViewById(R.id.day_title);
            tv.setText(mContext.getApplicationContext().getResources().getString(R.string.day).toUpperCase());

            // night
            tv = (TextView)v.findViewById(R.id.night_title);
            tv.setText(mContext.getApplicationContext().getResources().getString(R.string.night).toUpperCase());

我没有得到空的底层。嗯?

我怀疑,因为您是直接定义文本,而不是像您应该做的那样引用资源文件,所以Android发现没有为该字段定义资源

然后它会说,哦,这个字段中没有任何内容,因此它会为用于绘制它的Spannable指定一个空值,但也会绘制文本

尝试切换到使用资源文件,看看是否有帮助。

如果要访问android:xml文件中的文本,请使用TextView.getText

因为您引用了字符串资源

R.string.day
似乎没有名为day的字符串,如果需要,可以将其添加到res/values/strings.xml中

加上这个

<string
        name="day"
        >some value </string>

它不会返回null值

我需要将变量初始化为null以外的值。我没有看到其他开发人员将该变量初始化为null。我把它改成了一个空字符串,问题就解决了

这个视图的XML是什么?我用XML和代码更新了我的帖子。谢谢我不知道你的意思…我不是已经通过资源引用过了吗?mContext.getApplicationContext.getResources…您正在XML布局文件而不是strings.XML文件中定义日期。您发布的代码与此无关,问题出现在您的TextView中:。我可以完全删除xml中的该行,但仍然存在此显示问题。我也可以使用字符串资源填充,但仍然会遇到相同的显示问题。为什么要在代码中定义布局文本?它已经是资源文件中的静态文本。您可能正在引用一个不存在的字符串。尝试按ctrl键单击R.string.day以查看它是否实际在任何地方。使用字符串资源仍然会产生相同的显示问题,并且底层为null。
<string
        name="day"
        >some value </string>
 <TextView 
    android:id="@+id/day"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:text="@string/day"
    style="@style/ForecastLayout.Detail.DayTextSizeBold"/>
buf = mContext.getApplicationContext().getResources().getString(R.string.day).toUpperCase();