当我的应用收到短信的时候,模拟器打出的出错log如下:
java.lang.RuntimeException: Unable to instantiate receiver com.example.smschatroom.
MainActivity: java.lang.ClassCastException: com.example.smschatroom.
MainActivity cannot be cast to android.content.BroadcastReceiver是否拦截短信时必须在
public class IncomingSMSReceiver extends BroadcastReceiver
{
public void onReceive(Context _context, Intent _intent)
{
}
}如果有界面该如何处理;
java.lang.RuntimeException: Unable to instantiate receiver com.example.smschatroom.
MainActivity: java.lang.ClassCastException: com.example.smschatroom.
MainActivity cannot be cast to android.content.BroadcastReceiver是否拦截短信时必须在
public class IncomingSMSReceiver extends BroadcastReceiver
{
public void onReceive(Context _context, Intent _intent)
{
}
}如果有界面该如何处理;
解决方案 »
- PreferenceActivity修改SharedPreference问题
- Android平台下读取通讯录联系人信息,出现问题了。求英雄解释。。。
- android真机测试问题
- 安卓程序运行出错 The source attachment does not contain the source for the file
- 【求救】wincer前来投靠android了,请帮忙解答一些入门问题
- 求大神帮忙,ORIENTATION感应器 值不对,怎么校准? 有什么方法呀??
- listview 自动 删除一行 导致 getview() 重复执行
- android如何获取本地文件属性信息??
- Android下怎么把多张图片拼成一个gif啊,有没有现成的库?
- Android 2048小游戏虚拟机显示不出数字
- 我是怎么用Tabhost 实现不同的View和Activity
- Andorid 单例模式操作数据库,SQL不好使
MainActivity cannot be cast to android.content.BroadcastReceiver如果是这个类型转换错误的话,你是不是在什么地方想把MainActivity 转成BroadcastReceiver?
可以把 onReceive()部分的代码贴出来看看
<receiver android:name="com.example.smschatroom.MainActivity">
<intent-filter android:priority="800">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
删除该定义,就可以接收了,但是我没弄清楚是什么原因.