0

To develope a client applications, I need to read and modify worksheets and data in Google Sheets. I am facing with below issue:

SpreadsheetService service = new SpreadsheetService("sheet1");
String sheetUrl = "https://spreadsheets.google.com/feeds/list/1XP3KQTboWCArbvH99XYEGsVOldc97NqFzKD MiEepXRA/default/public/values"; //Sheet url             
URL url = new URL(sheetUrl); // Get Feed of Spreadsheet url 
ListFeed lf = service.getFeed(url, ListFeed.class); //Error statement

Issue:

java.net.UnknownHostException: spreadsheets.google.com at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.security.ssl.SSLSocketImpl.connect(Unknown Source) at sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.protocol.https.HttpsClient.(Unknown Source) at sun.net.www.protocol.https.HttpsClient.New(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source) at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:503) at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535) at com.google.gdata.client.Service.getFeed(Service.java:1135) at com.google.gdata.client.Service.getFeed(Service.java:998) at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631) at com.google.gdata.client.Service.getFeed(Service.java:1017) at test_project.test_demo.main(test_demo.java:35)

pkc456
  • 8,350
  • 38
  • 53
  • 109
Bishal Kumar
  • 11
  • 1
  • 1
  • Unknown host usually means your URL is wrong...are you sure it isn't just sheets.google.com or something else? – Sameer Puri Aug 05 '16 at 14:09
  • It might not be a duplicate. Is your project java 7 or 8 ? In case of java 8 the default appengine-web.xml settings can cause that exception when billing is not enabled. Please have a look at url-stream-handler at https://cloud.google.com/appengine/docs/standard/java/config/appref – Daniel Przybylowski Jan 12 '18 at 12:55

1 Answers1

0

As stated here, UnknownHostException means that your device was not able to resolve the host name. It emerges when you are trying to connect to a remote host using its host name, but the IP address of that host cannot be resolved. From this blog, you should check the input of Socket (or any other method that throws an UnknownHostException), and validate that it is the intended one. If you are not sure whether you have the correct host name, you can launch a terminal and use the nslookup command to see if your DNS server can resolve the host name to an IP address successfully.

If that doesn’t work, you should check if the host name you have is correct and then try to refresh your DNS cache. If that doesn’t work either, try to use a different DNS server, eg Google Public DNS is a very good alternative.

You can also check on this link. Hope this helps!

abielita
  • 13,147
  • 2
  • 17
  • 59