/ / Weird ClassCastException: ImageView não pode ser convertido para ListView - android, listview, android-listview

Estranho ClassCastException: ImageView não pode ser convertido em ListView - android, listview, android-listview

ClassCastException estranho: ImageView não pode ser convertido para ListView. No xml, a exibição é declarada como ListView. Quando recupero o objeto da seguinte maneira:

private void initShareContextMenu() {
ListView shareListITem = (ListView) findViewById(R.id.share_list);
shareList = new ContextMenuList(shareListITem,
(RelativeLayout) findViewById(R.id.content_wrapper), this);

List<View> views = new ArrayList<View>();
views.add(findViewById(R.id.share_btn));

shareList.setViews(views);
}

Eu tenho ClassCastException. Tentou criar e limpar o projeto, remova as pastas gen / bin, renomeando o controle, mas nada ajuda. O layout é o seguinte:

<RelativeLayout
android:id="@+id/content_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<FrameLayout
android:id="@+id/youtube_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black" />

<ListView
android:id="@+id/share_list"
android:layout_width="@dimen/share_context_menu_width"
android:layout_height="wrap_content"
android:divider="@color/share_list_divider"
android:dividerHeight="1px"
android:visibility="gone" />
</RelativeLayout>


05-01 09:40:45.215: E/MessageQueue-JNI(18500): Exception in MessageQueue callback: handleReceiveCallback
05-01 09:40:46.096: E/MessageQueue-JNI(18500): java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.ListView
05-01 09:40:46.096: E/MessageQueue-JNI(18500):  at com.packagename.ui.activities.VideoPlayerActivity.initShareContextMenu(VideoPlayerActivity.java:1394)
05-01 09:40:46.096: E/MessageQueue-JNI(18500):  at com.packagename.ui.activities.VideoPlayerActivity.showVideoEndScreen(VideoPlayerActivity.java:1375)
05-01 09:40:46.096: E/MessageQueue-JNI(18500):  at com.packagename.ui.activities.VideoPlayerActivity.onBackPressed(VideoPlayerActivity.java:1587)
05-01 09:40:46.096: E/MessageQueue-JNI(18500):  at android.app.Activity.onKeyUp(Activity.java:2193)
05-01 09:40:46.096: E/MessageQueue-JNI(18500):  at android.view.KeyEvent.dispatch(KeyEvent.java:2664)
05-01 09:40:46.096: E/MessageQueue-JNI(18500):  at android.app.Activity.dispatchKeyEvent(Activity.java:2423)
05-01 09:40:46.096: E/MessageQueue-JNI(18500):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1962)

Respostas:

1 para resposta № 1

Veja a resposta para uma pergunta semelhante aqui:

Android: java.lang.ClassCastException: android.widget.imageView não pode ser transmitido para android.widget.textView

Eclipse tende a atrapalhar seus recursos agorae depois. Isso leva a algum comportamento estranho, como seqüências de caracteres e imagens sendo trocadas por todo o lado seu aplicativo e, geralmente, classCastException (s), que acontecem quando O Eclipse muda os IDs de seus modos de exibição.

Algumas soluções para esse problema:

Limpe seu projeto.

Modifique um arquivo de layout xml e salve.

Exclua seu arquivo R. (Não se preocupe, ele será gerado automaticamente novamente).

Basicamente, qualquer coisa que faça o seu projeto reconstruir e gerar novamente o Arquivo R.