-1

This is my first android app. I had a main activity defined in the androidmainifest.xml with the intent-filter block. I then had a number of subsequent activities. There are 5 altogether and 2 of them retrieve small bits of data from different web pages.

I then added a new activity that I wanted to be the main activity of the app. I cut the intent-filter block out of the initial main activity and pasted it in to the new activity that I wanted to be the main activity. It worked, in that this new activity was now the start up activity, but this new activity can't access web pages like all other activities.

I have uses-permission android:name="android.permission.INTERNET" above the application block in the androidmainfest.xml file Below is the stack trace.

android.os.NetworkOnMainThreadException
 android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1236)
 java.net.InetAddress.lookupHostByName(InetAddress.java:388)
 java.net.InetAddress.getAllByNameImpl(InetAddress.java:239)
 java.net.InetAddress.getAllByName(InetAddress.java:214)
 com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)
com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)
com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)
com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)
com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:179)
com.windsweptsoftware.wslistit.Utilities.GetNewData(Utilities.java:45)
com.windsweptsoftware.wslistit.LogIn.onLoginClicked(LogIn.java:96)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:515)
android.view.View$1.onClick(View.java:3860)
android.view.View.performClick(View.java:4480)
android.view.View$PerformClick.run(View.java:18673)
android.os.Handler.handleCallback(Handler.java:733)
android.os.Handler.dispatchMessage(Handler.java:95)
android.os.Looper.loop(Looper.java:157)
android.app.ActivityThread.main(ActivityThread.java:5872)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
dalvik.system.NativeStart.main(Native Method)
user1091524
  • 865
  • 1
  • 15
  • 28

1 Answers1

1

The log says what is not right itself. Running a network operation on the main thread is all but ok. Look into AsyncTask! Hope I helped you, Roberto

Roberto Anić Banić
  • 1,411
  • 10
  • 21
  • I'm implementing asynctask now. It is working, sort of. Still now sure how to get the data back while in the onCreate(), where I need it. Why did it work in all other activities and not this new one. – user1091524 Jan 19 '15 at 18:43
  • I implemented asynctask in that one activity and it now works. All of the other activities that access web pages work as well, even though they don't utilize asynctask. Why> – user1091524 Jan 19 '15 at 20:35
  • Actually that should not be happening. It is not good. You should change it right away! Could you tag my answer correct please? – Roberto Anić Banić Jan 19 '15 at 22:55