Java android.content.res.Resources$NotFoundException
我正在开发一个登录Java android.content.res.Resources$NotFoundException,java,android,error-handling,Java,Android,Error Handling,我正在开发一个登录活动,我想记录下用户尝试登录的次数,因此每次尝试登录时,计数都会增加一次。。。但当我运行“活动”时,此错误出现在我的日志中: android.content.res.Resources$NotFoundException:字符串资源ID#0x1 有人能帮我解决这个问题吗?这是你的错误: @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState
活动
,我想记录下用户尝试登录的次数,因此每次尝试登录时,计数都会增加一次。。。但当我运行“活动”时,此错误出现在我的日志中:
android.content.res.Resources$NotFoundException:字符串资源ID#0x1
有人能帮我解决这个问题吗?这是你的错误:
@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();
}
}
您试图在此处调用的makeText
是makeText
,它将第二个参数aresId
作为第二个参数。有关更多信息,请参阅。由于要打印计数值,必须将其转换为字符串
Toast.makeText(ScreenLockActivity.this, count, Toast.LENGTH_SHORT).show();
这是你的错误:
@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();
}
}
您试图在此处调用的makeText
是makeText
,它将第二个参数aresId
作为第二个参数。有关更多信息,请参阅。由于要打印计数值,必须将其转换为字符串
Toast.makeText(ScreenLockActivity.this, count, Toast.LENGTH_SHORT).show();
这一行应该在
onClick()
或compareID()
内:
这一行应该在
onClick()
或compareID()
内:
您在Eclipse IDE中从project Clean中清除项目后进行了尝试?在Eclipse IDE中从project Clean中清除项目后进行了尝试?在Eclipse IDE中从project Clean中清除项目后进行了尝试?@blackbelt,我面临相同的错误,那么你能告诉我如何识别错误吗line@AndroidOptimist它在堆栈跟踪中。在logcat中,当错误发生时,您将看到许多红线。你应该寻找在你的文章中指出的那个code@blackbelt,我面临同样的错误,你能告诉我如何识别错误吗line@AndroidOptimist它在堆栈跟踪中。在logcat中,当错误发生时,您将看到许多红线。你应该寻找在你的文章中指出的那个code@blackbelt,我面临同样的错误,你能告诉我如何识别错误吗line@AndroidOptimist它在堆栈跟踪中。在logcat中,当错误发生时,您将看到许多红线。您应该查找代码中指出的一个