• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

android program that connects to internet doesn't work

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, just asking why this program doesn't work..

computer specs:
-using eclipse adt bundle

android phone specs
- using model number: Samsung galaxy ace GT-S5830
- using android version 2.3.3

error produced:
On startup the application shows a blank white screen and then closes. Immediatley after, the android device pops up with an error message saying "the application WEConnectingToWebPage (process con.example.weconnectingtowebpage) has stopped unexpectedly. Please try again.

code for MainActivity.java:




code for activity_main.xml:



and finally code for the android manifest file:




I will be checking this thread regularly and any suggestions will be much appreciated

 
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does LogCat tell you?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will have to dig deeper into the error. There is a DDMS perspective in Eclipse that will let you look at LogCat messages. Make sure your phone is connected, that USB Debugging is activated, and then run the application and see what errors occur in the LogCat output.
 
Adam Preston
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the log:

01-24 16:02:34.479: I/ApplicationPackageManager(959): cscCountry is not German : H3G
01-24 16:02:34.579: D/AndroidRuntime(959): Shutting down VM
01-24 16:02:34.579: W/dalvikvm(959): threadid=1: thread exiting with uncaught exception (group=0x40018578)
01-24 16:02:34.579: E/AndroidRuntime(959): FATAL EXCEPTION: main
01-24 16:02:34.579: E/AndroidRuntime(959): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.weconnectingtowebpage/com.example.weconnectingtowebpage.MainActivity}: java.lang.ArrayIndexOutOfBoundsException
01-24 16:02:34.579: E/AndroidRuntime(959): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
01-24 16:02:34.579: E/AndroidRuntime(959): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-24 16:02:34.579: E/AndroidRuntime(959): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-24 16:02:34.579: E/AndroidRuntime(959): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-24 16:02:34.579: E/AndroidRuntime(959): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 16:02:34.579: E/AndroidRuntime(959): at android.os.Looper.loop(Looper.java:123)
01-24 16:02:34.579: E/AndroidRuntime(959): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-24 16:02:34.579: E/AndroidRuntime(959): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 16:02:34.579: E/AndroidRuntime(959): at java.lang.reflect.Method.invoke(Method.java:507)
01-24 16:02:34.579: E/AndroidRuntime(959): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-24 16:02:34.579: E/AndroidRuntime(959): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-24 16:02:34.579: E/AndroidRuntime(959): at dalvik.system.NativeStart.main(Native Method)
01-24 16:02:34.579: E/AndroidRuntime(959): Caused by: java.lang.ArrayIndexOutOfBoundsException
01-24 16:02:34.579: E/AndroidRuntime(959): at com.example.weconnectingtowebpage.MainActivity.onCreate(MainActivity.java:38)
01-24 16:02:34.579: E/AndroidRuntime(959): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-24 16:02:34.579: E/AndroidRuntime(959): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
01-24 16:02:34.579: E/AndroidRuntime(959): ... 11 more
 
Adam Preston
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm assuming it has something to do with AsyncTask but i'm relatively new to android programming and don't know enough about it to understand why an error is occuring.
 
Ron McLeod
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a couple of issues with AyncTask, but this problem is related to your array. It indicates you have gone out-of-bounds. What size is your array, and what element are you trying to access when the exception is raised?

E/AndroidRuntime(959): Caused by: java.lang.ArrayIndexOutOfBoundsException
E/AndroidRuntime(959): at com.example.weconnectingtowebpage.MainActivity.onCreate(MainActivity.java:38)




 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're initializing the "urls" array to be of zero length - so when you try to access the element at the first position ("urls[0]") you get the exception. Try "String[] urls = new String[1];" instead.
 
Adam Preston
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:You're initializing the "urls" array to be of zero length - so when you try to access the element at the first position ("urls[0]") you get the exception. Try "String[] urls = new String[1];" instead.



of course, i see it now i'll fix the array exception first then i'll deal with asynctask. I will have to do it tomorrow now though.
 
Adam Preston
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay i fixed the array issue but now there is a problem with connecting to the internet. it says there is a security exception although i have enabled both two permissions:



Anyway here is the new log message:

01-25 19:16:04.199: I/ApplicationPackageManager(2239): cscCountry is not German : H3G
01-25 19:16:36.969: D/AndroidRuntime(2239): Shutting down VM
01-25 19:16:36.969: W/dalvikvm(2239): threadid=1: thread exiting with uncaught exception (group=0x40018578)
01-25 19:16:36.979: E/AndroidRuntime(2239): FATAL EXCEPTION: main
01-25 19:16:36.979: E/AndroidRuntime(2239): java.lang.SecurityException: ConnectivityService: Neither user 10073 nor current process has android.permission.ACCESS_NETWORK_STATE.
01-25 19:16:36.979: E/AndroidRuntime(2239): at android.os.Parcel.readException(Parcel.java:1322)
01-25 19:16:36.979: E/AndroidRuntime(2239): at android.os.Parcel.readException(Parcel.java:1276)
01-25 19:16:36.979: E/AndroidRuntime(2239): at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:369)
01-25 19:16:36.979: E/AndroidRuntime(2239): at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:251)
01-25 19:16:36.979: E/AndroidRuntime(2239): at com.example.weconnectingtowebpage.MainActivity$1.onClick(MainActivity.java:47)
01-25 19:16:36.979: E/AndroidRuntime(2239): at android.view.View.performClick(View.java:2485)
01-25 19:16:36.979: E/AndroidRuntime(2239): at android.view.View$PerformClick.run(View.java:9080)
01-25 19:16:36.979: E/AndroidRuntime(2239): at android.os.Handler.handleCallback(Handler.java:587)
01-25 19:16:36.979: E/AndroidRuntime(2239): at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 19:16:36.979: E/AndroidRuntime(2239): at android.os.Looper.loop(Looper.java:123)
01-25 19:16:36.979: E/AndroidRuntime(2239): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-25 19:16:36.979: E/AndroidRuntime(2239): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 19:16:36.979: E/AndroidRuntime(2239): at java.lang.reflect.Method.invoke(Method.java:507)
01-25 19:16:36.979: E/AndroidRuntime(2239): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-25 19:16:36.979: E/AndroidRuntime(2239): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-25 19:16:36.979: E/AndroidRuntime(2239): at dalvik.system.NativeStart.main(Native Method)
01-25 19:18:04.349: I/ApplicationPackageManager(2321): cscCountry is not German : H3G
01-25 19:18:46.739: W/IInputConnectionWrapper(2321): beginBatchEdit on inactive InputConnection
01-25 19:18:46.739: W/IInputConnectionWrapper(2321): endBatchEdit on inactive InputConnection
01-25 19:18:46.739: W/IInputConnectionWrapper(2321): getExtractedText on inactive InputConnection
01-25 19:18:46.749: W/IInputConnectionWrapper(2321): getExtractedText on inactive InputConnection
01-25 19:18:51.819: W/IInputConnectionWrapper(2321): getExtractedText on inactive InputConnection
01-25 19:18:51.819: W/IInputConnectionWrapper(2321): getExtractedText on inactive InputConnection
01-25 19:19:18.439: I/ApplicationPackageManager(2321): cscCountry is not German : H3G
01-25 19:19:56.999: W/IInputConnectionWrapper(2321): beginBatchEdit on inactive InputConnection
01-25 19:19:56.999: W/IInputConnectionWrapper(2321): endBatchEdit on inactive InputConnection
01-25 19:19:56.999: W/IInputConnectionWrapper(2321): getExtractedText on inactive InputConnection
01-25 19:19:56.999: W/IInputConnectionWrapper(2321): getExtractedText on inactive InputConnection
01-25 19:20:02.089: W/IInputConnectionWrapper(2321): getExtractedText on inactive InputConnection
01-25 19:20:02.089: W/IInputConnectionWrapper(2321): getExtractedText on inactive InputConnection
01-25 19:20:02.159: I/ApplicationPackageManager(2321): cscCountry is not German : H3G

 
Ron McLeod
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adding the ACCESS_NETWORK_STATE permission should have fixed that issue.

Maybe try making a clean build.
 
Adam Preston
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:Adding the ACCESS_NETWORK_STATE permission should have fixed that issue.

Maybe try making a clean build.



done clean build and errors have gone, but warnings are still showing up:

01-25 20:06:47.979: W/IInputConnectionWrapper(1075): getExtractedText on inactive InputConnection

Is this something to do with my phone not being able to connect to the internet?
 
Ron McLeod
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you see the same behaviour when running on the emulator?
 
Adam Preston
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ill try it tomorrow but i heard configuring an emulator properly can be quite complicated

EDIT: nvm I think i have figured the problem out, problems occurred on line 48 and 43
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is happening because you are not running network retated stuff in a new thread...android does not allow the network operations in main thread...it will work if you start a new thread for network connections
 
Ron McLeod
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

aniket chaudhary wrote:this is happening because you are not running network retated stuff in a new thread...android does not allow the network operations in main thread...it will work if you start a new thread for network connections


That is the case here - I ran the code without restructuring it (just a few bug fixes) and it worked.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic