0

when launching this activity i get this awkward error

java.lang.ClassCastException: com.example.com.kada.view.pzv.PullToZoomScrollViewEx cannot be cast to com.example.com.kada.view.pzv.PullToZoomListViewEx

my Activity (ZoomActivity)

package com.example.com.kada;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ListView;

import com.example.com.kada.adhss.PullToZoomScrollViewEx;
import com.example.com.kada.view.pzv.PullToZoomListViewEx;


public class ZoomActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zoom);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        PullToZoomListViewEx listView = (PullToZoomListViewEx) findViewById(R.id.paralax_social_list_view);
       listView.setShowDividers(0);

       // PullToZoomListViewEx listView = (PullToZoomListViewEx) findViewById(R.id.paralax_social_list_view);
       // listView.setShowDividers(0);

    }

}

the Layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_blog_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@color/hss_background"
    tools:context="com.example.kada.blogListActivity">


    <com.example.kada.view.pzv.PullToZoomScrollViewEx
        android:id="@+id/paralax_social_list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@android:color/transparent"
        app:headerView="@layout/header_parallax_social" />




</RelativeLayout>

How to solve this problem despite i'm put the same code in other project that serve the dependency com.android.support:support-v4:21.0.3 and it looks fine

and now i'm using com.android.support:appcompat-v7:25.3.1

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Houssem Cherif
  • 221
  • 1
  • 11

1 Answers1

1

com.example.com.kada.view.pzv.PullToZoomScrollViewEx is not subclass of com.example.com.kada.view.pzv.PullToZoomListViewEx so it cannot be casted. This is what exception message is clearly trying to tell you.

Your layout uses PullToZoomScrollViewEx but you cast what findViewById() returns to PullToZoomListViewEx. Either fix the casting to use correct class or ensure class has the same ancestors.

Also if you switch to use use SDK 26 to compile, see Android O casting to findViewById not needed anymore?, however this will still throw the exception if you use wrong classes.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • Thank you so much ** you save my day ** and don't blame me about this basic error – Houssem Cherif Sep 09 '17 at 14:05
  • I am not blaming you. I am answering you help request by pointing out the errors you were unable to spot yourself which was the main reason you asked. I hope you should know how to interpret the exception message and that it's worth reading it carefuly in first place :) – Marcin Orlowski Sep 09 '17 at 14:42