我在用
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = new TextView(this);
GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
GoogleAPI.setKey("AIzaSyBi7y4EgC0B-Q9UZg-tOzsOI0sLQ8F1Oow");
try {
String translatedText = Translate.DEFAULT.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);
} catch (GoogleAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我收到以下错误,我不明白我做错了什么
02-26 10:53:53.409: W/System.err(2612):
com.google.api.GoogleAPIException: java.lang.Exception:
[google-api-translate-java] Error retrieving translation. 02-26
10:53:53.409: W/System.err(2612): at
com.google.api.translate.TranslateV2.execute(TranslateV2.java:68)
02-26 10:53:53.409: W/System.err(2612): at
com.example.testtranslate.Translator.onCreate(Translator.java:32)
02-26 10:53:53.409: W/System.err(2612): at
android.app.Activity.performCreate(Activity.java:5158) 02-26
10:53:53.409: W/System.err(2612): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-26 10:53:53.409: W/System.err(2612): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
02-26 10:53:53.409: W/System.err(2612): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
02-26 10:53:53.410: W/System.err(2612): at
android.app.ActivityThread.access$600(ActivityThread.java:149) 02-26
10:53:53.410: W/System.err(2612): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
02-26 10:53:53.411: W/System.err(2612): at
android.os.Handler.dispatchMessage(Handler.java:99) 02-26
10:53:53.411: W/System.err(2612): at
android.os.Looper.loop(Looper.java:153) 02-26 10:53:53.411:
W/System.err(2612): at
android.app.ActivityThread.main(ActivityThread.java:5086) 02-26
10:53:53.412: W/System.err(2612): at
java.lang.reflect.Method.invokeNative(Native Method) 02-26
10:53:53.412: W/System.err(2612): at
java.lang.reflect.Method.invoke(Method.java:511) 02-26 10:53:53.412:
W/System.err(2612): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
02-26 10:53:53.413: W/System.err(2612): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584) 02-26
10:53:53.413: W/System.err(2612): at
dalvik.system.NativeStart.main(Native Method) 02-26 10:53:53.413:
W/System.err(2612): Caused by: java.lang.Exception:
[google-api-translate-java] Error retrieving translation. 02-26
10:53:53.414: W/System.err(2612): at
com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:99) 02-26
10:53:53.414: W/System.err(2612): at
com.google.api.translate.TranslateV2.execute(TranslateV2.java:62)
02-26 10:53:53.416: W/System.err(2612): ... 15 more 02-26
10:53:53.416: W/System.err(2612): Caused by:
java.lang.NullPointerException 02-26 10:53:53.418: W/System.err(2612):
at
libcore.net.http.HttpEngine.writeRequestHeaders(HttpEngine.java:647)
02-26 10:53:53.418: W/System.err(2612): at
libcore.net.http.HttpEngine.readResponse(HttpEngine.java:801) 02-26
10:53:53.419: W/System.err(2612): at
libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:293)
02-26 10:53:53.419: W/System.err(2612): at
libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:185)
02-26 10:53:53.420: W/System.err(2612): at
libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
02-26 10:53:53.420: W/System.err(2612): at
com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:93) 02-26
10:53:53.420: W/System.err(2612): ... 16 more