0
單擊imageswitcher時,獲取logcat中顯示的錯誤classcastexception。請幫我傢伙 代碼中,我感到當點擊imageswitcher單擊imageswitcher時出現錯誤
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//List<String> it;
imageId = parent.getAdapter().getItemId(position);
try {}
}
,我使用這個圖片ID
imageView.setLayoutParams(new ViewGroup.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
imageView.setImageResource((int) imageid);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
05-17 19:04:40.053: W/dalvikvm(5956): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-17 19:04:40.092: E/AndroidRuntime(5956): FATAL EXCEPTION: main
05-17 19:04:40.092: E/AndroidRuntime(5956): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3123)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.view.View.measure(View.java:8171)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.view.View.measure(View.java:8171)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.view.View.measure(View.java:8171)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.view.View.measure(View.java:8171)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.os.Looper.loop(Looper.java:123)
05-17 19:04:40.092: E/AndroidRuntime(5956): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-17 19:04:40.092: E/AndroidRuntime(5956): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 19:04:40.092: E/AndroidRuntime(5956): at java.lang.reflect.Method.invoke(Method.java:521)
05-17 19:04:40.092: E/AndroidRuntime(5956): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-17 19:04:40.092: E/AndroidRuntime(5956): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-17 19:04:40.092: E/AndroidRuntime(5956): at dalvik.system.NativeStart.main(Native Method)
我已經做了清理和重建,但沒有改變 –
什麼是'imageid'?它是什麼類型?如果你正在訪問資源文件,然後檢查我的答案。 –
imageId = parent.getAdapter()。getItemId(position);當從圖庫中選擇圖片 –