0

I am trying to import EventBus.jar file from this link but when i am trying to create an instance of EventBus. it gives me error "EventBus cannot be resolved to a type "

here is my code for your consideration

 public class ChargingReceiver extends BroadcastReceiver{
 private EventBus bus = EventBus.getDefault(); 

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
     ChargingEvent event = null;

        // Get current time
        Time now = new Time();
        now.setToNow();     
        String timeOfEvent = now.format("%H:%M:%S");

        String eventData = "@" + timeOfEvent + " this device started ";
        if(intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)){
            event=new ChargingEvent(eventData+"charging.");
        } else if(intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)){
            event=new ChargingEvent(eventData+"discharging.");
        }

        // Post the event
        bus.post(event);

}
ALI RAZA
  • 33
  • 9
  • If you are using Android Studio, just put this in your gradle.build file inside the dependencies block `compile 'de.greenrobot:eventbus:2.4.0` – Aksiom Dec 21 '15 at 10:07
  • 1
    Can I ask why? You should really consider switching to Android Studio because support for the Android Developer Tools (ADT) in Eclipse has ended a long time ago. And Android Studio rocks :) – Aksiom Dec 21 '15 at 10:17
  • 1
    Eclipse is and always was terrible. Just don't use it. Android Studio has been the default IDE for Android for at least a year now, and it was release more than two years ago. If you haven't switched by now, there is no reason not to do it now. – Xaver Kapeller Dec 21 '15 at 10:20
  • very soon m going to switch my project in android studio. – ALI RAZA Dec 21 '15 at 10:31
  • @ALIRAZA Have you followed this instruction during adding jar file http://stackoverflow.com/a/6859020/1658267 ? Still doesn't work? (Though, I agree with guys regarding Android Studio. It's incomparably better) – Konstantin Loginov Dec 21 '15 at 16:27
  • yes i have followed the instruction. and by the way issue is resolved now. there was problem in JAR file. so i got the JAR from another source. – ALI RAZA Dec 22 '15 at 05:26

0 Answers0