android警报无法启动警报活动

时间:2012-06-25 14:24:57

标签: android android-emulator alarm

我是Android编程的新手,我正在尝试制作这个简单的闹钟应用程序。我编写了我的代码,编译时没有错误。该应用程序在模拟器中运行,即主要活动询问日期和时间,但是当我单击确认按钮时,它会显示消息 - “不幸的是,Timer1已停止工作。”

我的主要活动代码如下:

public void onClick(View v) {
    EditText date = (EditText) findViewById(R.id.editDate);
    EditText month = (EditText) findViewById(R.id.editMonth);
    EditText hour = (EditText) findViewById(R.id.editHour);
    EditText min = (EditText) findViewById(R.id.editMin);
    int dt = Integer.parseInt(date.getText().toString());
    int mon = Integer.parseInt(month.getText().toString());
    int hr = Integer.parseInt(hour.getText().toString());
    int mnt = Integer.parseInt(min.getText().toString());
    Intent myIntent = new Intent(MainActivity.this, AlarmActivity.class);
    pendingIntent = PendingIntent.getService(MainActivity.this, 0, myIntent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DATE, dt);
    calendar.set(Calendar.MONTH, mon);
    calendar.set(Calendar.HOUR, hr);
    calendar.set(Calendar.MINUTE, mnt);
    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}

我不明白logcat中的所有错误是什么意思,所以我发布了它们:

06-25 16:03:32.175: I/Process(566): Sending signal. PID: 566 SIG: 9
06-25 16:03:53.775: I/dalvikvm(612): threadid=3: reacting to signal 3
06-25 16:03:54.046: I/dalvikvm(612): Wrote stack traces to '/data/anr/traces.txt'
06-25 16:03:54.255: I/dalvikvm(612): threadid=3: reacting to signal 3
06-25 16:03:54.305: I/dalvikvm(612): Wrote stack traces to '/data/anr/traces.txt'
06-25 16:03:54.735: I/dalvikvm(612): threadid=3: reacting to signal 3
06-25 16:03:54.785: I/dalvikvm(612): Wrote stack traces to '/data/anr/traces.txt'
06-25 16:03:54.925: D/gralloc_goldfish(612): Emulator without GPU emulation detected.
06-25 16:05:09.605: D/AndroidRuntime(612): Shutting down VM
06-25 16:05:09.605: W/dalvikvm(612): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
06-25 16:05:09.685: E/AndroidRuntime(612): FATAL EXCEPTION: main
06-25 16:05:09.685: E/AndroidRuntime(612): java.lang.NumberFormatException: Invalid int: "android.widget.EditText@41030b40"
06-25 16:05:09.685: E/AndroidRuntime(612):  at java.lang.Integer.invalidInt(Integer.java:138)
06-25 16:05:09.685: E/AndroidRuntime(612):  at java.lang.Integer.parse(Integer.java:375)
06-25 16:05:09.685: E/AndroidRuntime(612):  at java.lang.Integer.parseInt(Integer.java:366)
06-25 16:05:09.685: E/AndroidRuntime(612):  at java.lang.Integer.parseInt(Integer.java:332)
06-25 16:05:09.685: E/AndroidRuntime(612):  at com.kapymay.tversion1.MainActivity$1.onClick(MainActivity.java:34)
06-25 16:05:09.685: E/AndroidRuntime(612):  at android.view.View.performClick(View.java:3511)
06-25 16:05:09.685: E/AndroidRuntime(612):  at android.view.View$PerformClick.run(View.java:14105)
06-25 16:05:09.685: E/AndroidRuntime(612):  at android.os.Handler.handleCallback(Handler.java:605)
06-25 16:05:09.685: E/AndroidRuntime(612):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-25 16:05:09.685: E/AndroidRuntime(612):  at android.os.Looper.loop(Looper.java:137)
06-25 16:05:09.685: E/AndroidRuntime(612):  at android.app.ActivityThread.main(ActivityThread.java:4424)
06-25 16:05:09.685: E/AndroidRuntime(612):  at java.lang.reflect.Method.invokeNative(Native Method)
06-25 16:05:09.685: E/AndroidRuntime(612):  at java.lang.reflect.Method.invoke(Method.java:511)
06-25 16:05:09.685: E/AndroidRuntime(612):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-25 16:05:09.685: E/AndroidRuntime(612):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-25 16:05:09.685: E/AndroidRuntime(612):  at dalvik.system.NativeStart.main(Native Method)
06-25 16:05:10.445: I/dalvikvm(612): threadid=3: reacting to signal 3
06-25 16:05:10.575: I/dalvikvm(612): Wrote stack traces to '/data/anr/traces.txt'

1 个答案:

答案 0 :(得分:0)

  int dt = Integer.parseInt(date.getText().toString());
                int mon = Integer.parseInt(month.getText().toString());
                int hr = Integer.parseInt(hour.getText().toString());
                int mnt = Integer.parseInt(min.getText().toString());

其中一个不能解析为整数。

查看哪一个的方法:

首先写出来:

String date = date.getText().toString();

对于所有4个做类似的

and then Log.i("YOURACTIVITNAME", "date:"+date+" hour"+.....);

OR 而不是Log.i你可以简单地插入一个断点,然后调试。并看看哪一个犯了错误。

在你的tostring之后使用.trim()删除空格也可能会很好。