I am getting crash on this activity when I run the app. This is not due to appcompat as you can see in the stack trace. This is native android ListView class whose method is not found while running the app.
The same app is running properly on other devices. The minSdkVersion = 13 target =23 max =23 and current device of crashing is API 17.
FATAL EXCEPTION: main
java.lang.NoSuchMethodError: android.widget.ListView.setElevation
at com.example.saloni.laughgurumarketingapp.ContentDetails.getValues(ContentDetails.java: 392)
at com.example.saloni.laughgurumarketingapp.ContentDetails.onCreate(ContentDetails.java: 298)
at android.app.Activity.performCreate(Activity.java: 5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: 1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2358)
at android.app.ActivityThread.access$600(ActivityThread.java: 156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1340)
at android.os.Handler.dispatchMessage(Handler.java: 99)
at android.os.Looper.loop(Looper.java: 153)
at android.app.ActivityThread.main(ActivityThread.java: 5297)
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: 833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 600)
at dalvik.system.NativeStart.main(Native Method)
In the code it's just a set elevation method on which it is crashing as you can see in the trace. Similarly it crashed last time on using one of the TextView class method. Why is this happening?
There is no setElevation() method in api 17. You need to only call this on api 21 and higher.
https://developer.android.com/reference/android/view/View.html#setElevation(float)
If you want to call this method on api 21 devices do this:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP){
// Do something for lollipop and above versions
} else{
// do something for phones running an SDK before lollipop
}
You can use ViewCompat.setElevation and your app won't crash on pre-21 systems; however it won't have any effect on those older devices either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With