0

When click on imageswitcher , getting error classcastexception that is show in logcat. please help me guys The code i am using when click on 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 {}
}

and i am using this image 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)
4

1 回答 1

0

Eclipse 的另一个失误。只需清理您的项目一次,它就会重建您的R.java文件。

更新 1

我不明白你为什么要明确地进行类型转换imageid。只需使用int imageid= R.drawable.somepic

更新 2

尝试更改getItemIdgetResourceId.

于 2013-05-17T13:53:52.917 回答