当我们更改Android手机方向时,我们收到以下错误。目前在android v 5和4.4.4中测试这个。我们的应用程序被锁定为肖像。因此,如果我们将手机转为横向模式,视图将不会更改,但会保持纵向模式。
当我们将手机方向更改为横向时,会抛出此异常并且应用程序崩溃。这将永远无法复制。但是,一旦在10或15次,应用程序崩溃与以下错误。即使它是随机的,也可以不断复制。如果我们在任何特定时间扭动手机但可能不确定。我经常在登录或退出操作期间扭动手机,这需要几秒钟才能完成这些操作。
不会从特定活动或代码段抛出此异常。正如我在帖子中提到的那样,当我在10或15次随机的任何视图上改变手机方向时会抛出这种情况。但是无法不断复制。
以下是完整的堆栈跟踪。
java.lang.ArrayIndexOutOfBoundsException: length=3; index=-2147483648
at android.widget.GridLayout$Axis.groupArcsByFirstVertex(GridLayout.java:1413)
at android.widget.GridLayout$Axis$1.<init>(GridLayout.java:1432)
at android.widget.GridLayout$Axis.topologicalSort(GridLayout.java:1429)
at android.widget.GridLayout$Axis.topologicalSort(GridLayout.java:1468)
at android.widget.GridLayout$Axis.createArcs(GridLayout.java:1502)
at android.widget.GridLayout$Axis.getArcs(GridLayout.java:1516)
at android.widget.GridLayout$Axis.computeLocations(GridLayout.java:1687)
at android.widget.GridLayout$Axis.getLocations(GridLayout.java:1708)
at android.widget.GridLayout$Axis.getMeasure(GridLayout.java:1729)
at android.widget.GridLayout$Axis.getMeasure(GridLayout.java:1740)
at android.widget.GridLayout.onMeasure(GridLayout.java:1056)
at android.view.View.measure(View.java:16557)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16557)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1226)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.widget.ScrollView.onMeasure(ScrollView.java:326)
at android.view.View.measure(View.java:16557)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16557)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16557)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16557)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:868)
at android.view.View.measure(View.java:16557)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16557)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
at android.view.View.measure(View.java:16557)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16557)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1942)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1132)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1321)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1019)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5725)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.sys
答案 0 :(得分:-1)
您可以覆盖活动中的onConfigurationChanged,并在每次更改方向时更新阵列。
diff(x-y) <= 1
您还需要将android:configChanges添加到您的活动中:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// Update your array here
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
// Update your array here
}
}
当方向更改时,此代码将停止重新启动您的活动。但是这可能不起作用,因为我不知道你的代码是什么样的。