我的代码遵守http://android-er.blogspot.com/2009/10/multi-language-translate.html
并强行关闭
private void showLang() {
db.open();
cursor = db.getLang();
cursor.moveToFirst();
startManagingCursor(cursor);
SimpleCursorAdapter qc = new SimpleCursorAdapter(
this,
android.R.layout.simple_spinner_item,
cursor,
new String[] {DBAdapter.KEY_LANG},
new int[] {android.R.id.text1});
qc.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Language_Spinner.setAdapter(qc);
TranslateButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
String InputString;
String OutputString = null;
InputString = Thai_word.getText().toString();
String language = (String)Language_Spinner
.getItemAtPosition((int) Language_Spinner.getSelectedItemId());
try {
Translate.setHttpReferrer("http://android-er.blogspot.com/");
OutputString = Translate.execute(InputString,
Language.ENGLISH,Language.THAI);
} catch (Exception ex) {
ex.printStackTrace();
OutputString = "Error";
}
Target_word.setText(OutputString+language);
}
});
}
}
这是我的logcat
02-12 21:45:44.701:ERROR / AndroidRuntime(437):致命异常:主要 02-12 21:45:44.701:ERROR / AndroidRuntime(437):java.lang.ClassCastException:android.database.sqlite.SQLiteCursor 02-12 21:45:44.701:ERROR / AndroidRuntime(437):at com.android.proj.Sens_Create $ 1.onClick(Sens_Create.java:133) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):在android.view.View.performClick(View.java:2408) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):在android.view.View $ PerformClick.run(View.java:8816) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):在android.os.Handler.handleCallback(Handler.java:587) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):在android.os.Handler.dispatchMessage(Handler.java:92) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):在android.os.Looper.loop(Looper.java:123) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):在android.app.ActivityThread.main(ActivityThread.java:4627) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):at java.lang.reflect.Method.invokeNative(Native Method) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):at java.lang.reflect.Method.invoke(Method.java:521) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 02-12 21:45:44.701:ERROR / AndroidRuntime(437):at dalvik.system.NativeStart.main(Native Method)
请帮助
答案 0 :(得分:1)
String language = (String)Language_Spinner
.getItemAtPosition((int) Language_Spinner.getSelectedItemId());
我认为你的问题就在这里。此方法不返回字符串,因此会发生类强制转换异常。