简体   繁体   中英

ArrayIndexOutOfBounds when reading a file Android

I am trying to read a file in my application The content of the file roughly looks like this:

0 1 
1 0
0 2 
2 0  
...

When I read the file I get an ArrayIndexOutOfBounds Exception This is how I read the file:

AssetManager amanager ;
    String word = null;

    try {
        amanager= getAssets();
        InputStream inputStream = amanager.open("edges.txt");
        InputStreamReader streamReader = new InputStreamReader(inputStream);
        BufferedReader breader = new BufferedReader(streamReader);
        //word 

        while((word=breader.readLine()) != null){
            String s = breader.readLine();

            String[] words =s.split(" ");

            String sx = words[0];
            String sy = words[1]; // ---LINE 200, THIS IS THE LINE WHERE THE EXCEPTION IS

            System.out.println(sx);
            System.out.println(sy);

        }
        breader.close();
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }

It reads String sx = words[0];

I have also tried initializing String[] word = new String[500]; but that didn't help.

This is what I get in my LogCat:

04-08 20:55:21.096: D/dalvikvm(1038): GC_EXTERNAL_ALLOC freed 69K, 49% free 2753K/5379K, external 1625K/2137K, paused 13ms
04-08 20:55:21.140: D/(1038): HostConnection::get() New Host Connection established 0x92f2638, tid 1038
04-08 20:55:28.404: W/KeyCharacterMap(1038): No keyboard for id 0
04-08 20:55:28.404: W/KeyCharacterMap(1038): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
04-08 20:55:35.712: I/System.out(1038): 1
04-08 20:55:35.712: I/System.out(1038): 0
04-08 20:55:35.716: I/System.out(1038): 2
04-08 20:55:35.720: I/System.out(1038): 0
04-08 20:55:35.720: I/System.out(1038): 69
04-08 20:55:35.724: I/System.out(1038): 0
04-08 20:55:35.724: I/System.out(1038): 2
04-08 20:55:35.724: I/System.out(1038): 1
04-08 20:55:35.724: I/System.out(1038): 69
04-08 20:55:35.724: I/System.out(1038): 1
04-08 20:55:35.724: I/System.out(1038): 3
04-08 20:55:35.724: I/System.out(1038): 2
04-08 20:55:35.724: I/System.out(1038): 4
04-08 20:55:35.724: I/System.out(1038): 3
04-08 20:55:35.724: I/System.out(1038): 5
04-08 20:55:35.724: I/System.out(1038): 4
04-08 20:55:35.724: I/System.out(1038): 6
04-08 20:55:35.724: I/System.out(1038): 5
04-08 20:55:35.728: I/System.out(1038): 7
04-08 20:55:35.728: I/System.out(1038): 5
04-08 20:55:35.728: I/System.out(1038): 7
04-08 20:55:35.728: I/System.out(1038): 6
04-08 20:55:35.728: I/System.out(1038): 8
04-08 20:55:35.728: I/System.out(1038): 6
04-08 20:55:35.728: I/System.out(1038): 8
04-08 20:55:35.728: I/System.out(1038): 7
04-08 20:55:35.728: I/System.out(1038): 10
04-08 20:55:35.728: I/System.out(1038): 8
04-08 20:55:35.728: I/System.out(1038): 10
04-08 20:55:35.728: I/System.out(1038): 9
04-08 20:55:35.728: I/System.out(1038): 11
04-08 20:55:35.728: I/System.out(1038): 9
04-08 20:55:35.728: I/System.out(1038): 11
04-08 20:55:35.732: I/System.out(1038): 10
04-08 20:55:35.732: I/System.out(1038): 12
04-08 20:55:35.732: I/System.out(1038): 9
04-08 20:55:35.732: I/System.out(1038): 13
04-08 20:55:35.732: I/System.out(1038): 9
04-08 20:55:35.732: I/System.out(1038): 12
04-08 20:55:35.732: I/System.out(1038): 11
04-08 20:55:35.732: I/System.out(1038): 15
04-08 20:55:35.732: I/System.out(1038): 12
04-08 20:55:35.732: I/System.out(1038): 14
04-08 20:55:35.732: I/System.out(1038): 13
04-08 20:55:35.732: I/System.out(1038): 15
04-08 20:55:35.732: I/System.out(1038): 13
04-08 20:55:35.732: I/System.out(1038): 16
04-08 20:55:35.732: I/System.out(1038): 14
04-08 20:55:35.732: I/System.out(1038): 17
04-08 20:55:35.732: I/System.out(1038): 14
04-08 20:55:35.732: I/System.out(1038): 16
04-08 20:55:35.740: I/System.out(1038): 15
04-08 20:55:35.740: I/System.out(1038): 17
04-08 20:55:35.740: I/System.out(1038): 16
04-08 20:55:35.740: I/System.out(1038): 18
04-08 20:55:35.740: I/System.out(1038): 17
04-08 20:55:35.740: I/System.out(1038): 19
04-08 20:55:35.740: I/System.out(1038): 18
04-08 20:55:35.740: I/System.out(1038): 20
04-08 20:55:35.740: I/System.out(1038): 19
04-08 20:55:35.740: I/System.out(1038): 21
04-08 20:55:35.744: I/System.out(1038): 20
04-08 20:55:35.744: I/System.out(1038): 22
04-08 20:55:35.744: I/System.out(1038): 21
04-08 20:55:35.744: I/System.out(1038): 23
04-08 20:55:35.744: I/System.out(1038): 21
04-08 20:55:35.744: I/System.out(1038): 23
04-08 20:55:35.744: I/System.out(1038): 20
04-08 20:55:35.744: I/System.out(1038): 23
04-08 20:55:35.744: I/System.out(1038): 22
04-08 20:55:35.744: I/System.out(1038): 24
04-08 20:55:35.744: I/System.out(1038): 23
04-08 20:55:35.744: I/System.out(1038): 25
04-08 20:55:35.744: I/System.out(1038): 24
04-08 20:55:35.744: I/System.out(1038): 26
04-08 20:55:35.744: I/System.out(1038): 25
04-08 20:55:35.744: I/System.out(1038): 27
04-08 20:55:35.744: I/System.out(1038): 25
04-08 20:55:35.744: I/System.out(1038): 27
04-08 20:55:35.744: I/System.out(1038): 26
04-08 20:55:35.744: I/System.out(1038): 28
04-08 20:55:35.744: I/System.out(1038): 27
04-08 20:55:35.748: I/System.out(1038): 29
04-08 20:55:35.748: I/System.out(1038): 28
04-08 20:55:35.748: I/System.out(1038): 30
04-08 20:55:35.748: I/System.out(1038): 29
04-08 20:55:35.748: I/System.out(1038): 31
04-08 20:55:35.748: I/System.out(1038): 30
04-08 20:55:35.748: I/System.out(1038): 32
04-08 20:55:35.748: I/System.out(1038): 30
04-08 20:55:35.748: I/System.out(1038): 32
04-08 20:55:35.748: I/System.out(1038): 31
04-08 20:55:35.748: I/System.out(1038): 33
04-08 20:55:35.748: I/System.out(1038): 32
04-08 20:55:35.748: I/System.out(1038): 34
04-08 20:55:35.748: I/System.out(1038): 33
04-08 20:55:35.752: I/System.out(1038): 35
04-08 20:55:35.752: I/System.out(1038): 33
04-08 20:55:35.752: I/System.out(1038): 35
04-08 20:55:35.752: I/System.out(1038): 34
04-08 20:55:35.752: I/System.out(1038): 36
04-08 20:55:35.752: I/System.out(1038): 35
04-08 20:55:35.752: I/System.out(1038): 37
04-08 20:55:35.752: I/System.out(1038): 36
04-08 20:55:35.752: I/System.out(1038): 38
04-08 20:55:35.752: I/System.out(1038): 37
04-08 20:55:35.752: I/System.out(1038): 39
04-08 20:55:35.752: I/System.out(1038): 38
04-08 20:55:35.752: I/System.out(1038): 40
04-08 20:55:35.752: I/System.out(1038): 39
04-08 20:55:35.752: I/System.out(1038): 41
04-08 20:55:35.752: I/System.out(1038): 39
04-08 20:55:35.760: I/System.out(1038): 42
04-08 20:55:35.760: I/System.out(1038): 40
04-08 20:55:35.760: I/System.out(1038): 43
04-08 20:55:35.760: I/System.out(1038): 40
04-08 20:55:35.760: I/System.out(1038): 43
04-08 20:55:35.760: I/System.out(1038): 42
04-08 20:55:35.760: I/System.out(1038): 44
04-08 20:55:35.764: I/System.out(1038): 43
04-08 20:55:35.764: I/System.out(1038): 45
04-08 20:55:35.764: I/System.out(1038): 44
04-08 20:55:35.764: I/System.out(1038): 46
04-08 20:55:35.764: I/System.out(1038): 45
04-08 20:55:35.764: I/System.out(1038): 47
04-08 20:55:35.764: I/System.out(1038): 46
04-08 20:55:35.764: I/System.out(1038): 48
04-08 20:55:35.764: I/System.out(1038): 47
04-08 20:55:35.764: I/System.out(1038): 49
04-08 20:55:35.768: I/System.out(1038): 48
04-08 20:55:35.768: I/System.out(1038): 50
04-08 20:55:35.768: I/System.out(1038): 48
04-08 20:55:35.768: I/System.out(1038): 51
04-08 20:55:35.772: I/System.out(1038): 49
04-08 20:55:35.772: I/System.out(1038): 51
04-08 20:55:35.772: I/System.out(1038): 50
04-08 20:55:35.776: I/System.out(1038): 52
04-08 20:55:35.776: I/System.out(1038): 50
04-08 20:55:35.776: I/System.out(1038): 54
04-08 20:55:35.776: I/System.out(1038): 51
04-08 20:55:35.776: I/System.out(1038): 53
04-08 20:55:35.776: I/System.out(1038): 52
04-08 20:55:35.776: I/System.out(1038): 55
04-08 20:55:35.776: I/System.out(1038): 53
04-08 20:55:35.776: I/System.out(1038): 55
04-08 20:55:35.776: I/System.out(1038): 54
04-08 20:55:35.776: I/System.out(1038): 57
04-08 20:55:35.776: I/System.out(1038): 54
04-08 20:55:35.776: I/System.out(1038): 56
04-08 20:55:35.776: I/System.out(1038): 55
04-08 20:55:35.776: I/System.out(1038): 57
04-08 20:55:35.776: I/System.out(1038): 56
04-08 20:55:35.776: I/System.out(1038): 58
04-08 20:55:35.776: I/System.out(1038): 56
04-08 20:55:35.776: I/System.out(1038): 60
04-08 20:55:35.776: I/System.out(1038): 57
04-08 20:55:35.776: I/System.out(1038): 59
04-08 20:55:35.780: I/System.out(1038): 58
04-08 20:55:35.780: I/System.out(1038): 60
04-08 20:55:35.780: I/System.out(1038): 59
04-08 20:55:35.780: I/System.out(1038): 61
04-08 20:55:35.780: I/System.out(1038): 59
04-08 20:55:35.780: I/System.out(1038): 62
04-08 20:55:35.780: I/System.out(1038): 61
04-08 20:55:35.780: I/System.out(1038): 63
04-08 20:55:35.780: I/System.out(1038): 62
04-08 20:55:35.784: I/System.out(1038): 64
04-08 20:55:35.784: I/System.out(1038): 63
04-08 20:55:35.784: I/System.out(1038): 65
04-08 20:55:35.784: I/System.out(1038): 64
04-08 20:55:35.784: I/System.out(1038): 66
04-08 20:55:35.784: I/System.out(1038): 65
04-08 20:55:35.784: I/System.out(1038): 67
04-08 20:55:35.788: I/System.out(1038): 66
04-08 20:55:35.788: I/System.out(1038): 68
04-08 20:55:35.788: I/System.out(1038): 67
04-08 20:55:35.788: I/System.out(1038): 69
04-08 20:55:35.788: I/System.out(1038): 68
04-08 20:55:35.788: I/System.out(1038): 70
04-08 20:55:35.788: I/System.out(1038): 69
04-08 20:55:35.788: D/AndroidRuntime(1038): Shutting down VM
04-08 20:55:35.788: W/dalvikvm(1038): threadid=1: thread exiting with uncaught exception (group=0xb5fac4f0)
04-08 20:55:35.792: E/AndroidRuntime(1038): FATAL EXCEPTION: main
04-08 20:55:35.792: E/AndroidRuntime(1038): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloworld3/com.example.helloworld3.FloorPlan}: java.lang.ArrayIndexOutOfBoundsException
04-08 20:55:35.792: E/AndroidRuntime(1038):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at android.os.Looper.loop(Looper.java:130)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at java.lang.reflect.Method.invokeNative(Native Method)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at java.lang.reflect.Method.invoke(Method.java:507)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at dalvik.system.NativeStart.main(Native Method)
04-08 20:55:35.792: E/AndroidRuntime(1038): Caused by: java.lang.ArrayIndexOutOfBoundsException
04-08 20:55:35.792: E/AndroidRuntime(1038):     at com.example.helloworld3.FloorPlan.onCreate(FloorPlan.java:200)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-08 20:55:35.792: E/AndroidRuntime(1038):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-08 20:55:35.792: E/AndroidRuntime(1038):     ... 11 more

EDIT :

This is the log when I just read the line without splitting :

04-08 21:11:27.520: D/dalvikvm(1151): GC_EXTERNAL_ALLOC freed 72K, 49% free 2753K/5379K, external 1625K/2137K, paused 28ms
04-08 21:11:27.612: D/(1151): HostConnection::get() New Host Connection established 0x92f2520, tid 1151
04-08 21:11:34.356: W/KeyCharacterMap(1151): No keyboard for id 0
04-08 21:11:34.356: W/KeyCharacterMap(1151): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
04-08 21:11:45.796: I/System.out(1151): 0 1
04-08 21:11:45.796: I/System.out(1151): 1 0
04-08 21:11:45.796: I/System.out(1151): 0 2
04-08 21:11:45.803: I/System.out(1151): 2 0
04-08 21:11:45.805: I/System.out(1151): 0 69
04-08 21:11:45.805: I/System.out(1151): 69 0
04-08 21:11:45.805: I/System.out(1151): 1 2
04-08 21:11:45.805: I/System.out(1151): 2 1
04-08 21:11:45.805: I/System.out(1151): 1 69
04-08 21:11:45.805: I/System.out(1151): 69 1
04-08 21:11:45.805: I/System.out(1151): 2 3
04-08 21:11:45.805: I/System.out(1151): 3 2
04-08 21:11:45.812: I/System.out(1151): 3 4
04-08 21:11:45.812: I/System.out(1151): 4 3
04-08 21:11:45.812: I/System.out(1151): 4 5
04-08 21:11:45.812: I/System.out(1151): 5 4
04-08 21:11:45.812: I/System.out(1151): 5 6 
04-08 21:11:45.812: I/System.out(1151): 6 5
04-08 21:11:45.812: I/System.out(1151): 5 7
04-08 21:11:45.812: I/System.out(1151): 7 5
04-08 21:11:45.812: I/System.out(1151): 6 7
04-08 21:11:45.812: I/System.out(1151): 7 6
04-08 21:11:45.812: I/System.out(1151): 6 8
04-08 21:11:45.812: I/System.out(1151): 8 6
04-08 21:11:45.812: I/System.out(1151): 7 8
04-08 21:11:45.816: I/System.out(1151): 8 7
04-08 21:11:45.816: I/System.out(1151): 8 10 
04-08 21:11:45.825: I/System.out(1151): 10 8
04-08 21:11:45.825: I/System.out(1151): 9 10
04-08 21:11:45.828: I/System.out(1151): 10 9
04-08 21:11:45.832: I/System.out(1151): 9 11
04-08 21:11:45.832: I/System.out(1151): 11 9
04-08 21:11:45.832: I/System.out(1151): 10 11
04-08 21:11:45.832: I/System.out(1151): 11 10
04-08 21:11:45.832: I/System.out(1151): 9 12
04-08 21:11:45.836: I/System.out(1151): 12 9
04-08 21:11:45.840: I/System.out(1151): 9 13
04-08 21:11:45.840: I/System.out(1151): 13 9
04-08 21:11:45.840: I/System.out(1151): 11 12
04-08 21:11:45.840: I/System.out(1151): 12 11
04-08 21:11:45.840: I/System.out(1151): 12 15
04-08 21:11:45.852: I/System.out(1151): 15 12
04-08 21:11:45.852: I/System.out(1151): 13 14
04-08 21:11:45.852: I/System.out(1151): 14 13
04-08 21:11:45.852: I/System.out(1151): 13 15
04-08 21:11:45.852: I/System.out(1151): 15 13
04-08 21:11:45.852: I/System.out(1151): 14 16
04-08 21:11:45.852: I/System.out(1151): 16 14
04-08 21:11:45.852: I/System.out(1151): 14 17
04-08 21:11:45.852: I/System.out(1151): 17 14
04-08 21:11:45.852: I/System.out(1151): 15 16
04-08 21:11:45.852: I/System.out(1151): 16 15
04-08 21:11:45.852: I/System.out(1151): 16 17 
04-08 21:11:45.852: I/System.out(1151): 17 16
04-08 21:11:45.852: I/System.out(1151): 17 18
04-08 21:11:45.852: I/System.out(1151): 18 17
04-08 21:11:45.852: I/System.out(1151): 18 19
04-08 21:11:45.852: I/System.out(1151): 19 18
04-08 21:11:45.852: I/System.out(1151): 19 20 
04-08 21:11:45.852: I/System.out(1151): 20 19
04-08 21:11:45.852: I/System.out(1151): 20 21
04-08 21:11:45.852: I/System.out(1151): 21 20
04-08 21:11:45.852: I/System.out(1151): 21 22
04-08 21:11:45.852: I/System.out(1151): 22 21
04-08 21:11:45.852: I/System.out(1151): 21 23
04-08 21:11:45.852: I/System.out(1151): 23 21
04-08 21:11:45.852: I/System.out(1151): 20 23
04-08 21:11:45.852: I/System.out(1151): 23 20
04-08 21:11:45.852: I/System.out(1151): 22 23
04-08 21:11:45.852: I/System.out(1151): 23 22
04-08 21:11:45.852: I/System.out(1151): 23 24
04-08 21:11:45.852: I/System.out(1151): 24 23
04-08 21:11:45.852: I/System.out(1151): 24 25
04-08 21:11:45.852: I/System.out(1151): 25 24
04-08 21:11:45.852: I/System.out(1151): 25 26
04-08 21:11:45.852: I/System.out(1151): 26 25
04-08 21:11:45.852: I/System.out(1151): 25 27
04-08 21:11:45.852: I/System.out(1151): 27 25
04-08 21:11:45.852: I/System.out(1151): 26 27
04-08 21:11:45.852: I/System.out(1151): 27 26
04-08 21:11:45.852: I/System.out(1151): 27 28
04-08 21:11:45.860: I/System.out(1151): 28 27
04-08 21:11:45.860: I/System.out(1151): 28 29
04-08 21:11:45.864: I/System.out(1151): 29 28
04-08 21:11:45.864: I/System.out(1151): 29 30
04-08 21:11:45.868: I/System.out(1151): 30 29
04-08 21:11:45.876: I/System.out(1151): 30 31
04-08 21:11:45.876: I/System.out(1151): 31 30
04-08 21:11:45.876: I/System.out(1151): 30 32
04-08 21:11:45.876: I/System.out(1151): 32 30
04-08 21:11:45.876: I/System.out(1151): 31 32
04-08 21:11:45.876: I/System.out(1151): 32 31
04-08 21:11:45.876: I/System.out(1151): 32 33
04-08 21:11:45.876: I/System.out(1151): 33 32
04-08 21:11:45.876: I/System.out(1151): 33 34
04-08 21:11:45.876: I/System.out(1151): 34 33
04-08 21:11:45.876: I/System.out(1151): 33 35
04-08 21:11:45.876: I/System.out(1151): 35 33
04-08 21:11:45.876: I/System.out(1151): 34 35
04-08 21:11:45.876: I/System.out(1151): 35 34
04-08 21:11:45.876: I/System.out(1151): 35 36
04-08 21:11:45.876: I/System.out(1151): 36 35
04-08 21:11:45.876: I/System.out(1151): 36 37
04-08 21:11:45.876: I/System.out(1151): 37 36
04-08 21:11:45.876: I/System.out(1151): 37 38
04-08 21:11:45.876: I/System.out(1151): 38 37
04-08 21:11:45.876: I/System.out(1151): 38 39
04-08 21:11:45.876: I/System.out(1151): 39 38
04-08 21:11:45.876: I/System.out(1151): 39 40
04-08 21:11:45.876: I/System.out(1151): 40 39
04-08 21:11:45.876: I/System.out(1151): 39 41
04-08 21:11:45.876: I/System.out(1151): 41 39
04-08 21:11:45.876: I/System.out(1151): 40 42
04-08 21:11:45.876: I/System.out(1151): 42 40
04-08 21:11:45.876: I/System.out(1151): 40 43
04-08 21:11:45.876: I/System.out(1151): 43 40
04-08 21:11:45.876: I/System.out(1151): 42 43
04-08 21:11:45.876: I/System.out(1151): 43 42
04-08 21:11:45.876: I/System.out(1151): 43 44
04-08 21:11:45.876: I/System.out(1151): 44 43
04-08 21:11:45.876: I/System.out(1151): 44 45
04-08 21:11:45.876: I/System.out(1151): 45 44
04-08 21:11:45.876: I/System.out(1151): 45 46
04-08 21:11:45.876: I/System.out(1151): 46 45
04-08 21:11:45.876: I/System.out(1151): 46 47
04-08 21:11:45.876: I/System.out(1151): 47 46
04-08 21:11:45.876: I/System.out(1151): 47 48
04-08 21:11:45.876: I/System.out(1151): 48 47
04-08 21:11:45.876: I/System.out(1151): 48 49
04-08 21:11:45.876: I/System.out(1151): 49 48
04-08 21:11:45.876: I/System.out(1151): 48 50
04-08 21:11:45.876: I/System.out(1151): 50 48
04-08 21:11:45.876: I/System.out(1151): 49 51
04-08 21:11:45.876: I/System.out(1151): 51 49
04-08 21:11:45.876: I/System.out(1151): 50 51
04-08 21:11:45.876: I/System.out(1151): 51 50
04-08 21:11:45.876: I/System.out(1151): 50 52
04-08 21:11:45.876: I/System.out(1151): 52 50
04-08 21:11:45.876: I/System.out(1151): 51 54 
04-08 21:11:45.876: I/System.out(1151): 54 51
04-08 21:11:45.876: I/System.out(1151): 52 53
04-08 21:11:45.876: I/System.out(1151): 53 52
04-08 21:11:45.876: I/System.out(1151): 53 55
04-08 21:11:45.876: I/System.out(1151): 55 53
04-08 21:11:45.876: I/System.out(1151): 54 55
04-08 21:11:45.876: I/System.out(1151): 55 54
04-08 21:11:45.876: I/System.out(1151): 54 57
04-08 21:11:45.876: I/System.out(1151): 57 54
04-08 21:11:45.876: I/System.out(1151): 55 56
04-08 21:11:45.876: I/System.out(1151): 56 55
04-08 21:11:45.876: I/System.out(1151): 56 57 
04-08 21:11:45.876: I/System.out(1151): 57 56
04-08 21:11:45.876: I/System.out(1151): 56 58
04-08 21:11:45.876: I/System.out(1151): 58 56
04-08 21:11:45.876: I/System.out(1151): 57 60 
04-08 21:11:45.876: I/System.out(1151): 60 57
04-08 21:11:45.876: I/System.out(1151): 58 59
04-08 21:11:45.876: I/System.out(1151): 59 58
04-08 21:11:45.876: I/System.out(1151): 59 60
04-08 21:11:45.876: I/System.out(1151): 60 59
04-08 21:11:45.876: I/System.out(1151): 59 61
04-08 21:11:45.876: I/System.out(1151): 61 59
04-08 21:11:45.876: I/System.out(1151): 61 62
04-08 21:11:45.876: I/System.out(1151): 62 61
04-08 21:11:45.876: I/System.out(1151): 62 63
04-08 21:11:45.876: I/System.out(1151): 63 62
04-08 21:11:45.876: I/System.out(1151): 63 64 
04-08 21:11:45.876: I/System.out(1151): 64 63
04-08 21:11:45.876: I/System.out(1151): 64 65
04-08 21:11:45.876: I/System.out(1151): 65 64
04-08 21:11:45.876: I/System.out(1151): 65 66
04-08 21:11:45.876: I/System.out(1151): 66 65
04-08 21:11:45.876: I/System.out(1151): 66 67 
04-08 21:11:45.876: I/System.out(1151): 67 66
04-08 21:11:45.876: I/System.out(1151): 67 68
04-08 21:11:45.876: I/System.out(1151): 68 67
04-08 21:11:45.876: I/System.out(1151): 68 69
04-08 21:11:45.876: I/System.out(1151): 69 68
04-08 21:11:45.876: I/System.out(1151): 69 70
04-08 21:11:45.876: I/System.out(1151): 70 69
04-08 21:11:45.876: I/System.out(1151):  
04-08 21:11:45.893: W/System.err(1151): java.io.FileNotFoundException: /data/data/com.example.helloworld3/files/taitfirstponts.xml (No such file or directory)
04-08 21:11:45.893: W/System.err(1151):     at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
04-08 21:11:45.893: W/System.err(1151):     at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
04-08 21:11:45.893: W/System.err(1151):     at java.io.FileInputStream.<init>(FileInputStream.java:80)
04-08 21:11:45.893: W/System.err(1151):     at android.app.ContextImpl.openFileInput(ContextImpl.java:412)
04-08 21:11:45.893: W/System.err(1151):     at android.content.ContextWrapper.openFileInput(ContextWrapper.java:152)
04-08 21:11:45.893: W/System.err(1151):     at com.example.helloworld3.FloorPlan.onCreate(FloorPlan.java:217)
04-08 21:11:45.893: W/System.err(1151):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-08 21:11:45.893: W/System.err(1151):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-08 21:11:45.893: W/System.err(1151):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-08 21:11:45.904: W/System.err(1151):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-08 21:11:45.904: W/System.err(1151):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-08 21:11:45.904: W/System.err(1151):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 21:11:45.904: W/System.err(1151):     at android.os.Looper.loop(Looper.java:130)
04-08 21:11:45.904: W/System.err(1151):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-08 21:11:45.904: W/System.err(1151):     at java.lang.reflect.Method.invokeNative(Native Method)
04-08 21:11:45.904: W/System.err(1151):     at java.lang.reflect.Method.invoke(Method.java:507)
04-08 21:11:45.904: W/System.err(1151):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-08 21:11:45.904: W/System.err(1151):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-08 21:11:45.904: W/System.err(1151):     at dalvik.system.NativeStart.main(Native Method)
04-08 21:11:45.936: D/dalvikvm(1151): GC_EXTERNAL_ALLOC freed 158K, 48% free 2911K/5575K, external 2425K/2961K, paused 32ms
04-08 21:11:46.036: I/System.out(1151): C201
04-08 21:11:46.036: I/System.out(1151): 51
04-08 21:11:46.040: I/System.out(1151): 89
04-08 21:11:46.040: I/System.out(1151): C2Exit5
04-08 21:11:46.040: I/System.out(1151): 42
04-08 21:11:46.040: I/System.out(1151): 164
04-08 21:11:46.040: I/System.out(1151): C1Exit1
04-08 21:11:46.040: I/System.out(1151): 52
04-08 21:11:46.040: I/System.out(1151): 174
04-08 21:11:46.040: I/System.out(1151): C108
04-08 21:11:46.040: I/System.out(1151): 51
04-08 21:11:46.040: I/System.out(1151): 89
04-08 21:11:46.160: I/System.out(1151): C201
04-08 21:11:46.160: I/System.out(1151): C2Exit5
04-08 21:11:46.160: I/System.out(1151): 52.0
04-08 21:11:46.160: I/System.out(1151): 174.0
04-08 21:11:46.160: I/System.out(1151): 51.0
04-08 21:11:46.160: I/System.out(1151): 89.0

Thank you for all your help!

readLine() actually reads the line.

You are checking if next line is not null and then skip it and actually split the one after that.

See my changes:

    while((word=breader.readLine()) != null){


            String[] words =word.split(" ");

            String sx = words[0];
            String sy = words[1]; // --- THIS IS THE LINE WHERE THE EXCEPTION IS

            System.out.println(sx);
            System.out.println(sy);

    }

You're calling breader.readLine() twice with every iteration.

Change this:

while((word=breader.readLine()) != null){
            String s = breader.readLine();

To:

while((word=breader.readLine()) != null){
            String s = word;

Additionally, there was whitespace at the end of the file which caused the exception.

This should fix it:

AssetManager amanager ;
String word = null;

try {
    amanager= getAssets();
    InputStream inputStream = amanager.open("edges.txt");
    InputStreamReader streamReader = new InputStreamReader(inputStream);
    BufferedReader breader = new BufferedReader(streamReader);
    //word 

    while((word=breader.readLine()) != null){
        String s = breader.readLine();
        if (s == null || "".equals(s)) continue;

        String[] words =s.split(" ");

        String sx = words[0];
        String sy = words[1]; // ---LINE 200, THIS IS THE LINE WHERE THE EXCEPTION IS

        System.out.println(sx);
        System.out.println(sy);

    }
    breader.close();
} catch (IOException e2) {
    // TODO Auto-generated catch block
    e2.printStackTrace();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM