-1

I receive the following error when my android app call my receiver after boot. This problem only happens in Android GoogleApi's API level 8 Platform 2.2 (this work well in api level 8, level 10 and above).

09-18 05:26:10.421: E/AndroidRuntime(261): FATAL EXCEPTION: main
09-18 05:26:10.421: E/AndroidRuntime(261): java.lang.RuntimeException: Unable to  instantiate receiver com.adduci.BootReceiver: java.lang.ClassNotFoundException: com.adduci.BootReceiver in loader dalvik.system.PathClassLoader[/data/app/com.adduci-2.apk]
09-18 05:26:10.421: E/AndroidRuntime(261):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2789)
09-18 05:26:10.421: E/AndroidRuntime(261):  at android.app.ActivityThread.access$3200(ActivityThread.java:125)
09-18 05:26:10.421: E/AndroidRuntime(261):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
09-18 05:26:10.421: E/AndroidRuntime(261):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-18 05:26:10.421: E/AndroidRuntime(261):  at android.os.Looper.loop(Looper.java:123)
09-18 05:26:10.421: E/AndroidRuntime(261):  at android.app.ActivityThread.main(ActivityThread.java:4627)
09-18 05:26:10.421: E/AndroidRuntime(261):  at java.lang.reflect.Method.invokeNative(Native Method)
09-18 05:26:10.421: E/AndroidRuntime(261):  at java.lang.reflect.Method.invoke(Method.java:521)
09-18 05:26:10.421: E/AndroidRuntime(261):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-18 05:26:10.421: E/AndroidRuntime(261):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-18 05:26:10.421: E/AndroidRuntime(261):  at dalvik.system.NativeStart.main(Native Method)
09-18 05:26:10.421: E/AndroidRuntime(261): Caused by: java.lang.ClassNotFoundException: com.adduci.BootReceiver in loader dalvik.system.PathClassLoader[/data/app/com.adduci-2.apk]
09-18 05:26:10.421: E/AndroidRuntime(261):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
09-18 05:26:10.421: E/AndroidRuntime(261):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
09-18 05:26:10.421: E/AndroidRuntime(261):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
09-18 05:26:10.421: E/AndroidRuntime(261):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2780)
09-18 05:26:10.421: E/AndroidRuntime(261):  ... 10 more

I clarify that the code works fine, because if I run it on an emulator to run 10 or Api Api 16 works perfectly. The error I repeat, I get it only when I run it on an emulator to run 8 or Google Api Api's platform 2.2 API level 8. Thanks!!

My manifest file is this:

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".ListPro3Activity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name=".MyReceiverAlarmItem"/>
    <activity android:name=".AlarmEventActivity">
    </activity>
    <activity android:name=".ShowAlarmMessageActivity">
    </activity>

   <receiver android:name="com.adduci.BootReceiver">
       <intent-filter>
           <action android:name="android.intent.action.BOOT_COMPLETED" />
           <category android:name="android.intent.category.HOME" />
           <!--category android:name="android.intent.category.LAUNCHER" /-->
       </intent-filter>
   </receiver>
   <service android:enabled="true" android:name="ConfigAlarmService">
   <intent-filter>
    <action android:name="com.adduci.ConfigAlarmService">
    </action>
    </intent-filter>
    </service>
</application>
</manifest>

My BroadCast file is this:

package com.adduci;

import com.adduci.Utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class BootReceiver extends BroadcastReceiver  {

public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        Log.v("lp","INICIO BROADCAST Y VOY A LLAMAR AL SERVICE");
        Intent i = new Intent();
        i.setAction("com.adduci.ConfigAlarmService");
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ComponentName service = context.startService(i);

        //context.stopService(new Intent(context, service.getClass()));
    }
}
}

and my Service file is this:

package com.adduci;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.text.ParseException;

import android.app.Service;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

public class ConfigAlarmService extends Service{
private MyAlarm alarm;
private ArrayList<HashMap<String,Object>> columns;
private ArrayList<Datos> datos;

@Override
public void onCreate(){
    Log.v("lp","SERVICE ONCREATE!!!");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) 
{
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    Log.v("lp","StartAtBootService -- onStartCommand()");           
    ....
    ....
    String cols="[" +
                "{'content':'itemId'," +
                "'SQLiteType':'Int'}," +
                "{'content':'itemDescripcion'," +
                "'SQLiteType':'String'}," +
                "{'content':'recordatorio'," +
                "'SQLiteType':'Int'}," +
                "{'content':'recordatorioFecha'," +
                "'SQLiteType':'String'}" +
                "]";
    this.columns = Utils.jsonToArray(cols);

    Log.v("lp","OPENHELPER");       
    SQLiteOpenHelper sqLiteOpenHelper=new ListProSQLiteHelper(this, "DBListPro", null, 1);
    Log.v("lp","FIN OPENHELPER!!!");
    this.load("SELECT * FROM items WHERE recordatorio=1", sqLiteOpenHelper);
    this.stopSelf();
    return START_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

public void onDestroy(){
    super.onDestroy();
    Log.v("lp","CONFIGALARMSERVICE DESTROY!!");
}

private void load(String sqlCondition, SQLiteOpenHelper sqLiteOpenHelper){
    this.datos = new ArrayList<Datos>();
    Object[]sql={sqlCondition, sqLiteOpenHelper};
    DataFromSqlite dataSqlite=new DataFromSqlite(this, this.getColumns(), sql, DataFromSqlite.ASYNCHRO, DataFromSqlite.DIALOG_WHEEL_OFF){

        @Override
        void onPreExecuteEvent() {
            // TODO Auto-generated method stub
        }

        @Override
        void onDoInBackGroundEvent() {
            // TODO Auto-generated method stub
        }

        @Override
        void onPostExecuteEvent() {
            // TODO Auto-generated method stub
            for(int i=0;i< this.getData().size();i++){
                ContentValues cv= this.getData().get(i);
                Datos datoItem=new Datos();
                for(int j=0; j<this.columns.size();j++){
                    String col=(String)columns.get(j).get("content");
                    datoItem.put(col, cv.get(col));
                }
                datos.add(datoItem);
            }
            setAlarms();
        }
    };
}

private void setAlarms(){
    Log.v("lp","DaToS : "+ this.datos);
    for(int i=0; i< this.datos.size(); i++){
        Datos dat = this.datos.get(i);
        if(Integer.parseInt((String) dat.get("recordatorio")) == 1){
            Bundle bundleReceiver= new Bundle();
            bundleReceiver.putString("NotificationText", (String) dat.get("itemDescripcion"));
            this.alarm= new MyAlarm(this, MyReceiverAlarmItem.class, bundleReceiver);

            Date recordatorioFecha= new Date();
            SimpleDateFormat formato= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
            try {
                recordatorioFecha= formato.parse((String) dat.get("recordatorioFecha"));
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Calendar calendar= Calendar.getInstance();
            calendar.setTime(recordatorioFecha);

            if(calendar.getTimeInMillis() > System.currentTimeMillis()){
                Log.v("lp","DAT:"+dat+"MES:"+String.valueOf(calendar.get(Calendar.MONTH)));
                this.alarm.setAlarm(Integer.parseInt((String) dat.get("itemId")) , calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE));
            }
        }   
    }
}

private ArrayList<HashMap<String,Object>> getColumns(){
    return this.columns;
}   
}
  • Try changing the line in your manifest file from to – Arunkumar Sep 18 '12 at 09:46
  • Thanks for your answer. Leave the as I put in the message. I closed the emulator and eclipse. The restart and went well the first time. I went back to do the same, and the second time started giving the same error as before. I'm baffled. Please help! – diego adduci Sep 18 '12 at 18:26
  • after further testing I noticed that the error only occurs when you use the project in Google's API, but not if you use any other library API Level 8 or higher (API 10, APi 16, etc). That is, the only problem is caused by the Google's Api. Please help!!, because I need to use in the project the Google's Api – diego adduci Sep 19 '12 at 09:44

1 Answers1

0

Try replacing your menifest entry with the following and then check.

<receiver android:name="BootReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
Chandrashekhar
  • 498
  • 4
  • 19
  • This works the first, at most, the second time. then starts the error. I repeat that only causes problems when I use the Google's API level 8. if you do not use the Google's API works perfectly. It's like some data is stored permanently in the memory of ADV, and then could not overwrite it, or to make any calls, then it will remain hopelessly locked, After the error because there is no way to run again in the ADV broadcast, even when fully discuss its content and service call. After the error, I must create a new ADV. Also, thank you very much – diego adduci Sep 19 '12 at 16:20