android.content.res.Resources $ NotFoundException [英] 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:字符串资源编号为0x1
,
有人可以帮助我解决这个问题?
Can someone help me solve this problem?
推荐答案
下面是你的错误:
Toast.makeText(ScreenLockActivity.this, count, Toast.LENGTH_SHORT).show();
在 makeText
你是想在这里引用,是 makeText
这需要作为第二个参数渣油
。请参阅<一href="http://developer.android.com/reference/android/widget/Toast.html#makeText%28android.content.Context,%20int,%20int%29"相对=nofollow>这里获取更多信息。既然你要打印的计数值,你必须把它转换的字符串。
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屋!