使用警报管理器的 numberformat 异常 - 在开始之前崩溃 [英] numberformat exception using alarmamanager - crashes before on start

查看:13
本文介绍了使用警报管理器的 numberformat 异常 - 在开始之前崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

---------更新 -----------------------------

---------UPDATE -----------------------------------------

当应用程序启动时,我在以下行收到 numberformat 异常:

When the app starts I receive numberformat exception at line :

final long thetime=Long.parseLong(time_value);

但以上内容不在主要活动中...

But the above aren't in the main activity...

在我在edittex中的xml文件中

In the xml file I have in the edittex

android:inputType="number" .

android:inputType="number" .

这一行在我有警报管理器的 myservice 类中(注意我不能使用 catch,因为在下面(alarm.setRepeating)它不能识别时间"值.

This line is in myservice class in which I have the alarmamanager(note I can't use catch because below(alarm.setRepeating) it doesn't recognize "thetime" value.

protected void onHandleIntent(Intent intent) {
        //try{
            String time_value;
            time_value=(String) intent.getStringExtra("time_value");
            final long thetime=Long.parseLong(time_value);// }
        //  catch (NumberFormatException e) {

            //}
        mContext = getApplicationContext();
        mHandler.post(new Runnable(){

            @Override
            public void run() {

                // Start service using AlarmManager
                Calendar cal = Calendar.getInstance();
                cal.add(Calendar.SECOND, 10);
                Intent intent = new Intent(myservice.this,selection.class);
                PendingIntent pintent = PendingIntent.getService(myservice.this, 0, intent,
                        0);
                AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
                        thetime*1000, pintent);
             // Tell the user about what we did.
                Toast.makeText(myservice.this, "Configured time interval",
                        Toast.LENGTH_LONG).show();

            }
        });
    }
}

我从另一个活动加载时间值:

I load the time_value from another activity:

public void onClick(View v) {
        switch (v.getId()){
        case R.id.btn:
             edit11=edit1.getText().toString();
             edit22=edit2.getText().toString();
             Intent i=new Intent(this,selection.class);
             i.putExtra("code_value",edit11);
             Intent k=new Intent(this,myservice.class);
             k.putExtra("time_value",edit22);
             this.startService(k);
             Intent l=new Intent(this,MainActivity.class);
             startActivity(l);  
             break;

     }
     }

推荐答案

好吧,我忘记了:

startService() 我的主要活动.我必须把它放在我的服务活动中.

startService() im my main activity. I had to put it in myservice activity.

谢谢大家

这篇关于使用警报管理器的 numberformat 异常 - 在开始之前崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆