Вопрос

I am getting the signal strength from the wifi locations available. When I run the program, i get the output. But, when I click on refresh button, I get the error, as mentioned in the stack trace. I know that before I kept the counter buttons, it was working perfectly, but after I kept the buttons for plus and minus, I am getting the error, only when i click on refresh button.

Can you please help me out.

Stack Trace :

FATAL EXCEPTION: main
 java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS flg=0x10000010 } in com.example.wifisignalstrength.MainActivity$1@410f98f8
android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
android.os.Handler.handleCallback(Handler.java:605)
android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4517)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)

dalvik.system.NativeStart.main(Native Method)
03-06 13:15:45.102: E/AndroidRuntime(7139): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
java.util.ArrayList.get(ArrayList.java:304)
com.example.wifisignalstrength.MainActivity$1.onReceive(MainActivity.java:202)
android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
Это было полезно?

Решение

Take a look on the count==15 branch. You are trying to get first element (index = 0) of empty ArrayList, since you've only initialized it via ArrayList<String> arr = new ArrayList<String>();, but it has no data. The only place where you put data to it is count<15 && count>=5 branch.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top