android - Application is not launching with FATAL EXCEPTION -
my application crashing while launching following error.
05-13 05:55:33.031: e/androidruntime(1022): fatal exception: main 05-13 05:55:33.031: e/androidruntime(1022): java.lang.runtimeexception: unable instantiate activity componentinfo{com.example.myphonecall/com.example.myphonecall.myphonecall}: java.lang.classcastexception: com.example.myphonecall.myphonecall cannot cast android.app.activity 05-13 05:55:33.031: e/androidruntime(1022): @ android.app.activitythread.performlaunchactivity(activitythread.java:2106) 05-13 05:55:33.031: e/androidruntime(1022): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 05-13 05:55:33.031: e/androidruntime(1022): @ android.app.activitythread.access$600(activitythread.java:141) 05-13 05:55:33.031: e/androidruntime(1022): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 05-13 05:55:33.031: e/androidruntime(1022): @ android.os.handler.dispatchmessage(handler.java:99) 05-13 05:55:33.031: e/androidruntime(1022): @ android.os.looper.loop(looper.java:137) 05-13 05:55:33.031: e/androidruntime(1022): @ android.app.activitythread.main(activitythread.java:5039) 05-13 05:55:33.031: e/androidruntime(1022): @ java.lang.reflect.method.invokenative(native method) 05-13 05:55:33.031: e/androidruntime(1022): @ java.lang.reflect.method.invoke(method.java:511) 05-13 05:55:33.031: e/androidruntime(1022): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-13 05:55:33.031: e/androidruntime(1022): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-13 05:55:33.031: e/androidruntime(1022): @ dalvik.system.nativestart.main(native method) 05-13 05:55:33.031: e/androidruntime(1022): caused by: java.lang.classcastexception: com.example.myphonecall.myphonecall cannot cast android.app.activity 05-13 05:55:33.031: e/androidruntime(1022): @ android.app.instrumentation.newactivity(instrumentation.java:1054) 05-13 05:55:33.031: e/androidruntime(1022): @ android.app.activitythread.performlaunchactivity(activitythread.java:2097) 05-13 05:55:33.031: e/androidruntime(1022): ... 11 more
code
myphonecall.java package com.example.myphonecall;
import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.os.bundle; import android.telephony.telephonymanager; import android.util.log; import android.widget.toast; public class myphonecall extends broadcastreceiver { @override public void onreceive(context context, intent intent) { bundle extras = intent.getextras(); if (extras != null) { string state = extras.getstring(telephonymanager.extra_state); log.w("my_debug_tag", state); if (state.equals(telephonymanager.extra_state_ringing)) { string phonenumber = extras .getstring(telephonymanager.extra_incoming_number); //log.w("my_debug_tag", phonenumber); toast.maketext(context, "getting call "+phonenumber, toast.length_long).show(); } } } }
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myphonecall" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="15" /> <uses-permission android:name="android.permission.read_phone_state" > </uses-permission> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".myphonecall" android:label="myphonecall" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <receiver android:name="myphonereceiver" > <intent-filter> <action android:name="android.intent.action.phone_state" > </action> </intent-filter> </receiver> </application> </manifest>
your myphonecall
broadcastreceiver
, declare activity
. gives error.
05-13 05:55:33.031: e/androidruntime(1022): java.lang.runtimeexception: unable instantiate activity componentinfo{com.example.myphonecall/com.example.myphonecall.myphonecall}: java.lang.classcastexception: com.example.myphonecall.myphonecall cannot cast android.app.activity
declare following way.
<receiver android:name=".myphonecall" > <intent-filter> <action ...... /> <action ..... /> </intent-filter> </receiver>
Comments
Post a Comment