Answer the question
In order to leave comments, you need to log in
How to deal with source not found in eclipse?
Hello. Now I decided to start learning java. I have win 8.1 64 bit. Installed JDK 1.8 SE 64 bit and Eclipse neon.3 for Java EE 64 bit. All possible paths in variable environments are registered.
When I run a case study, for example, a program that is a variation of the Java text-to-speech program.
`Main` class:
package com.example.TTS; // package of class Main
import com.example.TTS.GoogleTextToSpeech; // import class GoogleTextToSpeech
public class Main {
public static void main(String[] args) {
GoogleTextToSpeech gtts = new GoogleTextToSpeech(); // make instance gtts
gtts.say("Hello dear friends", "en"); // use method say
// gtts.say("Bonjour mon amis!", "fr");
}
}
package com.example.TTS; // package of class GoogleTextToSpeech
import java.io.InputStream; // import classes from Java library
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import javazoom.jl.player.Player; // import class from jl1.0.1.jar
public class GoogleTextToSpeech {
private static String ENCODING = "UTF-8"; //make constants and assign values to them
private static String URL_BEGINNING = "http://translate.google.com/translate_tts?ie=";
private static String URL_QUERY = "&q=";
private static String URL_TL = "&tl=";
private static String USER_AGENT_LITERAL = "User-Agent";
private static String USER_AGENT = "Mozilla/4.7";
public void say( String phrase, String lang ) {
try {
//Make full URL
phrase=URLEncoder.encode(phrase, ENCODING); //assign value to variable with name 'phrase' by use method encode from class URLEncoder
String sURL = URL_BEGINNING + ENCODING + URL_TL + lang + URL_QUERY + phrase; //assign value to variable sURL
URL url = new URL(sURL); // make instance url with constructor
//Create connection
URLConnection urlConn = url.openConnection(); //assign value to variable urlConn
HttpURLConnection httpUrlConn = (HttpURLConnection) urlConn; //Declaring a httpUrlConn variable of type HttpURLConnection and assigning it a value to some variable urlConn (which is previously reduce to HttpURLConnection)
httpUrlConn.addRequestProperty(USER_AGENT_LITERAL, USER_AGENT);// use method
//Create stream
InputStream mp3WebStream = urlConn.getInputStream();//create instance and assign it a value
//Play stream
Player plr = new Player(mp3WebStream); //create instance plr with constructor
plr.play(); //use method
}
//use exception with name ex
catch (Exception ex) {
ex.printStackTrace(); //use method
}
}
}
java.io.IOException: Server returned HTTP response code: 503 for URL: http://ipv4.google.com/sorry/index?continue=http://translate.google.com/translate_tts%3Fie%3DUTF-8%26tl%3Den%26q%3DHello%2Bdear%2Bfriends&q=EgRbegWvGJ3FldEFIhkA8aeDS952qU94sbK8DAgP55pH8cbMicZdMgFy
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at com.example.TTS.GoogleTextToSpeech.say(GoogleTextToSpeech.java:32)
at com.example.TTS.Main.main(Main.java:9)
HttpURLConnection.java:1492
HttpURLConnection.java:1894
public class sun.net.www.protocol.http.HttpURLConnection extends java.net.HttpURLConnection
they mean some other class from SUN (where could it come from?). main.java или в GoogleTextToSpeech.java
(including the class HttpURLConnection
) HttpURLConnection.class
and not HttpURLConnection.java
Answer the question
In order to leave comments, you need to log in
It is not necessary to prescribe anything anywhere, why do you need the source codes of these classes at all? The error says Server returned HTTP response code: 503 for URL. Figure out what's wrong with the server, why it responds this way and you will be happy. You don’t need to get into the guts of the dignity classes for this, especially since now you won’t understand anything there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question