xamarin / AndroidSupportComponents

Xamarin bindings for Android Support libraries - For AndroidX see https://github.com/xamarin/AndroidX
MIT License
146 stars 56 forks source link

AppCompatSeekBar Min property not bound - setting propert results in runtime exception #117

Closed EnglishDave closed 5 years ago

EnglishDave commented 5 years ago

Xamarin.Android Version (eg: 6.0): 9.0.0.19

Operating System & Version (eg: Mac OSX 10.11): Windows 10

Support Libraries Version (eg: 23.3.0): Xamarin.Android.Support.Design 27.0.2.1

Describe your Issue: When using AppCompatSeekBar, if the Min property is set in code, then a runtime Java.Lang.NoSuchMethodError exception is thrown, No exception thrown when property set in axml. Probable native binding issue.

Notes: Max property can be set in code without throwing exception. Setting Max property first does not resolve issue.

Steps to Reproduce (with link to sample solution if possible):

Create project. Include Xamarin.Android.Support.Design 27.0.2.1 NuGet. Create layout containing AppCompatSeekBar . Set Min property in code, Run

Include any relevant Exception Stack traces, build logs, adb logs:

Loaded assembly: System.Xml.dll [External] Unhandled Exception:

Java.Lang.NoSuchMethodError: no non-static method "Landroid/widget/ProgressBar;.setMin(I)V"

10-09 08:43:15.718 D/Mono (16445): DllImport attempting to load: '/system/lib/liblog.so'. 10-09 08:43:15.718 D/Mono (16445): DllImport loaded library '/system/lib/liblog.so'. 10-09 08:43:15.718 D/Mono (16445): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so'). 10-09 08:43:15.718 D/Mono (16445): Searching for 'android_log_print'. 10-09 08:43:15.718 D/Mono (16445): Probing 'android_log_print'. 10-09 08:43:15.718 D/Mono (16445): Found as 'android_log_print'. 10-09 08:43:15.722 I/MonoDroid(16445): UNHANDLED EXCEPTION: 10-09 08:43:15.791 I/MonoDroid(16445): Java.Lang.NoSuchMethodError: no non-static method "Landroid/widget/ProgressBar;.setMin(I)V" 10-09 08:43:15.791 I/MonoDroid(16445): at Java.Interop.JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x0005b] in <034d4a9852dd45bea9353cc7776c99f0>:0 10-09 08:43:15.791 I/MonoDroid(16445): at Java.Interop.JniType.GetInstanceMethod (System.String name, System.String signature) [0x0000c] in <034d4a9852dd45bea9353cc7776c99f0>:0 10-09 08:43:15.791 I/MonoDroid(16445): at Java.Interop.JniPeerMembers+JniInstanceMethods.GetMethodInfo (System.String encodedMember) [0x00031] in <034d4a9852dd45bea9353cc7776c99f0>:0 10-09 08:43:15.791 I/MonoDroid(16445): at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001c] in <034d4a9852dd45bea9353cc7776c99f0>:0 10-09 08:43:15.791 I/MonoDroid(16445): at Android.Widget.ProgressBar.set_Min (System.Int32 value) [0x00022] in :0 10-09 08:43:15.791 I/MonoDroid(16445): at Malt.Demo.Android.Fragments.SliderSeekbarPageFragment.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) [0x00047] in C:\Work\Dev\ABI\Malt6a\Malt.Demo.Android\Fragments\SliderSeekbarPageFragment.cs:31 10-09 08:43:15.791 I/MonoDroid(16445): at Android.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_osBundle (System.IntPtr jnienv, System.IntPtr nativethis, System.IntPtr native_inflater, System.IntPtr native_container, System.IntPtr native_savedInstanceState) [0x00022] in :0 10-09 08:43:15.791 I/MonoDroid(16445): at (wrapper dynamic-method) System.Object.20(intptr,intptr,intptr,intptr,intptr) 10-09 08:43:15.791 I/MonoDroid(16445): --- End of managed Java.Lang.NoSuchMethodError stack trace --- 10-09 08:43:15.791 I/MonoDroid(16445): java.lang.NoSuchMethodError: no non-static method "Landroid/widget/ProgressBar;.setMin(I)V" 10-09 08:43:15.791 I/MonoDroid(16445): at md53c6d486b8d052215fa6970780cd4e59a.SliderSeekbarPageFragment.n_onCreateView(Native Method) 10-09 08:43:15.791 I/MonoDroid(16445): at md53c6d486b8d052215fa6970780cd4e59a.SliderSeekbarPageFragment.onCreateView(SliderSeekbarPageFragment.java:38) 10-09 08:43:15.791 I/MonoDroid(16445): at android.app.Fragment.performCreateView(Fragment.java:2053) An unhandled exception occured.

10-09 08:43:15.791 I/MonoDroid(16445): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894) 10-09 08:43:15.791 I/MonoDroid(16445): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) 10-09 08:43:15.791 I/MonoDroid(16445): at android.app.BackStackRecord.run(BackStackRecord.java:834) 10-09 08:43:15.791 I/MonoDroid(16445): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452) 10-09 08:43:15.791 I/MonoDroid(16445): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447) 10-09 08:43:15.791 I/MonoDroid(16445): at android.os.Handler.handleCallback(Handler.java:739) 10-09 08:43:15.791 I/MonoDroid(16445): at android.os.Handler.dispatchMessage(Handler.java:95) 10-09 08:43:15.791 I/MonoDroid(16445): at android.os.Looper.loop(Looper.java:135) 10-09 08:43:15.791 I/MonoDroid(16445): at android.app.ActivityThread.main(ActivityThread.java:5254) 10-09 08:43:15.791 I/MonoDroid(16445): at java.lang.reflect.Method.invoke(Native Method) 10-09 08:43:15.791 I/MonoDroid(16445): at java.lang.reflect.Method.invoke(Method.java:372) 10-09 08:43:15.792 I/MonoDroid(16445): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 10-09 08:43:15.792 I/MonoDroid(16445): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 10-09 08:43:15.803 D/Mono (16445): DllImport searching in: '__Internal' ('(null)'). 10-09 08:43:15.803 D/Mono (16445): Searching for 'java_interop_jnienv_throw'. 10-09 08:43:15.803 D/Mono (16445): Probing 'java_interop_jnienv_throw'. 10-09 08:43:15.803 D/Mono (16445): Found as 'java_interop_jnienv_throw'.

newky2k commented 5 years ago

@EnglishDave could you please provide a sample that demonstrates the issue you are experiencing please.

Regards

matsnas commented 5 years ago

I get the same error! seekbar.Max is ok but Min seems to be missing an implementation.

image

Redth commented 5 years ago

How are you using this exactly in your layout file?

I've tested using the Seekbar and setting min works fine. Could you paste an example of the axml layout file usage?

matsnas commented 5 years ago

I'm trying to set it in code as the screenshot above. The axml file doesn't affect the value for the min property. Not sure this is what you're asking for but below is a snippet? Trying to run the code will give a runtime exception as the one EnglishDave posted when the min value is assigned in the Activity code.

           ...
            <LinearLayout
                android:layout_marginTop="8dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TextView
                    style="@style/SmallCaption"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginRight="8dp"
                    android:id="@+id/noEffectLabel"
                    android:text="No effekt" />
                <SeekBar
                    android:id="@+id/Effect" 
                    android:thumb="@drawable/thumb"
                    android:progressDrawable="@drawable/progress"
                    android:layout_gravity="center_vertical"
                    android:min="1"
                    android:max="3"
                    android:layout_weight="1"
                    android:layout_width="0px"
                    android:layout_height="wrap_content" />
                <TextView
                    style="@style/SmallCaption"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="8dp"
                    android:id="@+id/maxEffectLabel"
                    android:gravity="right"
                    android:text="Max effekt" />
            </LinearLayout>
            ,,,
Redth commented 5 years ago

I asked because I am trying to reproduce it not working locally. This all works fine for me.

Redth commented 5 years ago

Try this:

var seekBar = FindViewById<Android.Support.V7.Widget.AppCompatSeekBar>(Resource.Id.appCompatSeekBar);
seekBar.Min = 2;
seekBar.Max = 4;
Redth commented 5 years ago

What I meant, was try invoking FindViewById with the AppCompatSeekBar type.

This seems really odd though and maybe like some weird Samsung implementation error/detail as clearly android.widget.Progress Bar.getMin() exists in android.jar: https://developer.android.com/reference/android/widget/ProgressBar.html#getMin()

matsnas commented 5 years ago

Hi! Thanks for your time! So I don't get the error on my Samsung S9 but do get it on the S6. Even with the AppCompatSeekbar I get the same error. image

I've cleaned, manually deleted the bin and obj folders and rebuilt but still the same error. I'm doing this on a mac with Mojave (OS X 10.14.1) running Visual Studio Community 2017 for Mac Version 7.6.11 (build 9) and Xamarin.Android Version: 9.0.0.20 (Visual Studio Community) if that makes any difference?

jonpryor commented 5 years ago

[ProgressBar.getMin()](https://developer.android.com/reference/android/widget/ProgressBar.html#getMin()) was added in API-26 (Android v8.0).

What version of Android is your S6 running?

matsnas commented 5 years ago

24! What should i do for <26? Offset from 0, e.g. range 4 to 10 (i.e. 7 steps), would be max 6 and min defaults to 0?

Redth commented 5 years ago

Yep, looks like you'll need to add some custom logic to deal with a 0 based range and translate that into your own range.