有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

运行google maps API v2约20分钟时出现java JNI错误

我正在编写一个应用程序,它使用谷歌地图API v2不断标记你的位置和方向。到目前为止,该应用程序的工作方式是,标记会随着您的位置和方向发生变化,但大约20分钟后,该应用程序会崩溃,并显示“JNI错误(应用程序错误):全局引用表溢出(max=51200)消息”在代码中,我基本上注册了一个用于GPS定位的位置监听器,以及一个用于定向的加速计和磁场监听器。在位置更新时,我将当前位置存储在一个私有字段中。在传感器更新中,我将旋转存储在一个私有字段中,并更新我的谷歌地图标记的位置。我已经在下面粘贴了相关代码

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    setUpMapIfNeeded();

    // Set up GPS and sensors
    mGoogleApiClient = new GoogleApiClient.Builder(this)
           .addConnectionCallbacks(this)
           .addOnConnectionFailedListener(this)
           .addApi(LocationServices.API)
           .build(););

   mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
   mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
   mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

}

private void setUpMapIfNeeded() {
   // Do a null check to confirm that we have not already instantiated the map.   
   if (mMap == null) {
      // Try to obtain the map from the SupportMapFragment.
      mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
             .getMap();
   }
}

protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

protected void onResume() {
    super.onResume();
    setUpMapIfNeeded();
    if (mGoogleApiClient.isConnected())
        startLocationUpdates();

    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
    mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_UI);
}

protected void onPause() {
    super.onPause();
    LocationServices.FusedLocationApi.removeLocationUpdates(
            mGoogleApiClient, this);

    mSensorManager.unregisterListener(this);
}

protected void onStop() {
    mGoogleApiClient.disconnect();
    super.onStop();
}

@Override
public void onConnected(Bundle bundle) {
    // Get the last known location and update map view to that location
    mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(
            mGoogleApiClient);
    if (mMarker == null) {
        mMarker = createMarker(mCurrentLocation, mMarker, mRotation, R.drawable.arrow);
    } else {
        setMarkerToLocation(mCurrentLocation, mMarker, mRotation);
    }

    // Set up location updates
    mLocationRequest = new LocationRequest();
    // Set interval to be 1 second
    mLocationRequest.setInterval(1000)
            // Set fastest interval to be 1 second
            .setFastestInterval(1000)
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    startLocationUpdates();
}

private Marker createMarker(Location location, Marker marker,
                            float rotation, int drawableId) {
    if (mMap != null) {
        if (location != null) {
            marker = mMap.addMarker(new MarkerOptions()
                    .position(new LatLng(location.getLatitude(),
                            location.getLongitude()))
                    .anchor(0.5f, 0.5f) //Set anchor to middle of marker
                    .rotation(rotation)
                    .icon(BitmapDescriptorFactory.fromResource(drawableId)));
        }
    }
    return marker;
}

private void setMarkerToLocation(Location location, Marker marker,
                                 float rotation) {
    if (mMap != null && location != null) {
        marker.setPosition(new LatLng(location.getLatitude(),
                location.getLongitude()));
        marker.setRotation(rotation);
    }
}

protected void startLocationUpdates() {
    LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);
}

@Override
public void onLocationChanged(Location location) {
    mCurrentLocation = location;
}

@Override
public void onSensorChanged(SensorEvent event) {

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        mGravity = lowpass(event.values, mGravity);
    }
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        mGeomagnetic = lowpass(event.values, mGeomagnetic);
    }

    if (mGravity != null && mGeomagnetic != null) {
        float RotMatrix[] = new float[9];
        float IncMatrix[] = new float[9];
        if (SensorManager.getRotationMatrix(RotMatrix, IncMatrix, mGravity, mGeomagnetic)) {
            float orientation[] = new float[3];
            SensorManager.getOrientation(RotMatrix, orientation);
            mRotation = (float) Math.toDegrees(orientation[0]);
            if (mMarker == null) {
                mMarker = createMarker(mCurrentLocation, mMarker, mRotation, R.drawable.arrow);
            } else {
                setMarkerToLocation(mCurrentLocation, mMarker, mRotation);
            }
        }

    }
}

下面是我的logcat输出的一个片段:

A/art﹕ art/runtime/indirect_reference_table.cc:98] JNI ERROR (app bug): global reference table overflow (max=51200)
A/art﹕ art/runtime/indirect_reference_table.cc:98] global reference table dump:
A/art﹕ art/runtime/indirect_reference_table.cc:98]   Last 10 entries (of 51200):
A/art﹕ art/runtime/indirect_reference_table.cc:98]     51199: 0x17b68580 com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]     51198: 0x17b68520 com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]     51197: 0x17b684c0 com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]     51196: 0x17b68460 com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]     51195: 0x17b68380 com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]     51194: 0x17b68320 com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]     51193: 0x17b682c0 com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]     51192: 0x17b68260 com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]     51191: 0x17b68200 com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]     51190: 0x17b681a0 com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]   Summary:
A/art﹕ art/runtime/indirect_reference_table.cc:98]       971 of com.google.安卓.gms.clearcut.a.h (971 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of 安卓.view.ViewRootImpl$AccessibilityInteractionConnection
A/art﹕ art/runtime/indirect_reference_table.cc:98]      2322 of com.google.安卓.gms.clearcut.a.h (2322 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of 安卓.view.inputmethod.InputMethodManager$ControlledInputConnectionWrapper
A/art﹕ art/runtime/indirect_reference_table.cc:98]      2057 of com.google.安卓.gms.clearcut.a.h (2057 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of dalvik.system.VMRuntime
A/art﹕ art/runtime/indirect_reference_table.cc:98]       141 of com.google.安卓.gms.clearcut.a.h (141 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of 安卓.hardware.SystemSensorManager$SensorEventQueue
A/art﹕ art/runtime/indirect_reference_table.cc:98]      7212 of com.google.安卓.gms.clearcut.a.h (7212 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         2 of 安卓.app.LoadedApk$ServiceDispatcher$InnerConnection (2 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]      3145 of com.google.安卓.gms.clearcut.a.h (3145 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of 安卓.opengl.EGLDisplay
A/art﹕ art/runtime/indirect_reference_table.cc:98]         4 of com.google.安卓.gms.clearcut.a.h (4 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of 安卓.opengl.EGLDisplay
A/art﹕ art/runtime/indirect_reference_table.cc:98]       279 of com.google.安卓.gms.clearcut.a.h (279 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of float[] (16 elements)
A/art﹕ art/runtime/indirect_reference_table.cc:98]      1812 of com.google.安卓.gms.clearcut.a.h (1812 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of 安卓.view.ViewRootImpl$W
A/art﹕ art/runtime/indirect_reference_table.cc:98]      1610 of com.google.安卓.gms.clearcut.a.h (1610 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of java.lang.ref.WeakReference
A/art﹕ art/runtime/indirect_reference_table.cc:98]         4 of com.google.安卓.gms.clearcut.a.h (4 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         5 of java.lang.ref.WeakReference (5 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]         5 of java.lang.ref.WeakReference (5 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]        10 of java.lang.ref.WeakReference (10 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]         3 of java.lang.ref.WeakReference (3 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]       467 of com.google.安卓.gms.clearcut.a.h (467 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of 安卓.view.WindowManagerGlobal$1
A/art﹕ art/runtime/indirect_reference_table.cc:98]      3925 of com.google.安卓.gms.clearcut.a.h (3925 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of 安卓.opengl.EGLSurface
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of com.google.安卓.gms.clearcut.a.h
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of 安卓.opengl.EGLSurface
A/art﹕ art/runtime/indirect_reference_table.cc:98]       624 of com.google.安卓.gms.clearcut.a.h (624 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of java.lang.Class
A/art﹕ art/runtime/indirect_reference_table.cc:98]       274 of com.google.安卓.gms.clearcut.a.h (274 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]        15 of java.lang.Class (13 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]        18 of com.google.安卓.gms.clearcut.a.h (18 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         5 of java.lang.Class (1 unique instances)
A/art﹕ art/runtime/indirect_reference_table.cc:98]         1 of com.google.安卓.gms.clearcut.a.h

共 (0) 个答案