Android NotificationCompact.Builder和ActionBarSherlock出现问题

Android NotificationCompact.Builder和ActionBarSherlock出现问题,android,compiler-errors,notifications,actionbarsherlock,Android,Compiler Errors,Notifications,Actionbarsherlock,在以下代码中,Eclipse发现了一个错误: The method build() is undefined for the type NotificationCompat.Builder 在添加(以下内容)之前,一切正常 build()已添加到新版Android支持包中。根据您获取和设置ActionBarSherlock的方式,您可能正在使用旧版本的Android支持包。确保在SDK管理器中下载了最新版本,然后在ActionBarSherlock项目和主应用程序项目中使用该android-s

在以下代码中,Eclipse发现了一个错误:

The method build() is undefined for the type NotificationCompat.Builder
在添加(以下内容)之前,一切正常

build()
已添加到新版Android支持包中。根据您获取和设置ActionBarSherlock的方式,您可能正在使用旧版本的Android支持包。确保在SDK管理器中下载了最新版本,然后在ActionBarSherlock项目和主应用程序项目中使用该
android-support-v4.jar

build()来自旧版本的android-support-v4.jar

[如果使用ActionBar Sherlock]

1从SDK更新Android支持库

2将其复制粘贴到您的库/文件夹,或更新路径处的引用

3.对sherlockactionbar项目也要这样做。小心,如果您有一个android-support2-v4.jar,请删除它并只添加android-support-v4.jar


4.清洁

有效谢谢!!>>“ActionBarSherlock项目和您的主应用程序项目中都有android-support-v4.jar。”实际上没有。您在ActionBarSherlock项目中只需要一个。@DoctororDrive:True。但是,如果两个项目中都存在旧JAR,那么只在一个项目中替换它将导致生成错误。要么两个项目都需要相同的JAR,要么只是将JAR放在ActionBarSherlock中,而不将JAR放在主项目中。@commonware这就是我的意思。最新的jar应该只在一个需要它的库项目中,或者在所有需要它的库项目中,而不引用其他拥有它的库项目。@doctorrdrive:您的方法当然是有效的。
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
    }
}