I am struggling with this error:
08-08 11: 42: 53.179: E / AndroidRuntime (20288): caused by: java.lang.InstantiationException: cannot create an instance of class com.example.localnotificationtest.ReminderService; no empty constructor
I do not understand why this error occurs.
I am trying to show a notification at a specific time and after searching for some time when I found this old stack question. I tried everything, but my code gives an error.
Please help me solve this problem.
Here is my MainActivity code:
public class MainActivity extends Activity { int mHour, mMinute; ReminderService reminderService; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); reminderService = new ReminderService("ReminderService"); TimePickerDialog dialog = new TimePickerDialog(this, mTimeSetListener, mHour, mMinute, false); dialog.show(); } TimePickerDialog.OnTimeSetListener mTimeSetListener = new OnTimeSetListener() { @Override public void onTimeSet(TimePicker v, int hourOfDay, int minute) { mHour = hourOfDay; mMinute = minute; AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, Calendar.YEAR); c.set(Calendar.MONTH, Calendar.MONTH); c.set(Calendar.DAY_OF_MONTH, Calendar.DAY_OF_MONTH); c.set(Calendar.HOUR_OF_DAY, mHour); c.set(Calendar.MINUTE, mMinute); c.set(Calendar.SECOND, 0); long timeInMills = c.getTimeInMillis(); Intent intent = new Intent(MainActivity.this, ReminderService.class); PendingIntent pendingIntent = PendingIntent.getService(MainActivity.this, 0, intent, 0); alarmManager.set(AlarmManager.RTC, timeInMills, pendingIntent); } }; }
and here is my ReminderService code:
public class ReminderService extends IntentService { public ReminderService(String name) { super(name);
and here is my manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.localnotificationtest" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name="ReminderService"></service> </application> </manifest>
I do not know where I am wrong. Am I missing some code?