• 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Content from web-site won't display in my logcat

 
Greenhorn
Posts: 27
Android Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello i am trying to download content of some random web content to my Logcat.I already did this many time but now i am getting onlyand nothing else.Content is some random JSON small samlpe and i want to show it in my logcat,and nothing else. I added internet permision.


 
Ranch Hand
Posts: 528
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you to not use AsyncTask is deprecated. I suggest also to click yourself the link you sent? You get a 401 error because you need to register to the api, try to use github as API that is free and you do not need to register, or if is important for you to use a weather API you should register, or even  pay if required
 
Master Rancher
Posts: 3874
35
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

click yourself the link you sent? You get a 401 error


There must be something about what this site does to that URL.  I copied it, trimmed it up, put in a browser and got this:


{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"base":"stations","main":{"temp":289.71,"feels_like":284.33,"temp_min":288.71,"temp_max":291.15,"pressure":1022,"humidity":42},"visibility":10000,"wind":{"speed":5.7,"deg":270},"clouds":{"all":51},"dt":1589746016,"sys":{"type":1,"id":1414,"country":"GB","sunrise":1589688320,"sunset":1589744925},"timezone":3600,"id":2643743,"name":"London","cod":200}

 
Giovanni Montano
Ranch Hand
Posts: 528
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


OK please show me the stack trace for the call
 
Norm Radder
Master Rancher
Posts: 3874
35
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There was no trace.  I loaded the URL into my browser and the site returned the text that I posted.
 
Milos Gojic
Greenhorn
Posts: 27
Android Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Giovanni Montano wrote:I suggest you to not use AsyncTask is deprecated. I suggest also to click yourself the link you sent? You get a 401 error because you need to register to the api, try to use github as API that is free and you do not need to register, or if is important for you to use a weather API you should register, or even  pay if required



It works with github api. But why not with openweather api?? I am registered and got api key but all in vain
 
Norm Radder
Master Rancher
Posts: 3874
35
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding a print statement after the statements  on lines 24 and 28 that print out the value of podaci so you can see what is read.
 
Milos Gojic
Greenhorn
Posts: 27
Android Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Try adding a print statement after the statements  on lines 24 and 28 that print out the value of podaci so you can see what is read.


in line 24
In my line 24 it shows number 123

but in line 28 it shows -1 ???

so in my while loop shows that podaci(data) are -1 and stop printing in log...but why??



EDIT: When i put this code :

my second log,in else, is activated like it's failed.
Prints:
 
Norm Radder
Master Rancher
Posts: 3874
35
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is that the InputStreamReader on line 24 has read all the contents of the stream into its buffer and the read statement returns the first character from the buffer: {    Note (char)123 is {
There is no more data in the stream so the InputStream used on line 28 returns the -1.
Try using the InputStreamReader for all the reads, not the InputStream.
 
Milos Gojic
Greenhorn
Posts: 27
Android Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:I think the problem is that the InputStreamReader on line 24 has read all the contents of the stream into its buffer and the read statement returns the first character from the buffer: {    Note (char)123 is {
There is no more data in the stream so the InputStream used on line 28 returns the -1.
Try using the InuputStreamReader for all the reads, not the InputStream.


I used BufferedReader and now it works fine...you were right problem was in in InputStream... hahahah what a sleepless night
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic