Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 resource ID #0x1,

Can someone help me solve this problem?

like image 275
Android_Rookie Avatar asked Dec 09 '22 00:12

Android_Rookie


1 Answers

Here is your mistake:

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

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();
like image 71
Blackbelt Avatar answered Jan 03 '23 11:01

Blackbelt