单击imageswitcher时,获取logcat中显示的错误classcastexception。请帮帮我们 我点击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)
答案 0 :(得分:0)
Eclipse的另一个错误。只需清理一次项目,它就会重建您的R.java
文件。
更新1
我不明白为什么你明确地强制转换imageid
。只需使用int imageid= R.drawable.somepic
更新2
尝试将getItemId
更改为getResourceId
。