Wrote a method of saving images in the application's memory. One of the input parameters is ImageView. In void onItemClick (AdapterView parent, View view, int position, long id) there is a View that is clicked. from it I do imageView

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ...... ImageView imageView = (ImageView) view; // вот тут то и возникает ошибка (строка 177) // Метод добавления логотипа в память addLogoFile(imageView, logoName) } 

But the logs:

02-10 18: 29: 09.267: E / AndroidRuntime (816): FATAL EXCEPTION: main 02-10 18: 29: 09.267: E / AndroidRuntime (816): java.lang.ClassCastException: android.widget.LinearLayout 02-10 18: 29: 09.267: E / AndroidRuntime (816): at com.sadko.askdroid.OnlineCatalog $ 2.onItemClick (OnlineCatalog.java:177) 02-10 18: 29: 09.267: E / AndroidRuntime (816): android. widget.AdapterView.performItemClick (AdapterView.java:284) 02-10 18: 29: 09.267: E / AndroidRuntime (816): at android.widget.ListView.performItemClick (ListView.java:3382) 02-10 18:29: 09.267: E / AndroidRuntime (816): at android.widget.AbsListView $ PerformClick.run (AbsListView.java:1696) 02-10 18: 29: 09.267: E / AndroidRuntime (816): at android.os.Handler.handleCallback (Handler.java Redu87) 02-10 18: 29: 09.267: E / AndroidRuntime (816): at android.os.Handler.dispatchMessage (Handler.java:92) 02-10 18: 29: 09.267: E / AndroidRuntime (816): at android.os.Looper.loop (Looper.java:123) 02-10 18: 29: 09.267: E / AndroidRuntime (816): at android.app.ActivityThread.main (ActivityThread.java:4627) 02-10 18: 29: 09.267: E / AndroidRuntime (816): at java.lang.reflect.Method.invokeNative (Native Method) 02-10 18: 29: 09.267: E / AndroidRuntime (816): at java.lang .reflect.Method.invoke (Method.java sources21) 02-10 18: 29: 09.267: E / AndroidRuntime (816): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:868) 02-10 18: 29: 09.267: E / AndroidRuntime (816): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:626) 02-10 18: 29: 09.267: E / AndroidRuntime (816) : at dalvik.system.NativeStart.main (Native Method)

But, for some reason, the value of imageView "errors during the evaluation" during debug .. Why?

  • show more code and error stack - Gorets
  • Obviously your view is LinearLayout - rasmisha
  • And how to get ImageView from LinearLayout? - Stas0n

1 answer 1

 ImageView imageView = view.findViewById(R.id.imageView); 
  • LinearLayout can't be resolved to a type - Stas0n
  • just look at the view - Gorets