我正在尝试通过单击按钮在我的 android 应用程序中使用 Yahoo Finance API 获取货币报价。我的代码:
String urlStr = "http://download.finance.yahoo.com/d/quotes.csv?s=USDEUR=X&f=l1&e=.csv";
httpGet = new HttpGet(urlStr);
InputStreamReader is = null;
String value = "";
try {
HttpResponse response = httpClient.execute(httpGet, localContext);
is = new InputStreamReader(response.getEntity().getContent());
BufferedReader reader = new BufferedReader(is);
String line = reader.readLine();
String[] RowData = line.split(",");
value = RowData[0];
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
} finally {
try {
is.close();
} catch (IOException e) {
// handle exception
}
}
((TextView) findViewById(R.id.value)).setText(value);
应用程序崩溃并给出 java.lang.IllegalStateException。我在这里想念什么?
堆栈跟踪:
06-25 16:40:19.154: E/AndroidRuntime(2426): FATAL EXCEPTION: main
06-25 16:40:19.154: E/AndroidRuntime(2426): java.lang.IllegalStateException: Could not execute method of the activity
06-25 16:40:19.154: E/AndroidRuntime(2426): at android.view.View$1.onClick(View.java:3599)
06-25 16:40:19.154: E/AndroidRuntime(2426): at android.view.View.performClick(View.java:4204)
06-25 16:40:19.154: E/AndroidRuntime(2426): at android.view.View$PerformClick.run(View.java:17355)
06-25 16:40:19.154: E/AndroidRuntime(2426): at android.os.Handler.handleCallback(Handler.java:725)
06-25 16:40:19.154: E/AndroidRuntime(2426): at android.os.Handler.dispatchMessage(Handler.java:92)
06-25 16:40:19.154: E/AndroidRuntime(2426): at android.os.Looper.loop(Looper.java:137)
06-25 16:40:19.154: E/AndroidRuntime(2426): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-25 16:40:19.154: E/AndroidRuntime(2426): at java.lang.reflect.Method.invokeNative(Native Method)
06-25 16:40:19.154: E/AndroidRuntime(2426): at java.lang.reflect.Method.invoke(Method.java:511)
06-25 16:40:19.154: E/AndroidRuntime(2426): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-25 16:40:19.154: E/AndroidRuntime(2426): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-25 16:40:19.154: E/AndroidRuntime(2426): at dalvik.system.NativeStart.main(Native Method)
06-25 16:40:19.154: E/AndroidRuntime(2426): Caused by: java.lang.reflect.InvocationTargetException
06-25 16:40:19.154: E/AndroidRuntime(2426): at java.lang.reflect.Method.invokeNative(Native Method)
06-25 16:40:19.154: E/AndroidRuntime(2426): at java.lang.reflect.Method.invoke(Method.java:511)
06-25 16:40:19.154: E/AndroidRuntime(2426): at android.view.View$1.onClick(View.java:3594)
06-25 16:40:19.154: E/AndroidRuntime(2426): ... 11 more
06-25 16:40:19.154: E/AndroidRuntime(2426): Caused by: java.lang.NullPointerException
06-25 16:40:19.154: E/AndroidRuntime(2426): at com.fuzzy.currencyconverter.CurrencyConverterActivity.fetch(CurrencyConverterActivity.java:79)
06-25 16:40:19.154: E/AndroidRuntime(2426): ... 14 more