-1
    ares = null;
    adob = null;
    ares = tres.split("-");
    if (!ares[0].toString().equals("0")) {
        for (int i = 0; i <= ares.length - 1; i++) {
            adob = ares[i].toString().split(",");
            // txtv = new TextView(Albums.this);
            valueTV = new TextView(Albums.this);
            valueTV.setText(adob[0].toString() + "[" + adob[1].toString()
                    + "]"); // Here I am Getting Exception !
            // valueTV.setId(i);
            valueTV.setGravity(Gravity.CENTER);
            valueTV.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            valueTV.setTextSize(20);
            valueTV.setTextColor(Color.BLUE);
            valueTV.setClickable(true);

Error LogCat is

08-26 14:35:00.945: W/dalvikvm(21180): threadid=1: thread exiting with uncaught exception (group=0x409e61f8)
08-26 14:35:00.975: D/dalvikvm(21180): GC_CONCURRENT freed 218K, 4% free 6798K/7047K, paused 2ms+3ms
08-26 14:35:00.975: E/AndroidRuntime(21180): FATAL EXCEPTION: main
08-26 14:35:00.975: E/AndroidRuntime(21180): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.pixitch/com.app.pixitch.Albums}: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
08-26 14:35:00.975: E/AndroidRuntime(21180):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at android.os.Looper.loop(Looper.java:137)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at android.app.ActivityThread.main(ActivityThread.java:4424)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at java.lang.reflect.Method.invokeNative(Native Method)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at java.lang.reflect.Method.invoke(Method.java:511)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at dalvik.system.NativeStart.main(Native Method)
08-26 14:35:00.975: E/AndroidRuntime(21180): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
08-26 14:35:00.975: E/AndroidRuntime(21180):    at com.app.pixitch.Albums.onCreate(Albums.java:79)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at android.app.Activity.performCreate(Activity.java:4492)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-26 14:35:00.975: E/AndroidRuntime(21180):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-26 14:35:00.975: E/AndroidRuntime(21180):    ... 11 more

when I Debug the program step by step its working nice. When I run the program without debugging it giving error like

Unable to start activity ComponentInfo{com.app.pixitch/com.app.pixitch.Albums}: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1

PS.

Line 79: valueTV.setText(adob[0].toString() + "[" + adob[1].toString() + "]");

4

2 回答 2

0

Put This Code in postExecute() of PrevAlb() asynctask rather in onCreate() method.

ares = tres.split("-");
    if (!ares[0].toString().equals("0")) {
        for (int i = 0; i <= ares.length - 1; i++) {
            adob = ares[i].toString().split(",");
            // txtv = new TextView(Albums.this);
            valueTV = new TextView(Albums.this);
            valueTV.setText(adob[0].toString() + "[" + adob[1].toString()
                    + "]");
            // valueTV.setId(i);
            valueTV.setGravity(Gravity.CENTER);
            valueTV.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            valueTV.setTextSize(20);
            valueTV.setTextColor(Color.BLUE);
            valueTV.setClickable(true);
            valueTV.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    imgArrayList = null;
                    new GetAlb(adob[2].toString().trim()).execute();
                    if (!strimgurls[0].toString().equals("0")) {
                        for (int j = 0; j <= strimgurls.length - 1; j++) {
                            String[] tmpimgurls = strimgurls[j].toString()
                                    .split("_");
                            String extn = strimgurls[j]
                                    .toString()
                                    .trim()
                                    .substring(
                                            strimgurls[j].toString().trim()
                                                    .lastIndexOf("."));
                            String fname = strimgurls[j].toString().trim()
                                    .replace(extn, "_b" + extn);
                            String temp = methods.albimg.trim()
                                    + tmpimgurls[1].toString() + "/"
                                    + tmpimgurls[2].toString() + "/"
                                    + tmpimgurls[3].toString() + "/"
                                    + fname.trim();
                            imgArrayList.add(temp.trim());
                        }
                        String[] imgulls = imgArrayList
                                .toArray(new String[imgArrayList.size()]);
                        Intent i = new Intent(Albums.this,
                                ImageGridActivity.class);
                        i.putExtra("imgurls", imgulls);
                        startActivity(i);
                    }
                }
            });
            lnrLayout.addView(valueTV);
        }
    }
于 2013-08-26T09:23:54.780 回答
0
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1

Your Exception Telling you the Everything

your adob has length=1 i.e only index 0 can be accessed adob[0] and you are trying to access the index 1 adob[1] which doesn't Exist

Change

 valueTV.setText(adob[0].toString() + "[" + adob[1].toString() + "]");

To

if(adob!=null && adob.length>=2)
{
      valueTV.setText(adob[0].toString() + "[" + adob[1].toString() + "]");
}
于 2013-08-26T09:31:21.713 回答