Receiver抛出IllegalArgument异常

时间:2014-01-23 19:39:57

标签: java android android-intent notifications broadcastreceiver

我创建了一个接收器类来启动一个意图。当用户确认所需的东西后几秒钟应用程序抛出异常。这是logcat输出

01-23 20:18:32.541: E/AndroidRuntime(7603): Process: com.ppero196.thumbnail.file.deleter:remote, PID: 7603
01-23 20:18:32.541: E/AndroidRuntime(7603): java.lang.RuntimeException: Unable to start receiver com.ppero196.thumbnail.file.deleter.reminderreciever: java.lang.IllegalArgumentException: contentView required: pkg=com.ppero196.thumbnail.file.deleter id=2131492903 notification=Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 kind=[null])
01-23 20:18:32.541: E/AndroidRuntime(7603): Caused by: java.lang.IllegalArgumentException: contentView required: pkg=com.ppero196.thumbnail.file.deleter id=2131492903 notification=Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 kind=[null])
01-23 20:18:32.541: E/AndroidRuntime(7603):     at com.ppero196.thumbnail.file.deleter.reminderreciever.onReceive(reminderreciever.java:25)

从我收集到的我需要ContentView somwhere,但我不知道在哪里。这是我的提醒课:

package com.ppero196.thumbnail.file.deleter;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class reminder extends Activity {

    EditText valor1;
    String myEditValue;
    public static int day;


  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.remind);
     getActionBar().setDisplayHomeAsUpEnabled(true);
      Button buttonStart = (Button)findViewById(R.id.start);
      buttonStart.setOnClickListener(new Button.OnClickListener(){

  @Override
  public void onClick(View arg0) {
   // TODO Auto-generated method stub
    Intent myIntent = new Intent(getBaseContext(),
            reminderreciever.class);

    PendingIntent pendingIntent
     = PendingIntent.getBroadcast(getBaseContext(),
       0, myIntent, 0);

    AlarmManager alarmManager
      = (AlarmManager)getSystemService(ALARM_SERVICE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 10);
    valor1 = (EditText) findViewById (R.id.desiredDay);
    myEditValue = valor1.getText().toString();
    day = Integer.parseInt(myEditValue); 
    long interval = day * 24 * 3600 * 1000; //
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
      calendar.getTimeInMillis(), interval, pendingIntent);
    finish();
    Toast.makeText(getApplicationContext(), 
            "Cleaning thumbnails every " + ( interval / (day * 24 * 3600 * 1000) * day ) + " days", Toast.LENGTH_LONG).show();
  }});
  }

}

这是我的接收器类:

package com.ppero196.thumbnail.file.deleter;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class reminderreciever extends BroadcastReceiver {

@SuppressWarnings("deprecation")
@Override
public void onReceive(Context context, Intent intent) {
 // TODO Auto-generated method stub

    NotificationManager mNM;
    mNM = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.ic_launcher, context.getText(R.string.alarm_service_label),
    System.currentTimeMillis());
    // The PendingIntent to launch our activity if the user selects this notification
    // Set the info for the views that show in the notification panel
    // Send the notification.
    // We use a layout id because it is a unique number. We use it later to cancel.
    mNM.notify(R.string.alarm_service_label, notification);    
 Intent scheduledIntent = new Intent(context, delete.class);
 scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 context.startActivity(scheduledIntent);

}

}

0 个答案:

没有答案