我只在Sony设备上报告了ArrayIndexOutOfBoundsException
错误,例如 - (D6603,SGP521)与Android 5.1.1。
我在堆栈跟踪中的代码行是对Activity.setContentView()的调用。感谢。
堆栈跟踪: -
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blacklight.klondike.patience.solitaire/com.blacklight.klondike.patience.solitaire.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=6; index=6
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5373)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
Caused by java.lang.ArrayIndexOutOfBoundsException: length=6; index=6
at android.content.res.Resources.toPreloadCookie(Resources.java:2491)
at android.content.res.Resources.loadDrawable(Resources.java:2519)
at android.content.res.Resources.getDrawable(Resources.java:828)
at android.content.Context.getDrawable(Context.java:403)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3640)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3687)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:372)
at android.app.Activity.setContentView(Activity.java:2145)
at com.blacklight.klondike.patience.ParentActivity.onCreate(ParentActivity.java:430)
at com.blacklight.klondike.patience.solitaire.MainActivity.onCreate(MainActivity.java:80)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5373)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
ParentActivity -
public class ParentActivity extends FragmentActivity implements OnClickListener/*,ButtonNeedsUpdateDelegate*/ {
@Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.full_game_layout);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
initFacebook(savedInstanceState);
}
}
R.layout.full_game_layout -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/home_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/ads_size"
android:visibility="invisible" >
<LinearLayout
android:id="@+id/daily_topbar"
android:layout_width="match_parent"
android:layout_height="@dimen/Daily_top_bar_h"
android:layout_alignParentTop="true"
android:background="@drawable/daily_shape"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:id="@+id/daily_home_caller"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight=".20"
android:gravity="center"
android:layout_height="match_parent"
>
<com.blacklight.klondike.patience.customviews.RobotoMTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="02"
android:textColor="@color/dark_grey"
android:id="@+id/daily_home_date"
android:textSize="@dimen/xlarge_text"
android:gravity="center|bottom"
android:layout_gravity="bottom"
/>
<com.blacklight.klondike.patience.customviews.RobotoMTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Feb"
android:id="@+id/daily_home_month"
android:gravity="center|top"
android:layout_gravity="top"
android:textColor="@color/grey_color"
android:textSize="@dimen/small_text"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="@dimen/home_divider_h"
android:layout_height="match_parent"
android:background="@color/black_transparent_1"></LinearLayout>
<LinearLayout
android:id="@+id/daily_home_caller1"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight=".60"
android:gravity="center"
android:layout_height="match_parent"
>
<com.blacklight.klondike.patience.customviews.RobotoMTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/popup_title_color"
android:text="@string/daily_clng"
android:textSize="@dimen/small_med_text"
android:gravity="center|bottom"
android:layout_gravity="bottom"
/>
<LinearLayout
android:baselineAligned="false"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<com.blacklight.klondike.patience.customviews.RobotoMTextView
android:id="@+id/daily_home_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/large_text"
android:textColor="@color/grey_color"
/>
<com.blacklight.klondike.patience.customviews.RobotoMTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/time_left"
android:layout_marginLeft="@dimen/margin_5"
android:layout_marginStart="@dimen/margin_5"
android:textSize="@dimen/small_med_text"
android:textColor="@color/grey_color"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/yesterday_leaderboard"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight=".20"
android:gravity="center"
android:background="@drawable/ldb_right_round_corner"
android:layout_height="match_parent"
android:layout_marginBottom="1dp">
<ImageView
android:layout_width="@dimen/radio_size"
android:layout_height="@dimen/radio_size"
android:src="@drawable/daily_leaderboard"
/>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/Daily_top_bar_h"
android:layout_alignParentTop="true"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="@dimen/radio_size"
android:id="@+id/right_tick"
android:src="@drawable/right_tick"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="@dimen/home_screen_padding"
android:layout_marginStart="@dimen/home_screen_padding"
android:visibility="invisible"/>
</RelativeLayout>
<LinearLayout
android:id="@+id/play_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/daily_topbar"
android:layout_above="@+id/pager_include"
android:gravity="center"
android:orientation="vertical"
android:layout_toRightOf="@+id/home_setting"
android:layout_toEndOf="@+id/home_setting"
android:layout_toLeftOf="@+id/home_achivements"
android:layout_toStartOf="@+id/home_achivements"
android:layout_marginRight="@dimen/home_screen_padding"
android:layout_marginEnd="@dimen/home_screen_padding"
android:layout_marginStart="@dimen/home_screen_padding"
android:layout_marginLeft="@dimen/home_screen_padding">
<ImageView
android:id="@+id/symbol_img"
android:layout_width="@dimen/logo_dimen"
android:layout_height="@dimen/logo_dimen"
android:src="@drawable/taptoplay_1"
tools:ignore="ContentDescription" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/home_screen_padding"
android:gravity="center"
android:orientation="vertical" >
<com.blacklight.klondike.patience.customviews.RobotoLTextView
android:id="@+id/home_play"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/tap_to_play"
android:textColor="@color/dark_grey"
android:textSize="@dimen/med_large_text" />
</LinearLayout>
<com.blacklight.klondike.patience.customviews.RobotoLTextView
android:id="@+id/game_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_5"
android:gravity="center"
android:text=""
android:textColor="@color/dark_grey"
android:textSize="@dimen/small_text" />
</LinearLayout>
<LinearLayout
android:id="@+id/plus_view"
android:layout_width="@dimen/theme_icn_w"
android:layout_height="wrap_content"
android:layout_above="@+id/pager_include"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/home_screen_padding"
android:orientation="vertical" >
</LinearLayout>
<include
android:id="@+id/pager_include"
android:layout_width="wrap_content"
android:layout_height="@dimen/home_pager_h"
android:layout_above="@+id/dot_view"
android:layout_centerHorizontal="true"
layout="@layout/home_stats_view"/>
<!--layout="@layout/home_stats_view"-->
<LinearLayout
android:id="@+id/dot_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="@dimen/margin_5"
android:paddingTop="@dimen/margin_5" >
<ImageView
android:id="@+id/page_indicator1"
android:layout_width="@dimen/dot_size"
android:layout_height="@dimen/dot_size" />
<ImageView
android:id="@+id/page_indicator2"
android:layout_width="@dimen/dot_size"
android:layout_height="@dimen/dot_size"
android:layout_marginLeft="@dimen/dot_size"
android:layout_marginRight="@dimen/dot_size" />
<ImageView
android:id="@+id/page_indicator3"
android:layout_width="@dimen/dot_size"
android:layout_height="@dimen/dot_size" />
</LinearLayout>
<ImageView
android:id="@+id/home_setting"
android:layout_width="@dimen/home_screen_icn_dimen"
android:layout_height="@dimen/home_screen_icn_dimen"
android:layout_above="@+id/pager_include"
android:layout_alignParentLeft="true"
android:layout_marginBottom="@dimen/home_screen_padding"
android:layout_marginLeft="@dimen/home_screen_padding"
android:src="@drawable/settings_1"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/self_managed_button"
android:layout_width="@dimen/home_screen_icn_dimen"
android:layout_height="@dimen/home_screen_icn_dimen"
android:layout_alignParentRight="true"
android:layout_above="@+id/more_games"
android:layout_marginBottom="@dimen/home_screen_padding"
android:layout_marginRight="@dimen/home_screen_padding"
android:visibility="invisible" />
<ImageView
android:id="@+id/more_games"
android:layout_width="@dimen/home_screen_icn_dimen"
android:layout_height="@dimen/home_screen_icn_dimen"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/home_setting"
android:layout_marginRight="@dimen/home_screen_padding"
android:background="@drawable/moregames_selector" />
<LinearLayout
android:layout_width="@dimen/home_screen_icn_dimen"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/daily_topbar"
android:layout_marginLeft="@dimen/home_screen_padding"
android:layout_marginTop="@dimen/home_screen_padding"
android:orientation="vertical" >
<com.sessionm.api.PortalButton
android:id="@+id/portalButton"
android:layout_width="@dimen/home_screen_icn_dimen"
android:layout_height="@dimen/home_screen_icn_dimen"
android:layout_marginBottom="@dimen/home_screen_padding"
android:background="@drawable/sessionm"
android:scaleType="fitStart" >
</com.sessionm.api.PortalButton>
<ImageView
android:id="@+id/fb_invite_home"
android:layout_width="@dimen/home_screen_icn_dimen"
android:layout_height="@dimen/home_screen_icn_dimen"
android:src="@drawable/fb_invite_selector_1"
android:visibility="visible" />
</LinearLayout>
<ImageView
android:id="@+id/removeads_icon_fulllayout"
android:layout_width="@dimen/home_screen_icn_dimen"
android:layout_height="@dimen/home_screen_icn_dimen"
android:layout_above="@+id/home_setting"
android:layout_alignLeft="@+id/home_setting"
android:layout_marginBottom="@dimen/home_screen_padding"
android:src="@drawable/noadd"
android:visibility="gone" />
<Button
android:id="@+id/inviteFriends"
android:layout_width="wrap_content"
android:layout_height="@dimen/home_screen_icn_dimen"
android:layout_below="@+id/daily_topbar"
android:layout_centerHorizontal="true"
android:background="@drawable/fb_share_img"
android:gravity="center"
android:paddingLeft="@dimen/home_screen_padding"
android:paddingRight="@dimen/home_screen_padding"
android:text="SHARE To Unlock"
android:textColor="@color/white"
android:textSize="@dimen/med_large_text"
android:visibility="visible" />
</RelativeLayout>
答案 0 :(得分:0)
检查一下:
错误是
java.lang.ArrayIndexOutOfBoundsException:length = 6;指数= 6
Java数组从0开始,而不是1.这意味着第一个元素 使用
array[0]
访问数组,使用array[1]
访问数组等。 因此,要访问数组的最后一个元素,请使用array[array.length - 1]
。使用array[array.length]
是一个索引 超出范围,因此例外。
答案 1 :(得分:0)
我看到我的一个应用程序崩溃了,它与toPreloadCookie
无法解析某些资源有关(对我而言是#34;?android:colorAccent&#34;)。
我建议访问该布局中的每个drawable,并为列出的每个xml drawable查看是否有任何引用非项目范围资源并替换它。
即:?android:colorAccent
@color/colorAccent
祝你好运
答案 2 :(得分:0)
由于使用了DeviceDefault(例如Theme.DeviceDefault.Light)主题,我的应用程序发生了崩溃。
要解决此问题,我已将所有活动更改为使用Android默认主题,例如Material和Holo。