android.content.res.Resources $ NotFoundException [英] android.content.res.Resources$NotFoundException

查看:91
本文介绍了android.content.res.Resources $ NotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Override
public void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);
    setContentView(R.layout.screenlocked);

    //Retrieve stored ID
    final String STORAGE = "Storage";  
    SharedPreferences unique = getSharedPreferences(STORAGE, 0);
    LoginID = unique.getString("identifier", "");

    //Retrieve stored phone number
    final String phoneNumber = unique.getString("PhoneNumber", "");
    phoneView = (TextView) findViewById(R.id.phone);
    phoneView.setText(phoneNumber.toString());

    //Retrieve user input
    input = (EditText) findViewById(R.id.editText1);
    userInput = input.getText().toString();

    //Set login button
    login = (Button) findViewById(R.id.login);
    login.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            compareID();
        }
    });
}

public void compareID(){

    if (userInput.equals(LoginID)){
        //phone screen unlocked
        //continue
        Toast.makeText(ScreenLockActivity.this, "Success!", Toast.LENGTH_SHORT).show();
    }
    else{
        count += 1;
        input.setText("");
        Toast.makeText(ScreenLockActivity.this, count, Toast.LENGTH_SHORT).show();
    }
}

我正在开发一个登录活动,我想记录用户尝试登录多少次,所以每次登录尝试时,计数将增加一个...但是当我运行该活动时,这个错误出现在我的logcat中:

I am developing a login activity and I would like to record down how many times the user tried to login, so every time there is a login attempt the count will increment by one... but when i run the activity, this error appears in my logcat:

android.content.res.Resources $ NotFoundException:String资源ID#0x1

有人可以帮我解决这个问题吗?

Can someone help me solve this problem?

推荐答案

错误:

Toast.makeText(ScreenLockActivity.this, count, Toast.LENGTH_SHORT).show();

makeText 您正尝试在这里调用,是 makeText ,作为第二个参数 resId 。请参阅 here 了解更多信息。因为要打印计数值,所以必须将其转换为字符串。

the makeText you are trying to invoke here, is the makeText that takes as second parameter a resId. See here for more info. Since you want to print the count value, you have to convert it in a String.

String value = String.valueOf(count);
Toast.makeText(ScreenLockActivity.this, value, Toast.LENGTH_SHORT).show();

这篇关于android.content.res.Resources $ NotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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