我是android的新手,我不知道为什么我会得到以下错误。我已经尝试了所有可能的解决方案,但对我不起作用。它没有显示发生实际错误的任何行号。
我尝试了不同的方法和解决方案,另外一种方式当我尝试使用适配器和其他它工作正常但我希望它用这种方式..
java.lang.IndexOutOfBoundsException
at android.graphics.Paint.getRunAdvance(Paint.java:2360)
at android.text.TextLine.handleText(TextLine.java:750)
at android.text.TextLine.handleRun(TextLine.java:900)
at android.text.TextLine.measureRun(TextLine.java:419)
at android.text.TextLine.measure(TextLine.java:298)
at android.text.TextLine.metrics(TextLine.java:272)
at android.text.Layout.getLineExtent(Layout.java:1131)
at android.text.Layout.drawText(Layout.java:428)
at android.text.Layout.draw(Layout.java:298)
at android.widget.Editor.onDraw(Editor.java:1575)
at android.widget.TextView.onDraw(TextView.java:5861)
at android.view.View.draw(View.java:16381)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.draw(View.java:16291)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.draw(View.java:16384)
at android.widget.ScrollView.draw(ScrollView.java:1873)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.draw(View.java:16384)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.draw(View.java:16291)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.draw(View.java:16291)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.draw(View.java:16291)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.draw(View.java:16291)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.draw(View.java:16384)
at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2692)
at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:3045)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2955)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2740)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2358)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1233)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6552)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:919)
at android.view.Choreographer.doCallbacks(Choreographer.java:710)
at android.view.Choreographer.doFrame(Choreographer.java:645)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:905)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5582)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
以下是我的Java代码
public class CategoryList extends AppCompatActivity implements OnClickListener {
Button[] ChapterButton;
String[] ChapterName;
String[] ChapterNumber;
int TotalChapters = 2;
Bundle basket;
ImageButton btnSearch;
ImageButton btninfo;
ImageButton btnsettings;
ImageButton btnshare;
Typeface font;
Intent f1i;
int[] id;
int[] idiv;
TextView tvheading;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.categorylist);
initializeData();
}
private void initializeData() {
ChapterName = getResources().getStringArray(R.array.ChapterName);
ChapterNumber = getResources().getStringArray(R.array.ChapterNumber);
font = Typeface.createFromAsset(getAssets(), "ERASMD.TTF");
tvheading = (TextView) findViewById(R.id.tvHeadingtxt);
tvheading.setTypeface(font);
ChapterButton = new Button[TotalChapters];
f1i = new Intent(this, MainActivity.class);
basket = new Bundle();
f1i.putExtra("clearCache", true);
id = new int[TotalChapters];
idiv = new int[TotalChapters];
id[0] = R.id.btn1;
id[1] = R.id.btn2;
for (int start = 0; start < TotalChapters; start++) {
ChapterButton[start] = (Button) findViewById(id[start]);
ChapterButton[start].setText(ChapterNumber[start]);
ChapterButton[start].append(Html.fromHtml("<br/>" + ChapterName[start]));
ChapterButton[start].setTypeface(font);
ChapterButton[start].setOnClickListener(this);
ChapterButton[start].setPadding(5, 10, 5, 10);
}
btnshare = (ImageButton) findViewById(R.id.btnshare);
btnsettings = (ImageButton) findViewById(R.id.btnsettings);
btninfo = (ImageButton) findViewById(R.id.btninfo);
btnSearch = (ImageButton) findViewById(R.id.btnsearch);
btnshare.setOnClickListener(this);
btnsettings.setOnClickListener(this);
btninfo.setOnClickListener(this);
btnSearch.setOnClickListener(this);
}
<string-array name="ChapterNumber">
<item>1</item>
<item>2</item>
</string-array>
<string-array name="ChapterName">
<item>View by</item>
<item>View by</item>
</string-array>