我试图用吐司来测试我的微调器的功能。我遇到了麻烦,因为它不是烘烤 ShowTime,而是强制关闭。我的 logcat 发布在代码下方。如果有人可以帮助我阅读我的 logcat 代码并找出问题所在。提前致谢!
public class Spinner extends Activity {
Spinner bus;
String GetTime;
int ShowTime;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String[] Log_Array = new String[9];
{
Log_Array[0] = "5 min";
Log_Array[1] = "10 min";
Log_Array[2] = "30 min";
Log_Array[3] = "50 min";
Log_Array[4] = "100 min";
Log_Array[5] = "300 min";
Log_Array[6] = "400 min";
Log_Array[7] = "500 min";
Log_Array[8] = "600 min";
bus= (Spinner) findViewById(R.id.timer);
ArrayAdapter NoCoreAdapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, Log_Array);
bus.setAdapter(NoCoreAdapter);
bus.setSelection(1);
}
bus.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
GetTime = parent.getItemAtPosition(pos).toString();
if (pos == 0) {
GetTime.equals(Log_Array[0]);
ShowTime = 5;
}
if (pos == 1) {
GetTime.equals(Log_Array[1]);
ShowTime = 5;
}
if (pos == 2) {
GetTime.equals(Log_Array[2]);
ShowTime = 5;
}
if (pos == 3) {
GetTime.equals(Log_Array[3]);
ShowTime = 5;
}
if (pos == 4) {
GetTime.equals(Log_Array[4]);
ShowTime = 5;
}
if (pos == 5) {
GetTime.equals(Log_Array[5]);
ShowTime = 5;
}
if (pos == 6) {
GetTime.equals(Log_Array[6]);
ShowTime = 5;
}
if (pos == 7) {
GetTime.equals(Log_Array[7]);
ShowTime = 5;
}
if (pos == 8) {
GetTime.equals(Log_Array[8]);
ShowTime = 6;
}
Toast.makeText(getApplicationContext(), ShowTime,
Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
});
}
我的日志猫
07-01 16:12:14.348: E/AndroidRuntime(21733): FATAL EXCEPTION: main
07-01 16:12:14.348: E/AndroidRuntime(21733): android.content.res.Resources$NotFoundException: String resource ID #0x5
07-01 16:12:14.348: E/AndroidRuntime(21733): at android.content.res.Resources.getText(Resources.java:210)
07-01 16:12:14.348: E/AndroidRuntime(21733): at android.widget.Toast.makeText(Toast.java:258)
07-01 16:12:14.348: E/AndroidRuntime(21733): at com.settings.Settings$1.onItemSelected(Settings.java:88)
07-01 16:12:14.348: E/AndroidRuntime(21733): at android.widget.AdapterView.fireOnSelected(AdapterView.java:871)
07-01 16:12:14.348: E/AndroidRuntime(21733): at android.widget.AdapterView.access$200(AdapterView.java:42)
07-01 16:12:14.348: E/AndroidRuntime(21733): at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:837)
07-01 16:12:14.348: E/AndroidRuntime(21733): at android.os.Handler.handleCallback(Handler.java:587)
07-01 16:12:14.348: E/AndroidRuntime(21733): at android.os.Handler.dispatchMessage(Handler.java:92)
07-01 16:12:14.348: E/AndroidRuntime(21733): at android.os.Looper.loop(Looper.java:143)
07-01 16:12:14.348: E/AndroidRuntime(21733): at android.app.ActivityThread.main(ActivityThread.java:4196)
07-01 16:12:14.348: E/AndroidRuntime(21733): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 16:12:14.348: E/AndroidRuntime(21733): at java.lang.reflect.Method.invoke(Method.java:507)
07-01 16:12:14.348: E/AndroidRuntime(21733): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-01 16:12:14.348: E/AndroidRuntime(21733): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-01 16:12:14.348: E/AndroidRuntime(21733): at dalvik.system.NativeStart.main(Native Method)