当前位置: 首页 > 知识库问答 >
问题:

android/v5/navigation框中的静态服务类型/mapionm/I

哈烨熠
2023-03-14

早上好,我已经创建了一个新项目,我已经编写了使用浏览器的示例代码,它已经工作了。但是现在,我试图复制它到我的主要项目不适合我。错误如下:

E/AndroidRuntime:致命异常:主进程:com。卡戈公寓。佩西亚。firebase2login,PID:5743 java。lang.NoSuchFieldError:Lcom/mapbox/services/android/navigation/ui/v5/R$id类中没有类型I的静态字段导航视图;或者它的超类(声明'com.mapbox.services.android.navigation.ui.v5.R$id'出现在/data/app/com.apparcago.pacea.firebase2login-LSC0SaLMEkd-LbroOrauqg==/split_lib_slice_4_apk.apk)在com上。地图盒。服务。Android航行用户界面。v5。MapboxNavigationActivity。android上的onCreate(MapboxNavigationActivity.java:32)。应用程序。活动在android上执行创建(Activity.java:7098)。应用程序。活动在android上执行创建(Activity.java:7089)。应用程序。仪器仪表。android上的callActivityOnCreate(Instrumentation.java:1215)。应用程序。活动线程。在android上执行启动活动(ActivityThread.java:2768)。应用程序。活动线程。android上的handleLaunchActivity(ActivityThread.java:2893)。应用程序。活动线程-android上的wrap11(未知来源:0)。应用程序。android上的ActivityThread$H.handleMessage(ActivityThread.java:1616)。操作系统。处理程序。android上的dispatchMessage(Handler.java:106)。操作系统。活套。android上的loop(Looper.java:164)。应用程序。活动线程。java上的main(ActivityThread.java:6650)。朗。反思。方法在com上调用(本机方法)。Android内部的操作系统。RuntimeInit$MethodAndArgsCaller。在com上运行(RuntimeInit.java:547)。Android内部的html" target="_blank">操作系统。合子体。main(ZygoteInit.java:818)

我显示了不起作用的项目代码:

显示

<activity
    android:name=".NavigationActivity"
    android:label="@string/title_activity_navigation">
</activity>

建筑格雷德尔(模块)

android {
buildToolsVersion "27.0.3"
compileSdkVersion 27
defaultConfig {
    applicationId "com.apparcago.pacea.firebase2login"
    minSdkVersion 24
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')


implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

//Firebase
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.4'

//Facebook
implementation 'com.facebook.android:facebook-login:4.38.1'

// Para botones chulos (Fancybuttons)
implementation 'com.github.medyo:fancybuttons:1.9.0'

//Material design para Dialogs chulos
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'

//ultima version me da errores
implementation 'com.google.android.gms:play-services-maps:16.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

// Material design de editText (Para hacer edit Text bonitos)
implementation 'com.rengwuxian.materialedittext:library:2.1.4'

//Diseño 27
implementation 'com.android.support:design:27.1.1'

//Cardview
implementation 'com.android.support:cardview-v7:27.1.1'

//FAB
implementation 'com.nightonke:boommenu:2.1.1'

//Mapbox
//implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.0.0-alpha.2'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.7.1'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.23.0'

}
//Firebase
apply plugin: 'com.google.gms.google-services'

Build.gradle(项目)

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'

    classpath 'com.google.gms:google-services:4.0.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()//Para mapbox
        maven { url 'https://mapbox.bintray.com/mapbox' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NavigationActivity">

<com.mapbox.mapboxsdk.maps.MapView
    android:id="@+id/mapView_mapbox"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    mapbox:mapbox_cameraTargetLat="37.7749"
    mapbox:mapbox_cameraTargetLng="-122.4194"
    mapbox:mapbox_cameraZoom="12"
    mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10" />

<Button
    android:id="@+id/startButton"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="24dp"
    android:layout_marginEnd="24dp"
    android:layout_marginStart="24dp"
    android:enabled="false"
    android:text="asd"
    android:textColor="@color/colorPrimary"
    mapbox:layout_constraintBottom_toBottomOf="@+id/mapView_mapbox"
    mapbox:layout_constraintEnd_toEndOf="parent"
    mapbox:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>

导航活性

package com.apparcago.pacea.firebase2login;

import android.location.Location;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;

import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.services.android.navigation.ui.v5.NavigationLauncher;
import com.mapbox.services.android.navigation.ui.v5.NavigationLauncherOptions;
import com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute;
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class NavigationActivity extends AppCompatActivity implements OnMapReadyCallback, MapboxMap.OnMapClickListener, PermissionsListener {
private MapView mapView;
// variables for adding location layer
private MapboxMap mapboxMap;
private PermissionsManager permissionsManager;
private Location originLocation;
// variables for adding a marker
private Marker destinationMarker;
private LatLng originCoord;
private LatLng destinationCoord;
// variables for calculating and drawing a route
private Point originPosition;
private Point destinationPosition;
private DirectionsRoute currentRoute;
private static final String TAG = "DirectionsActivity";
private NavigationMapRoute navigationMapRoute;
private Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Mapbox.getInstance(this, getString(R.string.access_token_mapbox));
    setContentView(R.layout.activity_navigation);
    mapView = findViewById(R.id.mapView_mapbox);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(this);

}

@Override
public void onMapReady(MapboxMap mapboxMap) {
    this.mapboxMap = mapboxMap;
    enableLocationComponent();
    originCoord = new LatLng(originLocation.getLatitude(), originLocation.getLongitude());
    mapboxMap.addOnMapClickListener(this);
    button = findViewById(R.id.startButton);
    button.setOnClickListener(v -> {
        boolean simulateRoute = true;
        NavigationLauncherOptions options = NavigationLauncherOptions.builder()
                .directionsRoute(currentRoute)
                .shouldSimulateRoute(simulateRoute)
                .build();
        // Call this method with Context from within an Activity
        NavigationLauncher.startNavigation(NavigationActivity.this, options);
    });
}

@Override
public void onMapClick(@NonNull LatLng point) {
    if (destinationMarker != null) {
        mapboxMap.removeMarker(destinationMarker);
    }
    destinationCoord = point;
    destinationMarker = mapboxMap.addMarker(new MarkerOptions()
            .position(destinationCoord)
    );
    destinationPosition = Point.fromLngLat(destinationCoord.getLongitude(), destinationCoord.getLatitude());
    originPosition = Point.fromLngLat(originCoord.getLongitude(), originCoord.getLatitude());
    getRoute(originPosition, destinationPosition);
    button.setEnabled(true);
    button.setBackgroundResource(R.color.mapboxBlue);
}

private void getRoute(Point origin, Point destination) {
    NavigationRoute.builder(this)
            .accessToken(Mapbox.getAccessToken())
            .origin(origin)
            .destination(destination)
            .build()
            .getRoute(new Callback<DirectionsResponse>() {
                @Override
                public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
                    // You can get the generic HTTP info about the response
                    Log.d(TAG, "Response code: " + response.code());
                    if (response.body() == null) {
                        Log.e(TAG, "No routes found, make sure you set the right user and access token.");
                        return;
                    } else if (response.body().routes().size() < 1) {
                        Log.e(TAG, "No routes found");
                        return;
                    }

                    currentRoute = response.body().routes().get(0);

                    // Draw the route on the map
                    if (navigationMapRoute != null) {
                        navigationMapRoute.removeRoute();
                    } else {
                        navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap, R.style.NavigationMapRoute);
                    }
                    navigationMapRoute.addRoute(currentRoute);
                }

                @Override
                public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
                    Log.e(TAG, "Error: " + throwable.getMessage());
                }
            });
}
@SuppressWarnings( {"MissingPermission"})
private void enableLocationComponent() {
    // Check if permissions are enabled and if not request
    if (PermissionsManager.areLocationPermissionsGranted(this)) {
        // Activate the MapboxMap LocationComponent to show user location
        // Adding in LocationComponentOptions is also an optional parameter
        LocationComponent locationComponent = mapboxMap.getLocationComponent();
        locationComponent.activateLocationComponent(this);
        locationComponent.setLocationComponentEnabled(true);
        // Set the component's camera mode
        locationComponent.setCameraMode(CameraMode.TRACKING);
        Location lastLocation = locationComponent.getLastKnownLocation();
        originLocation = locationComponent.getLastKnownLocation();

    } else {
        permissionsManager = new PermissionsManager(this);
        permissionsManager.requestLocationPermissions(this);
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
    Toast.makeText(this, "PRUEBA1", Toast.LENGTH_LONG).show();
}

@Override
public void onPermissionResult(boolean granted) {
    if (granted) {
        enableLocationComponent();
    } else {
        Toast.makeText(this, "PERMISOS NO ACEPTADOS", Toast.LENGTH_LONG).show();
        finish();
    }
}

@Override
protected void onStart() {
    super.onStart();
    mapView.onStart();
}

@Override
protected void onResume() {
    super.onResume();
    mapView.onResume();
}

@Override
protected void onPause() {
    super.onPause();
    mapView.onPause();
}

@Override
protected void onStop() {
    super.onStop();
    mapView.onStop();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mapView.onSaveInstanceState(outState);
}

@Override
protected void onDestroy() {
    super.onDestroy();
    mapView.onDestroy();
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    mapView.onLowMemory();
}

}

项目中唯一有效的区别是它有更少的依赖关系,因为它是一个只为学习mapbox而创建的项目。

我不会发现错误,但我认为可能与gradle有关,有什么建议吗?

对不起,我的长篇大论和我的英语,提前谢谢。

共有1个答案

华献
2023-03-14

只需将类名(NavigationActivity)和布局名(activity_navigation)重构为另一个。它与具有相同类和布局名称的mapbox类冲突

 类似资料:
  • 有时候希望人工管理服务提供者的上线和下线,此时需将注册中心标识为非动态管理模式。 <dubbo:registry address="10.20.141.150:9090" dynamic="false" /> 或者 <dubbo:registry address="10.20.141.150:9090?dynamic=false" /> 服务提供者初次注册时为禁用状态,需人工启用。断线时,将不

  • 我在做一个Java项目,对服务器端有些怀疑。 我有一个类,它将有多个实例(每个客户端请求一个实例)。在这个类中,有4个不同的任务要做,所以我创建了一个包含4个线程的线程池,但我怀疑执行器是否必须是静态的,因为我应该在服务器停止时调用侦听器来终止线程,对吗? 执行者服务执行者=执行者。新固定线程池(4) 非常感谢。

  • StaticCache 静态变量形式的缓存(是存放于当前进程的内存中)。注册中心的服务地址也存放于静态缓存中。 StaticCache::set($key, $value, $canUnset = true) use StaticCache; StaticCache::set('foo', 'bar'); //默认该变量可以被释放,也可设置不释放。使用情况:在使用Async

  • 一个机器或语言是用来计算的,根据计算机模型的定义,其操作的是存储器里的数据,就现在流行的用二进制实现的计算机中(曾出现过三进制计算机),数据本质都是0和1,但机器毕竟是为人服务的,解决的是现实问题,它操作的数据需要有现实的含义,所以基本上所有语言都有类型系统,即便是汇编和机器语言,也有整数和浮点的区别 类型系统是很复杂的理论,值得用一本厚书来写,好点的资料有《类型与程序设计语言》,但我没看懂,因为

  • 我们先来看看最简单的本地静态文件服务配置示例: server { listen 80; server_name www.test.com; charset utf-8; root /data/www.test.com; index index.html index.htm; } 就这些?

  • 前面说泛型的时候,提到了C++模板的实现方式是动态特性静态化,在实际情况中,这是一个提高效率的好办法。动态性的好处是灵活,开发简便,静态性的特性是效率高,编译期检查较好,因此很自然地就有一个问题,能不能各取所长,达到两全其美?应该说,在一定程度上是可以的,比如这篇即将讨论的静态类型推导,简称类型推导,因为动态类型无所谓什么推导。个人认为类型推导是编译原理最复杂的东西之一,其他复杂的有垃圾回收,代码