Android : illegaljavaexception Could not execute the method for activity - android

I'm trying using intent to add class to an application. I have made SecondAcitivity class and modified the manifest file as well. My application is running i.e. First activity Containing the button works well, but onclick on button the error comes and it does not displays a second activity.
This is my MainActivity.java file
package com.intent.usingintent;
import android.os.Bundle;
import android.content.Intent;
import android.app.Activity;
import android.view.View;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View view){
startActivity(new Intent("com.intent.SecondActivity"));
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.intent.usingintent"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.intent.usingintent.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.intent.SecondActivity"
android:label="SecondActivity" >
</activity>
<intent-filter>
<action android:name=".SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</application>
</manifest>
ERROR LOG
07-09 13:57:45.922: W/dalvikvm(20185): threadid=1: thread exiting with uncaught exception (group=0x40d8e2a0)
07-09 13:57:45.932: E/AndroidRuntime(20185): FATAL EXCEPTION: main
07-09 13:57:45.932: E/AndroidRuntime(20185): java.lang.IllegalStateException: Could not execute method of the activity
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View$1.onClick(View.java:3699)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View.performClick(View.java:4223)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View$PerformClick.run(View.java:17275)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.os.Handler.handleCallback(Handler.java:615)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.os.Handler.dispatchMessage(Handler.java:92)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.os.Looper.loop(Looper.java:137)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.ActivityThread.main(ActivityThread.java:4898)
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 13:57:45.932: E/AndroidRuntime(20185): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
07-09 13:57:45.932: E/AndroidRuntime(20185): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
07-09 13:57:45.932: E/AndroidRuntime(20185): at dalvik.system.NativeStart.main(Native Method)
07-09 13:57:45.932: E/AndroidRuntime(20185): Caused by: java.lang.reflect.InvocationTargetException
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 13:57:45.932: E/AndroidRuntime(20185): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.view.View$1.onClick(View.java:3694)
07-09 13:57:45.932: E/AndroidRuntime(20185): ... 11 more
07-09 13:57:45.932: E/AndroidRuntime(20185): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.intent.SecondActivity }
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1580)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivityForResult(Activity.java:3446)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivityForResult(Activity.java:3407)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivity(Activity.java:3617)
07-09 13:57:45.932: E/AndroidRuntime(20185): at android.app.Activity.startActivity(Activity.java:3585)
07-09 13:57:45.932: E/AndroidRuntime(20185): at com.intent.usingintent.MainActivity.onClick(MainActivity.java:17)
07-09 13:57:45.932: E/AndroidRuntime(20185): ... 14 more
07-09 13:57:57.072: I/Process(20185): Sending signal. PID: 20185 SIG: 9

In your App, your second activity in com.intent.usingintent package.And your intent action is com.intent.SecondActivity,and write <intent-filter> inside <activity> tag.
So in manifest file,Change
<activity
android:name="com.intent.SecondActivity"
android:label="SecondActivity" >
</activity>
<intent-filter>
<action android:name=".SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
to
<activity
android:name="com.intent.usingintent.SecondActivity"
android:label="SecondActivity" >
<intent-filter>
<action android:name="com.intent.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

You have misplaced IntentFilter for the SecondActivity in the manifest. Put it insude <activity></activity>
Though you do no treally need that you can simply do startActivity(new Intent(this, SecondActivity.class));

in your manifest file instead of this
<activity
android:name="com.intent.SecondActivity"
android:label="SecondActivity" >
</activity>
replace with
<activity
android:name="com.intent.usingintent.SecondActivity"
android:label="SecondActivity" >
</activity>
and even in your java class also
startActivity(new Intent("com.intent.SecondActivity"));
replace this with
startActivity(new Intent("com.intent.usingintent.SecondActivity"));

change in manifest file
<activity
android:name="com.intent.usingintent.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="SecondActivity"></activity>
change in click event
Intent n=new Intent(MainActivity.this,SecondActivity.class);
startActivity(n);

Related

Starting an alarm manager application on reboot

Presently, I am working on app that sets the phone into the vibration mode or the ringer mode at the selected time. I have successfully implemented this using the alarmmanager in my application.
I want my app to remember all the pending intents when the phone is rebooted.
I found a sample code in the internet, but it seems to crash my app when the phone is rebooted. I don't know what's going wrong.
Here is alarmreciever.java
package ishan.khandelwal.vitsilentmode;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.widget.Toast;
public class AlarmReciever extends BroadcastReceiver
{
private AudioManager mAudioManager;
#Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceIntent = new Intent("ishan.khandelwal.vitsilentmode");
context.startService(serviceIntent);
}
mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
// Show the toast
Toast.makeText(context, "Vibration Mode", Toast.LENGTH_SHORT).show();
}
}
Android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ishan.khandelwal.vitsilentmode"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<!-- permission required to use Alarm Manager -->
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver
android:name=".receiver.StartMyServiceAtBootReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity
android:name="ishan.khandelwal.vitsilentmode.MainActivity"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.GetSlots"
android:label="Select your slots"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.MorningSlots"
android:label="Select your morning slots"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.EveningSlots"
android:label="Select your evening slots"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.Labs"
android:label="Select your lab slots"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.About"
android:label="About"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.AlarmReciever"
android:label="AlarmReciever" >
</activity>
<!-- Register the Alarm Receiver -->
<receiver android:name=".AlarmReciever"/>
<activity
android:name="ishan.khandelwal.vitsilentmode.RingerMode"
android:label="RingerMode" >
</activity>
<!-- Register the Alarm Receiver -->
<receiver android:name=".RingerMode"/>
</application>
Logcat:
07-23 23:33:12.057: I/ActivityManager(858): Start proc com.android.providers.calendar for broadcast com.android.providers.calendar/.CalendarReceiver: pid=1116 uid=10023 gids={3003}
07-23 23:33:12.067: I/ActivityThread(1116): Pub com.android.calendar: com.android.providers.calendar.CalendarProvider2
07-23 23:33:12.087: I/SurfaceFlinger(858): Boot is finished (2041 ms)
07-23 23:33:12.128: I/ActivityManager(858): Start proc ishan.khandelwal.vitsilentmode for broadcast ishan.khandelwal.vitsilentmode/.receiver.StartMyServiceAtBootReceiver: pid=1127 uid=10031 gids={}
07-23 23:33:12.137: D/AndroidRuntime(1127): Shutting down VM
07-23 23:33:12.137: W/dalvikvm(1127): threadid=1: thread exiting with uncaught exception (group=0xb6fac4f0)
07-23 23:33:12.137: E/AndroidRuntime(1127): FATAL EXCEPTION: main
07-23 23:33:12.137: E/AndroidRuntime(1127): java.lang.RuntimeException: Unable to instantiate receiver ishan.khandelwal.vitsilentmode.receiver.StartMyServiceAtBootReceiver: java.lang.ClassNotFoundException: ishan.khandelwal.vitsilentmode.receiver.StartMyServiceAtBootReceiver in loader dalvik.system.PathClassLoader[/data/app/ishan.khandelwal.vitsilentmode-1.apk]
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1773)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.os.Handler.dispatchMessage(Handler.java:99)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.os.Looper.loop(Looper.java:130)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-23 23:33:12.137: E/AndroidRuntime(1127): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 23:33:12.137: E/AndroidRuntime(1127): at java.lang.reflect.Method.invoke(Method.java:507)
07-23 23:33:12.137: E/AndroidRuntime(1127): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-23 23:33:12.137: E/AndroidRuntime(1127): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-23 23:33:12.137: E/AndroidRuntime(1127): at dalvik.system.NativeStart.main(Native Method)
07-23 23:33:12.137: E/AndroidRuntime(1127): Caused by: java.lang.ClassNotFoundException: ishan.khandelwal.vitsilentmode.receiver.StartMyServiceAtBootReceiver in loader dalvik.system.PathClassLoader[/data/app/ishan.khandelwal.vitsilentmode-1.apk]
07-23 23:33:12.137: E/AndroidRuntime(1127): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
07-23 23:33:12.137: E/AndroidRuntime(1127): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
07-23 23:33:12.137: E/AndroidRuntime(1127): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1764)
07-23 23:33:12.137: E/AndroidRuntime(1127): ... 10 more
Thanks for the help in advance.
Ok, the problem is that you have specified in your AndroidManifest the wrong/a nonexistent receiver implementation. You specified this:
<receiver
android:name=".receiver.StartMyServiceAtBootReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
The problem is you have no class called StartMyServiceAtBootReceiver. What you I think you should have is something like this:
<receiver
android:name=".AlarmReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>

Android app does not start in emulator or device

I have finally finished my app and everything was working fine. I went back to add in the admob stuff and now it will not start in the emulator. it says it successfully installed the app on the emulator but it does not launch and the icon is not visible to try to manually run. I think the manifest is where my error is but I am unsure.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidsleepmachine.gamble"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.WAKE_LOCK" >
</uses-permission>
<uses-permission android:name="android.permission.Internet" >
</uses-permission>
<uses-permission android:name="android.permission.Write_EXTERNAL_STORAGE" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
</uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
></activity>
<activity
android:name=".Splash"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog" >
<intent-filter>
<action android:name="com.AndroidSleepMachine.gamble.SPLASH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.AndroidSleepMachine.gamble.HOME"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".About"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog" >
<intent-filter>
<action android:name="com.AndroidSleepMachine.gamble.ABOUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.androidsleepmachine.gamble.Ship" />
<activity android:name="com.androidsleepmachine.gamble.OceanThunder" />
<activity android:name="com.androidsleepmachine.gamble.Ocean" />
<activity android:name="com.androidsleepmachine.gamble.Forest" />
<activity android:name="com.androidsleepmachine.gamble.Rain" />
<activity android:name="com.androidsleepmachine.gamble.Thunderbirds" />
<activity android:name="com.androidsleepmachine.gamble.Meditation" />
<activity android:name="com.androidsleepmachine.gamble.Focus" />
<activity android:name="com.androidsleepmachine.gamble.Pain" />
</application>
</manifest>
logcat files
09-23 13:17:47.582: E/AndroidRuntime(1563): FATAL EXCEPTION: main
09-23 13:17:47.582: E/AndroidRuntime(1563): java.lang.RuntimeException: Unable to
instantiate activity
ComponentInfo{com.androidsleepmachine.gamble/com.AndroidSleepMachine.gamble.HOME}:
java.lang.ClassNotFoundException: com.AndroidSleepMachine.gamble.HOME
09-23 13:17:47.582: E/AndroidRuntime(1563): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
android.app.ActivityThread.access$600(ActivityThread.java:130)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
android.os.Handler.dispatchMessage(Handler.java:99)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
android.os.Looper.loop(Looper.java:137)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
android.app.ActivityThread.main(ActivityThread.java:4745)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
java.lang.reflect.Method.invokeNative(Native Method)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
java.lang.reflect.Method.invoke(Method.java:511)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
dalvik.system.NativeStart.main(Native Method)
09-23 13:17:47.582: E/AndroidRuntime(1563): Caused by:
java.lang.ClassNotFoundException: com.AndroidSleepMachine.gamble.HOME
09-23 13:17:47.582: E/AndroidRuntime(1563): at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-23 13:17:47.582: E/AndroidRuntime(1563): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
It looks like your main activity name is incorrect. Java is case sensitive and your application package name is
package="com.androidsleepmachine.gamble"
while your main activity class name is
com.AndroidSleepMachine.gamble.HOME
The ClassNotFoundException is being thrown because your Activity class name is incorrect in the manifest and isn't being found by the class loader.
It cannot find a class called:
com.AndroidSleepMachine.gamble.HOME
Why is "AndroidSleepMachine" using capital letters?
Why not just use:
android:name=".HOME"
...if your class is indeed called HOME.java? Case-sensitivity may be causing your issue.
com.AndroidSleepMachine.gamble.HOME is not the same as com.androidsleepmachine.gamble.HOME

GCMBroadcastReceiver lacks WAKE_LOCK permission that is declared in manifest

I've implemented GCM as closely to Google's examples as I can, but the default GCMBroadcastReceiver is throwing a SecurityException for lack of the WAKE_LOCK permission. I require it in the my manifest, though, so AFAIK it should have that permission at run-time. Here's the relevant portion of my manifest:
<permission
android:name="PACKAGENAME.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="PACKAGENAME.permission.C2D_MESSAGE" />
<permission
android:name="android.permission.WAKE_LOCK"
android:protectionLevel="signatureOrSystem" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<application
android:name=".App"
android:icon="#drawable/app"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
<service android:name=".GCMIntentService" />
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="PACKAGENAME" />
</intent-filter>
</receiver>
The exception I see in the log file is:
07-09 13:32:58.238: E/AndroidRuntime(2723): java.lang.RuntimeException: Unable to start receiver com.google.android.gcm.GCMBroadcastReceiver: java.lang.SecurityException: Neither user 10072 nor current process has android.permission.WAKE_LOCK.
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2126)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.Looper.loop(Looper.java:137)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-09 13:32:58.238: E/AndroidRuntime(2723): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 13:32:58.238: E/AndroidRuntime(2723): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 13:32:58.238: E/AndroidRuntime(2723): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-09 13:32:58.238: E/AndroidRuntime(2723): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-09 13:32:58.238: E/AndroidRuntime(2723): at dalvik.system.NativeStart.main(Native Method)
07-09 13:32:58.238: E/AndroidRuntime(2723): Caused by: java.lang.SecurityException: Neither user 10072 nor current process has android.permission.WAKE_LOCK.
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.Parcel.readException(Parcel.java:1327)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.Parcel.readException(Parcel.java:1281)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.IPowerManager$Stub$Proxy.acquireWakeLock(IPowerManager.java:279)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.PowerManager$WakeLock.acquireLocked(PowerManager.java:285)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.os.PowerManager$WakeLock.acquire(PowerManager.java:264)
07-09 13:32:58.238: E/AndroidRuntime(2723): at com.google.android.gcm.GCMBaseIntentService.runIntentInService(GCMBaseIntentService.java:235)
07-09 13:32:58.238: E/AndroidRuntime(2723): at com.google.android.gcm.GCMBroadcastReceiver.onReceive(GCMBroadcastReceiver.java:46)
07-09 13:32:58.238: E/AndroidRuntime(2723): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2119)
07-09 13:32:58.238: E/AndroidRuntime(2723): ... 10 more
I wasn't calling GCMRegistrar.onDestroy() in the onDestroy() method of the activity in which I registered to receive messages. For some reason that caused it to complain about not having WAKE_LOCK, but only on the 4.0.4 device.
You should use:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
instead of:
<permission
android:name="android.permission.WAKE_LOCK"
android:protectionLevel="signatureOrSystem" />

BOOT_COMPLETED receiver ActivityNotFoundException

I am trying to write an app that starts on boot up. My receiver works and my app is started on boot up, however it crashes because of ActivityNotFoundException. I may have messed up in the manifest somewhere. Please help to take a look.
This is the receiver code, LocationLock.class just does some stuff to lock the phone.
public class MyStartupIntentReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent){
Intent myStarterIntent = new Intent(context, LocationLock.class);
myStarterIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myStarterIntent);
}
}
This is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".LocationLock$Controller"
android:label="#string/app_name_controller">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".LocationLock"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="#xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<receiver android:name=".MyStartupIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>
Below are the errors:
05-03 02:54:55.301: ERROR/AndroidRuntime(264): FATAL EXCEPTION: main
05-03 02:54:55.301: ERROR/AndroidRuntime(264): java.lang.RuntimeException: Unable to start receiver org.example.locationlock.MyStartupIntentReceiver: android.content.ActivityNotFoundException: Unable to find explicit activity class {org.example.locationlock/org.example.locationlock.LocationLock}; have you declared this activity in your AndroidManifest.xml?
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ActivityThread.access$3200(ActivityThread.java:125)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.os.Looper.loop(Looper.java:123)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at dalvik.system.NativeStart.main(Native Method)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {org.example.locationlock/org.example.locationlock.LocationLock}; have you declared this activity in your AndroidManifest.xml?
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ContextImpl.startActivity(ContextImpl.java:622)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at org.example.locationlock.MyStartupIntentReceiver.onReceive(MyStartupIntentReceiver.java:12)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): ... 10 more
Maybe I can't have two receivers listed one after another, but the MyStartupIntentReceiver has no activity associated with it.
Any help is much appreciated!
you are trying to start a receiver class: Intent myStarterIntent = new Intent(context, LocationLock.class);, since in the manifest file it is declared as a reciever class: <receiver android:name=".LocationLock" so modify this declaration to activiy:
<activity
android:name=".LocationLock"
android:windowSoftInputMode="stateVisible|adjustResize" >
</activity>
have you tried defining it as an activity in your manifest?
for example, within your section:
<activity android:name=".MyStartupIntentReceiver"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:noHistory="true" />

App cannot start at all in Android 2.2 (Froyo)

My app has been running okay until the recent Froyo update. After installing the Android 2.2 SDK, I can compile my code without any errors. However, when I run it, it just force closes:
Here's the log:
05-23 10:15:13.463: DEBUG/AndroidRuntime(423): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
05-23 10:15:13.463: DEBUG/AndroidRuntime(423): CheckJNI is ON
05-23 10:15:14.193: DEBUG/AndroidRuntime(423): --- registering native functions ---
05-23 10:15:15.293: DEBUG/AndroidRuntime(423): Shutting down VM
05-23 10:15:15.303: DEBUG/dalvikvm(423): Debugger has detached; object registry had 1 entries
05-23 10:15:15.333:
INFO/AndroidRuntime(423): NOTE: attach of thread 'Binder Thread #3' failed
05-23 10:15:16.003: DEBUG/AndroidRuntime(431): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
05-23 10:15:16.013:
DEBUG/AndroidRuntime(431): CheckJNI is ON
05-23 10:15:16.273: DEBUG/AndroidRuntime(431): --- registering native functions ---
05-23 10:15:17.392: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=
[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.handyapps.easymoney/.EasyMoney }
05-23 10:15:17.602: DEBUG/AndroidRuntime(431): Shutting down VM
05-23 10:15:17.662: DEBUG/dalvikvm(431): Debugger has detached; object registry had 1 entries
05-23 10:15:17.742: INFO/AndroidRuntime(431): NOTE: attach of thread 'Binder Thread #3' failed
05-23 10:15:17.912: INFO/ActivityManager(59): Start proc com.handyapps.easymoney for activity
com.handyapps.easymoney/.EasyMoney: pid=438 uid=10035 gids={1006, 1015}
05-23 10:15:19.032: DEBUG/AndroidRuntime(438): Shutting down VM
05-23 10:15:19.032: WARN/dalvikvm(438): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-23
10:15:19.062: ERROR/AndroidRuntime(438): FATAL EXCEPTION: main
05-23 10:15:19.062: ERROR/AndroidRuntime(438): java.lang.RuntimeException: Unable to instantiate application
com.handyapps.easymoney.EasyMoney: java.lang.ClassCastException: com.handyapps.easymoney.EasyMoney
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at android.app.ActivityThread$PackageInfo.makeApplication
(ActivityThread.java:649)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at android.app.ActivityThread.handleBindApplication
(ActivityThread.java:4232)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at android.app.ActivityThread.access$3000(ActivityThread.java:125)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at android.os.Looper.loop(Looper.java:123)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at java.lang.reflect.Method.invokeNative(Native Method)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at java.lang.reflect.Method.invoke(Method.java:521)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:868)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at dalvik.system.NativeStart.main(Native Method)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): Caused by: java.lang.ClassCastException: com.handyapps.easymoney.EasyMoney
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at android.app.Instrumentation.newApplication(Instrumentation.java:957)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at android.app.Instrumentation.newApplication(Instrumentation.java:942)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): at android.app.ActivityThread$PackageInfo.makeApplication
(ActivityThread.java:644)
05-23 10:15:19.062: ERROR/AndroidRuntime(438): ... 11 more
05-23 10:15:19.082: WARN/ActivityManager(59): Force finishing activity com.handyapps.easymoney/.EasyMoney
05-23 10:15:19.592: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{450018f0
com.handyapps.easymoney/.EasyMoney}
//////////////THE ANDROID MANIFEST FILE////
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4" />
<application android:icon="#drawable/icon"
android:name="#string/app_name" android:label="#string/app_name"
android:debuggable="false">
<activity android:name=".EasyMoney"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TranList" android:label="#string/app_name" android:theme="#android:style/Theme.Light.NoTitleBar"/>
<activity android:name=".TranEdit" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden"/>
<activity android:name=".BillReminderEdit" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden"/>
<activity android:name=".BillReminderList" android:launchMode="singleTop" android:theme="#android:style/Theme.Light.NoTitleBar"/>
<activity android:name=".BudgetList" android:theme="#android:style/Theme.Light.NoTitleBar"/>
<activity android:name=".BudgetEdit" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden"/>
<activity android:name=".Search" android:theme="#style/CustomDialogTheme" android:windowSoftInputMode="stateAlwaysHidden"/>
<activity android:name=".PasscodeEntry" android:theme="#style/CustomDialogTheme" android:windowSoftInputMode="stateAlwaysHidden" android:screenOrientation="portrait"/>
<activity android:name=".AccountList" android:theme="#android:style/Theme.Light.NoTitleBar">
</activity>
<activity android:name=".AccountEdit" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden"/>
<activity android:name=".UserSettingsEdit" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden"/>
<activity android:name=".CurrencySettingsEdit" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden"/>
<activity android:name=".DisplaySettingsEdit" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden"/>
<activity android:name=".BackupSettingsEdit" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden"/>
<activity android:name=".CategoryList" android:theme="#android:style/Theme.Light.NoTitleBar" />
<activity android:name=".CategoryEdit" android:theme="#android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden"/>
<activity android:name=".ExpenseByCategory" android:theme="#android:style/Theme.Light.NoTitleBar"/>
<activity android:name=".BalanceReport" android:theme="#android:style/Theme.Light.NoTitleBar"/>
<activity android:name=".MonthlyExpenseReport" android:theme="#android:style/Theme.Light.NoTitleBar"/>
<activity android:name=".MonthlyIncomeReport" android:theme="#android:style/Theme.Light.NoTitleBar"/>
<activity android:name=".MonthlyCashflowReport" android:theme="#android:style/Theme.Light.NoTitleBar"/>
<activity android:name=".PhotoList" android:theme="#android:style/Theme.Light.NoTitleBar" />
<activity android:name=".ExpenseByPayee" android:theme="#android:style/Theme.Light.NoTitleBar"/>
<activity android:name=".ExpenseBySubCategory" android:theme="#android:style/Theme.Light.NoTitleBar"/>
<service android:name="StartAlarm_Service">
<intent-filter>
<action android:name="com.handyapps.easymoney.StartAlarm_Service" />
</intent-filter>
</service>
<service android:name=".AlarmService_Service" android:process=":remote" />
<receiver android:name="StartupIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<receiver android:name=".WidgetProvider" android:label="#string/widget_name">
<intent-filter>
<action
android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget" />
</receiver>
<receiver
android:name=".WidgetProvider" android:label="#string/widget_name">
<intent-filter>
<action
android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<data android:scheme="easymoney_widget" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget" />
</receiver>
<receiver android:name=".WidgetProvider">
<intent-filter>
<action android:name="com.handyapps.easymoney.WIDGET_CONTROL" />
<data android:scheme="easymoney_widget" />
</intent-filter>
</receiver>
</application>
The main startup class is com.handyapps.easymoney.EasyMoney. I placed a breakpoint at the start of the onCreate() method but I discovered it didn't even reach there. Somehow, the application just couldn't be loaded in Android 2.2... but it works perfectly fine for all the previous Android versions. Been trying to find the cause for the past 2 days but am totally stumped!!
I've found the solution! Just need to remove the android:name attribute from the application tag in the manifest... but the compiler should have given a warning or error.
From ClassCastException:
Thrown when a program attempts to cast
a an object to a type with which it is
not compatible.
I would go through the code and check the casts I am doing.

Categories

Resources