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

查看:359
本文介绍了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".

请尝试类似以下代码的内容

Please try something like the following code

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天全站免登陆