java - MapBox 地点选择器导致致命信号 6

标签 java android mapbox mapbox-android

我正在按照这些说明尝试实现此 Place Picker

但是我的应用程序每次启动时都会崩溃,并出现以下错误:A/libc: Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) 我该如何修复它?我在网上没有找到解决方案...甚至我发现GitHub issues也有同样的错误但没有答案。有人可以帮忙吗?

这是我的代码:

public class PlaceSelectionPluginActivity extends AppCompatActivity {

    private static final int REQUEST_CODE = 5678;
    private TextView selectedLocationTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        Mapbox.getInstance(this, "***myToken***");

        setContentView(R.layout.activity_place_selection);
        selectedLocationTextView = findViewById(R.id.selected_location_info_textview);
        goToPickerActivity();
    }

    /**
     * Set up the PlacePickerOptions and startActivityForResult
     */
    private void goToPickerActivity() {
        startActivityForResult(
                new PlacePicker.IntentBuilder()
                        .accessToken("***myToken***")
                        .placeOptions(PlacePickerOptions.builder()
                                .statingCameraPosition(new CameraPosition.Builder()
                                        .target(new LatLng(40.7544, -73.9862)).zoom(16).build())
                                .build())
                        .build(this), REQUEST_CODE);
    }

    /**
     * This fires after a location is selected in the Places Plugin's PlacePickerActivity.
     * @param requestCode code that is a part of the return to this activity
     * @param resultCode code that is a part of the return to this activity
     * @param data the data that is a part of the return to this activity
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_CANCELED) {
// Show the button and set the OnClickListener()
            Button goToPickerActivityButton = findViewById(R.id.go_to_picker_button);
            goToPickerActivityButton.setVisibility(View.VISIBLE);
            goToPickerActivityButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    goToPickerActivity();
                }
            });
        } else if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
// Retrieve the information from the selected location's CarmenFeature
            CarmenFeature carmenFeature = PlacePicker.getPlace(data);

// Set the TextView text to the entire CarmenFeature. The CarmenFeature
// also be parsed through to grab and display certain information such as
// its placeName, text, or coordinates.
            if (carmenFeature != null) {
                selectedLocationTextView.setText(String.format(
                        getString(R.string.selected_place_info), carmenFeature.toJson()));
            }
        }
    }
}

build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'


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

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

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

应用程序级别build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"

    defaultConfig {
        applicationId "com.mycompany.placepickertest"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'



    implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-places-v9:0.12.0'
}

activity_place_selection.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/go_to_picker_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="invisible"
        android:text="go to picker activity" />

    <TextView
        android:id="@+id/selected_location_info_textview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

完整的堆栈跟踪:

2020-05-17 01:00:57.244 14576-14628/com.mycompany.mapboxpickerattempt I/oxpickerattemp: --------- beginning of crash
2020-05-17 01:00:57.265 14576-14628/com.mycompany.mapboxpickerattempt A/libc: /usr/local/google/buildbot/src/android/ndk-release-r20/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:73: abort_message: assertion "terminating with uncaught exception of type jni::PendingJavaException" failed
2020-05-17 01:00:57.265 14576-14628/com.mycompany.mapboxpickerattempt A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 14628 (OnlineFileSourc), pid 14576 (oxpickerattempt)

最佳答案

这似乎需要 Java 8 声明。请将以下行添加到您的 build.gradle(应用程序级别):

compileOptions {
 sourceCompatibility JavaVersion.VERSION_1_8
 targetCompatibility JavaVersion.VERSION_1_8
}

这是我的 build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.placepicker"
        minSdkVersion 24
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-places-v9:0.12.0'

}

关于java - MapBox 地点选择器导致致命信号 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61763807/

相关文章:

java - 如何在 Ubuntu 上安装 Intellij IDEA?

java - 在父类(super class)中定义对私有(private)子类成员的相同处理

javascript - 无法看到 MapBox React Native GL 注释

java - 两个 Java 日期之间的正确周期

java - 文件中的空行

android - 禁用 mapView 的硬件加速会导致不断重绘

android - 如何以天为单位显示日期差异?

php - 将条形码 ID 作为输入传递给 HTML 表单

javascript - 在 MapBox 中的两个标记之间绘制线性动画线

zooming - map 最大程度缩小时允许捏合缩放手势