java.lang.IndexOutOfBoundsException:索引:10,大小:10
请不要在阅读前将此问题标记为重复。我是java新手,正在开发一个应用程序,这是我面临的问题java.lang.IndexOutOfBoundsException:索引:10,大小:10,java,android,Java,Android,请不要在阅读前将此问题标记为重复。我是java新手,正在开发一个应用程序,这是我面临的问题 java.lang.IndexOutOfBoundsException: Index: 10, Size: 10 当我点击列表的最后一项时。我知道我的数组类似于0-9,所以如果我使用10作为数字,那么我将得到错误。我的代码如下 private class Page { private int mIndx; private ArrayList<HashMap<String,
java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
当我点击列表的最后一项时。我知道我的数组类似于0-9,所以如果我使用10作为数字,那么我将得到错误。我的代码如下
private class Page {
private int mIndx;
private ArrayList<HashMap<String, String>> mQuotes;
private Page(int indx, ArrayList<HashMap<String, String>> quoteList) {
mQuotes = quoteList;
mIndx = indx;
}
private HashMap<String, String> getQuote(int indx) {
return mQuotes.get(indx);
}
}
完整日志在这里
Process:com.karopass.gujarati_status,PID:6865
java.lang.IndexOutOfBoundsException:索引:10,大小:10
获取(ArrayList.java:411)
在com.karopass.gujarati_status.material.QuoteViewActivity$Page.getQuote(QuoteViewActivity.java:703)
在com.karopass.gujarati_status.material.QuoteViewActivity$Page.access$1000(QuoteViewActivity.java:690)
在com.karopass.gujarati_status.material.QuoteViewActivity.getQuote(QuoteViewActivity.java:653)
在com.karopass.gujarati_status.material.QuoteViewActivity.access$800(QuoteViewActivity.java:48)
位于com.karopass.gujarati_status.material.QuoteViewActivity$QuoteFragmentAdapter.getItem(QuoteViewActivity.java:632)
位于android.support.v4.app.FragmentStatePagerAdapter.InstanceItem(FragmentStatePagerAdapter.java:109)
位于android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1034)
位于android.support.v4.view.ViewPager.populate(ViewPager.java:1248)
位于android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
在android.support.v4.view.ViewPager.onMeasure上(ViewPager.java:1642)
在android.view.view.measure(view.java:19965)
位于android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)上
在android.view.view.measure(view.java:19965)
位于android.widget.LinearLayout.measureVertical(LinearLayout.java:911)
位于android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
在android.view.view.measure(view.java:19965)
位于android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)上
在android.view.view.measure(view.java:19965)
位于android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6087)
位于android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)
位于android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
位于android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1391)
位于android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:784)
在android.view.view.measure(view.java:19965)
位于android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6087)
位于android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
位于android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
在android.view.view.measure(view.java:19965)
位于android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6087)
位于android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
位于android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
位于android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
private class Page {
public static int postion;
private int mIndx;
private ArrayList<HashMap<String, String>> mQuotes;
private Page(int indx, ArrayList<HashMap<String, String>> quoteList) {
mQuotes = quoteList;
mIndx = indx;
}
private HashMap<String, String> getQuote(int indx) {
if(indx == mQuotes.size())
{
postion = indx- 1;
}
else{
postion = indx;
}
return mQuotes.get(postion);
}
}
private HashMap<String, String> getQuote(int position) {
int pageIndx = ((position + 1) / QuotesListFragment.ITEMS_PER_PAGE) + (((position + 1) % QuotesListFragment.ITEMS_PER_PAGE) > 0 ? 1 : 0);
Page page = mQuotePages.get(pageIndx);
if (page == null) {
page = loadQuotePage(pageIndx);
}
int quoteIndxOfPage = position % QuotesListFragment.ITEMS_PER_PAGE;
return page.getQuote(quoteIndxOfPage);
}
public Cursor getQuotesByPage(int quotesType,String author,int pageIndx,int numOfItems){
int offset=(pageIndx-1)*numOfItems;
switch(quotesType){
case 1:
return getQuotes(offset,numOfItems);
case 2:
return getFavoriteQuotes(offset,numOfItems);
case 3:
return getAuthorQuotes(author,offset,numOfItems);
case 4:
return getAuthorQuotesTopLiked(author, offset, numOfItems);
case 5:
return getAuthorQuotesTopShared(author, offset, numOfItems);
case 6:
return getQuotesTopLiked(offset,numOfItems);
case 7:
return getQuotesTopShared(offset,numOfItems);
}
return null;
}
public Cursor getQuotes(int offset,int limit) {
// Select All Query
if (String.valueOf(offset).equals("50000")) {
String query_count = "SELECT COUNT(" + QU_ID + ") AS count FROM "
+ TABLE_QUOTES;
Cursor c_count = database.rawQuery(query_count, null);
c_count.moveToFirst();
Integer count = c_count.getInt(c_count.getColumnIndex("count"));
limit =count;// String.valueOf(count);
}
String query = "SELECT * FROM " + TABLE_QUOTES + " JOIN "
+ TABLE_AUTHORS + " ON " + QU_AUTHOR + " = " + AU_WEB_ID
+ " ORDER BY " + QU_ID + " DESC "+ " LIMIT " + offset+","+limit;
//Log.i("query",query);
Cursor cursor = database.rawQuery(query, null);
cursor.moveToFirst();
return cursor;
}
if(indx == mQuotes.size())
if(indx == mQuotes.size()-1)
private HashMap<String, String> getQuote(int indx) { if(indx>= mQuotes.size()) { return null;} else{return mQuotes.get(indx); }}