• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Android "android.os.NetworkOnMainThreadException" error  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 Hi! I am developing an android application in Eclipse and I've got the following class:
 
  I am instantiating this class in the MainActivity class as it follows:
 
  ...and, of course, when I am running this app I get the following error:
 "Invalid IP Address android.os.NetworkOnMainThreadException "
   If anyone knows how to correct this code please help me out!
 
Saloon Keeper
Posts: 2339
293
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Bogdan wrote:I am instantiating this class in the MainActivity class as it follows:
 
  ...and, of course, when I am running this app I get the following error:
 "Invalid IP Address android.os.NetworkOnMainThreadException "
   If anyone knows how to correct this code please help me out!


Your should be calling AsyncTask's execute method, not doInBackground, otherwise you will be running the network code in the main (UI) thread.
 
Ron McLeod
Saloon Keeper
Posts: 2339
293
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and Welcome to CodeRanch
 
Daniel Bogdan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:... and Welcome to CodeRanch


  Thank you for your greetings and your answer. I tried to execute with your method "job.execute()" but I received no feedback message from Toast. I've got no reaction when I pressed the button from my application.
  I can connect to my local apache server through the browser of my android phone but my android project application seems like it can not.
 
Daniel Bogdan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:
Your should be calling AsyncTask's execute method, not doInBackground, otherwise you will be running the network code in the main (UI) thread.


 Nevermind. I've detected the error. It was my php file... Thank you!
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!