【问题标题】:getOrientationMatrix causes the app to crashgetOrientationMatrix 导致应用程序崩溃
【发布时间】:2014-04-22 23:12:55
【问题描述】:

我在尝试获取设备方向时使用了SensorManager.getOrientation(matrixR, orientationMatrix);,如下所示。但我不知道为什么SensorManager.getOrientation(matrixR, orientationMatrix);,正如 logcat 所暗示的那样,它会导致应用程序崩溃?我试图省略SensorManager.getOrientation(matrixR, orientationMatrix); 并且应用程序运行正常。请帮我解决这个问题

Java代码:

if (accelerometerValues != null && magnetometerValues != null) {
        float [] matrixR = new float[3];
        float [] matrixI = new float[3];
        boolean success = SensorManager.getRotationMatrix(matrixR, matrixI,   
        accelerometerValues, magnetometerValues);
        if (success) {
            float [] orientationMatrix = new float[3];
            SensorManager.getOrientation(matrixR, orientationMatrix);
            tvAzimuthReading.setText(Float.toString(orientationMatrix[0]));
            tvPitchReading.setText(Float.toString(orientationMatrix[1]));
            tvRollReading.setText(Float.toString(orientationMatrix[2]));
        } else {
            Toast.makeText(getApplicationContext(), "No Rmatrix", Toast.LENGTH_LONG).show();
        }
    }

Logcat:

04-23 02:01:50.476: D/dalvikvm(24772): GC_FOR_ALLOC freed 144K, 21% free 10121K/12664K,  
paused 11ms, total 11ms
04-23 02:01:50.481: I/dalvikvm-heap(24772): Grow heap (frag case) to 13.294MB for 
1127536-byte allocation
04-23 02:01:50.491: D/dalvikvm(24772): GC_FOR_ALLOC freed 2K, 19% free 11221K/13768K, 
paused 11ms, total 11ms
04-23 02:01:50.521: D/SensorManager(24772): registerListener :: create queue :: handler   
= 0, name = LSM330DLC Acceleration Sensor, delay = 200000, 
04-23 02:01:50.521: D/SensorManager(24772): registerListener :: handler = 1, name =  
AK8963C Magnetic field Sensor, delay = 200000, 
04-23 02:01:50.596: D/libEGL(24772): loaded /system/lib/egl/libEGL_mali.so
04-23 02:01:50.601: D/libEGL(24772): loaded /system/lib/egl/libGLESv1_CM_mali.so
04-23 02:01:50.601: D/libEGL(24772): loaded /system/lib/egl/libGLESv2_mali.so
04-23 02:01:50.606: E/(24772): Device driver API match
04-23 02:01:50.606: E/(24772): Device driver API version: 23
04-23 02:01:50.606: E/(24772): User space API version: 23 
04-23 02:01:50.606: E/(24772): mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Fri Nov 29   
14:18:37 KST 2013 
04-23 02:01:50.676: D/OpenGLRenderer(24772): Enabling debug mode 0
04-23 02:01:50.781: E/SensorManager(24772): Exception dispatching input event.
04-23 02:01:50.781: D/AndroidRuntime(24772): Shutting down VM
04-23 02:01:50.781: W/dalvikvm(24772): threadid=1: thread exiting with uncaught    
exception (group=0x41c11700)
04-23 02:01:50.786: E/AndroidRuntime(24772): FATAL EXCEPTION: main
04-23 02:01:50.786: E/AndroidRuntime(24772): java.lang.ArrayIndexOutOfBoundsException:  
length=3; index=5
04-23 02:01:50.786: E/AndroidRuntime(24772):    at   
android.hardware.SensorManager.getOrientation(SensorManager.java:1135)
04-23 02:01:50.786: E/AndroidRuntime(24772):    at   
com.example.sensortest01.SensorTest01.onSensorChanged(SensorTest01.java:122)
04-23 02:01:50.786: E/AndroidRuntime(24772):    at      

【问题讨论】:

    标签: android android-sensors android-orientation sensormanager


    【解决方案1】:

    尝试将您的matrixRmatrixI 定义如下:

    float [] matrixR = new float[9];
    float [] matrixI = new float[9];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-21
      • 2016-06-04
      • 2011-08-24
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      相关资源
      最近更新 更多