Android Studio 错误:无法翻译 setText 中的字符串文字 [英] Android Studio Error: String literal in setText cannot be translated

查看:44
本文介绍了Android Studio 错误:无法翻译 setText 中的字符串文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一个应用程序,我遇到了一些问题.

This is my first app and I'm having some trouble.

当我运行应用程序时,它崩溃了,我不知道如何解决这个错误.

When I run the app it crashes and I don't know how to fix this error.

public class MainActivity extends AppCompatActivity {\
    TextView outputBottom = (TextView)findViewById(R.id.output);

}
public void play_the_big_lie(View view) {
    the_big_lie.start();
    outputBottom.setText("ObamaCare, the big lie");
}

推荐答案

setText 中的字符串文字无法翻译

String literal in setText cannot be translated

这不是错误,您可以放心地忽略它(除非您需要在应用中进行翻译).

This is not an error and you can safely ignore it (unless you need translation in your app).

这只是 Android Studio 的一个通知,表明您应该使用字符串资源文件而不是硬编码的字符串.

It is simply a notification by Android Studio that you should be using a string resource file instead of a hard-coded string.

如果我不得不猜测问题的根源,因为您没有发布 logcat,就是这个.

If I had to guess at the source of the issue since you did not post the logcat, it is this.

你不能在 setContentView 之前使用 findViewById 因为没有视图可以查找".

You can't use findViewById before setContentView because there is no view to "find".

请尝试类似下面的代码

public class MainActivity extends AppCompatActivity {

    private TextView outputBottom;    

    protected void onCreate(Bundle b) {
        super.onCreate(b);
        setContentView(R.layout.activity_main);
        outputBottom = (TextView)findViewById(R.id.output);
    }

这篇关于Android Studio 错误:无法翻译 setText 中的字符串文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆