建造者是抽象的;无法实例化。为什么?
Builder is abstract; cannot be instantiated. Why?
我正在尝试实现 Mapbox 的示例之一。他们有一个选项构建器,其实现方式如下所示。但是当我尝试构建它时出现错误
error: Builder is abstract; cannot be instantiated
MapboxNavigationOptions options = new MapboxNavigationOptions.Builder().navigationNotification(customNotification).build();
我不明白这是为什么?这个class不应该是这样用的吗?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
routeRefresh = new RouteRefresh(Mapbox.getAccessToken(), (RefreshCallback) getApplicationContext());
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
Context context = getApplicationContext();
CustomNavigationNotification customNotification = new CustomNavigationNotification(context);
MapboxNavigationOptions options = new MapboxNavigationOptions.Builder().navigationNotification(customNotification).build();
navigation = new MapboxNavigation(
this,
Mapbox.getAccessToken(),
options
);
navigation.addMilestone(new RouteMilestone.Builder()
.setIdentifier(BEGIN_ROUTE_MILESTONE)
.setInstruction(new BeginRouteInstruction())
.setTrigger(
Trigger.all(
Trigger.lt(TriggerProperty.STEP_INDEX, 3),
Trigger.gt(TriggerProperty.STEP_DISTANCE_TOTAL_METERS, 200),
Trigger.gte(TriggerProperty.STEP_DISTANCE_TRAVELED_METERS, 75)
)
).build());
customNotification.register(new MyBroadcastReceiver(navigation), context);
}
我通过删除 new
关键字并使用 MapboxNavigationOptions.builder()
而不是 new MapboxNavigationOptions.Builder()
来修复此问题。
我正在尝试实现 Mapbox 的示例之一。他们有一个选项构建器,其实现方式如下所示。但是当我尝试构建它时出现错误
error: Builder is abstract; cannot be instantiated
MapboxNavigationOptions options = new MapboxNavigationOptions.Builder().navigationNotification(customNotification).build();
我不明白这是为什么?这个class不应该是这样用的吗?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
routeRefresh = new RouteRefresh(Mapbox.getAccessToken(), (RefreshCallback) getApplicationContext());
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
Context context = getApplicationContext();
CustomNavigationNotification customNotification = new CustomNavigationNotification(context);
MapboxNavigationOptions options = new MapboxNavigationOptions.Builder().navigationNotification(customNotification).build();
navigation = new MapboxNavigation(
this,
Mapbox.getAccessToken(),
options
);
navigation.addMilestone(new RouteMilestone.Builder()
.setIdentifier(BEGIN_ROUTE_MILESTONE)
.setInstruction(new BeginRouteInstruction())
.setTrigger(
Trigger.all(
Trigger.lt(TriggerProperty.STEP_INDEX, 3),
Trigger.gt(TriggerProperty.STEP_DISTANCE_TOTAL_METERS, 200),
Trigger.gte(TriggerProperty.STEP_DISTANCE_TRAVELED_METERS, 75)
)
).build());
customNotification.register(new MyBroadcastReceiver(navigation), context);
}
我通过删除 new
关键字并使用 MapboxNavigationOptions.builder()
而不是 new MapboxNavigationOptions.Builder()
来修复此问题。