Note that there are some explanatory texts on larger screens.

plurals
  1. PONo empty constructor when create a service
    primarykey
    data
    text
    <p>I am struggling with this error:</p> <blockquote> <p>08-08 11:42:53.179: E/AndroidRuntime(20288): Caused by: java.lang.InstantiationException: can't instantiate class com.example.localnotificationtest.ReminderService; no empty constructor</p> </blockquote> <p>I don't understand why this error occurs.</p> <p>I am trying to appear notification at specific time and after searching for a time i found this <a href="https://stackoverflow.com/q/7540724/1250370">old stackoverflow question</a>. I tried everything but my code gives error.</p> <p>Please help me to solve this problem.</p> <p>Here is my MainActivity code:</p> <pre><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); } }; } </code></pre> <p>and here is my ReminderService code:</p> <pre><code>public class ReminderService extends IntentService { public ReminderService(String name) { super(name); // TODO Auto-generated constructor stub } @Override protected void onHandleIntent(Intent intent) { Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 1, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(this); builder.setContentIntent(contentIntent) .setSmallIcon(R.drawable.ic_launcher) .setTicker("Local Notification Ticker") .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setContentTitle("Local Notification") .setContentText("This is content text."); Notification n = builder.getNotification(); nm.notify(1, n); } } </code></pre> <p>and here is my manifest.xml:</p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.localnotificationtest" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="11" android:targetSdkVersion="15" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name=".MainActivity" android:label="@string/title_activity_main" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;service android:name="ReminderService"&gt;&lt;/service&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>I don't know where I am going wrong. Am I missing some code?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload