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、ユーザーがログインを試みた回数を記録したいので、ログインを試みるたびにカウントが1ずつ増えます...しかし、アクティビティを実行すると、このエラーがlogcat:

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

誰かが私がこの問題を解決するのを手伝ってもらえますか?

4

2 に答える 2

14

ここにあなたの間違いがあります:

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

makeTextここで呼び出そうとしているのはmakeText、2番目のパラメーターとしてaを取りますresId。詳細については、こちらをご覧ください。カウント値を出力したいので、文字列に変換する必要があります。

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

この行は内側にある必要がありますonClick()またはcompareID()

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