APPY SHAH
APPY SHAH

Reputation: 7

NoClassDefFoundError:android.view.ViewAnimatorUtils

I have the following scenario : on button click dialog should be open in a circular reveal effect.So I have implemented the code.On button click I am facing error NoClassDefFoundError:android.view.ViewAnimatorUtils. Below is my code

MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button=(Button)findViewById(R.id.button2);
        linearLayout=(LinearLayout) findViewById(R.id.linearLay);
        button.setOnClickListener(new View.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder=new AlertDialog.Builder(getApplicationContext());
                int x=view.getWidth()/2;
                int y=view.getHeight()/2;
                int finalRadius=Math.max(x,y)/2;
                Animator anim= ViewAnimationUtils.createCircularReveal(linearLayout,x,y,0,finalRadius);
                anim.start();
                builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });
                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });
            }
        });
    }

MainActivity.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        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"
        tools:context="com.example.dhaval.assignment10a.MainActivity">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            android:id="@+id/textView" />

        <Button
            android:text="Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button2"
            android:layout_marginLeft="50sp"
            android:layout_marginTop="50sp" />

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/textView"
            android:layout_marginTop="16dp"
            android:id="@id/linearLay">

        </LinearLayout>

    </RelativeLayout>

Log

E/AndroidRuntime: FATAL EXCEPTION: main
                  java.lang.NoClassDefFoundError: android.view.ViewAnimationUtils
                      at com.example.dhaval.assignment10a.MainActivity$1.onClick(MainActivity.java:34)
                      at android.view.View.performClick(View.java:4084)
                      at android.view.View$PerformClick.run(View.java:16966)
                      at android.os.Handler.handleCallback(Handler.java:615)
                      at android.os.Handler.dispatchMessage(Handler.java:92)
                      at android.os.Looper.loop(Looper.java:137)
                      at android.app.ActivityThread.main(ActivityThread.java:4745)
                      at java.lang.reflect.Method.invokeNative(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:511)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                      at dalvik.system.NativeStart.main(Native Method)

Upvotes: 0

Views: 318

Answers (2)

Mariusz Wiazowski
Mariusz Wiazowski

Reputation: 2446

What @Diveno says is correct, but if you don't want to set minsdk to 21 you can add this check before instantiating the object:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    //now you can use ViewAnimationUtils
}

Upvotes: 0

Diego
Diego

Reputation: 1488

ViewAnimationUtils was added in API level 21, you need to set minsdk to 21

Upvotes: 1

Related Questions