在下面的代碼,Eclipse中發現了一個錯誤:問題與NotificationCompact.Builder和ActionBarSherlock
The method build() is undefined for the type NotificationCompat.Builder
一切加入ActionBarSherlock
(以下this tutorial)之前工作的罰款。
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
public class NotificationActivity extends BroadcastReceiver {
NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
int notifyID = 1;
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context)
.setSmallIcon(R.drawable.zcicon)
.setAutoCancel(true)
.setDefaults(
Notification.DEFAULT_SOUND
| Notification.DEFAULT_LIGHTS)
.setTicker("mytitle").setContentTitle("mycontent")
.setContentText("text, text");
Intent resultIntent = new Intent(context, CalcareReader.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MyActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
nm.notify(notifyID, mBuilder.build()); // error here
}
}
工程謝謝! [鏈接](http://stackoverflow.com/questions/12793722/error-on-add-library-project-in-eclipse) – 2013-03-12 13:08:55
>>「ActionBarSherlock項目和你的主要應用程序中的android-support-v4.jar項目。」其實不是。您只需要在ActionBarSherlock項目中使用一個。 – 2013-03-12 13:56:13
@DoctororDrive:True。但是,如果兩個項目中都存在舊的JAR,則只更換一個會導致構建錯誤。兩個項目都需要相同的JAR,或者只在ActionBarSherlock中有JAR,而在主項目中沒有JAR。 – CommonsWare 2013-03-12 16:02:46