4
@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();
    }
}

我正在开发一个登录activity,我想记录用户尝试登录的次数,所以每次登录尝试计数都会增加一......但是当我运行活动时,这个错误出现在我的日志猫:

android.content.res.Resources$NotFoundException: String resource ID #0x1,

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

4

2 回答 2

14

这是你的错误:

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

makeText您试图在这里调用的是作为makeText第二个参数的 a resId。请参阅此处了解更多信息。由于要打印计数值,因此必须将其转换为字符串。

String value = String.valueOf(count);
Toast.makeText(ScreenLockActivity.this, value, Toast.LENGTH_SHORT).show();
于 2012-05-18T15:40:05.690 回答
0

这条线应该在里面onClick()or compareID()

userInput = input.getText().toString();
于 2012-05-18T15:44:19.390 回答