关于Android中的致命意外 [英] about FATAL EXCEPTION in Android

查看:52
本文介绍了关于Android中的致命意外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生
我是Android上的新手,现在在发送和接收短信方面遇到问题.实际上,我在项目名称ZigbeeActivity,SettingActivity,OnOffActivity等中分别有5个Activity类,现在我想发送一个SMS,这是一个单独的类SendSMS和SMSReceiver类从SettingActivit编写并调用一个函数到SendSMSclass的SMSsend,但是在发送致命异常时会在Settingctiviy屏幕上显示.我将SendSMS类的源代码绑定在pl下方.帮帮我.

hi sir
I am new on Android and I am now being face a problem in sms sending and receiving Actually I have 5 Activity class in project name ZigbeeActivity,SettingActivity,OnOffActivity etc each and a seprate class SendSMS and SMSReceiver Class now I wish to send a sms which compose from SettingActivit and call a function to SMSsend of SendSMSclass but when sending the Fatal Exception is shown on Settingctiviy screen.I have tied the source code of SendSMS class below pl. help me.

package com.sms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import android.app.PendingIntent;
import android.telephony.SmsManager;
import android.widget.Toast;
import android.app.Activity;
public class SendSMS extends Activity{
	private Object obj;
	public SendSMS(Object object){
		this.obj = object;
		}
	  //---sends an SMS message to another device---
	@SuppressWarnings("unused")
	public void sendSMS(String phoneNumber, String message)
    { 
		try{
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";
 
        PendingIntent sentPI = PendingIntent.getActivity(this, 0, new Intent(this,obj.getClass()), 0);
 
        PendingIntent deliveredPI = PendingIntent.getActivity(this, 0, new Intent(this,obj.getClass()), 0);
 
        //---when the SMS has been sent---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS sent", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off", 
                                Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        }, new IntentFilter(SENT));
 
        //---when the SMS has been delivered---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case Activity.RESULT_CANCELED:
                        Toast.makeText(getBaseContext(), "SMS not delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;                        
                }
            }
        }, new IntentFilter(DELIVERED));        
 
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);        
  
    }catch(Exception e){
    	Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
    }

}


感谢n问候
Om Parkash


thanks n regards
Om Parkash

推荐答案

您有一个

@SuppressWarnings("unused")

在其中-因此我假设该函数从未使用过,并且您不会在IDE中看到该消息,因为由于此注释而未显示警告,但是当您删除它时,您会发现有问题,然后您会发现FatalException弹出的位置. * takeAdeepBreath(); *
You have an

@SuppressWarnings("unused")

in there - so I assume the function is never used and you do not see that in the IDE as the warning doesn''t show up due to this annotation but when you would delete that you would find out that there is something wrong and then you would find out where the FatalException pops. *takeAdeepBreath();*


这篇关于关于Android中的致命意外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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