System.NotSupportedException: 'Unable to activate instance of type Java.Lang.Runnable

Hi there,


I use Xamarin shell navigation in my project and I have been encountering a particular problem and it happens randomly. This is my scenario. I have a SfButton in my page. The button has to navigate the user to another page using Shell navigation.

The app throws the following message and the app crashes:

System.NotSupportedException: 'Unable to activate instance of type Java.Lang.Runnable from native handle 0x7fd049a434 (key_handle 0x633ca33).'

These are the varieties of messages thrown:

System.NotSupportedException: 'Unable to activate instance of type Java.Lang.Runnable from native handle 0x7fd049a434 (key_handle 0xfc397b6).'


System.NotSupportedException: 'Unable to activate instance of type Java.Lang.Runnable from native handle 0x7fd049a434 (key_handle 0xfc397b6).'


System.NotSupportedException: 'Unable to activate instance of type Java.Lang.Runnable from native handle 0x7fd049a434 (key_handle 0x6a95d0b).'


System.NotSupportedException: 'Unable to activate instance of type Java.Lang.Runnable from native handle 0x7fd049a6c4 (key_handle 0x100f0a).'


I have tried updating to the release 19.2.0.55, yet this is not resolved. An additional information is I tried putting debug points in the target page and ran it several times. The control goes to that page and every time the page loaded successfully. But the moment I removed all debug points, the message starts to show up.

I need a solution immediately, as I'm nearing the release date and I still could not figure out what the problem is. All searches on the Internet leads to this link wherein a similar problem appears to be fixed earlier related to navigation drawer. It would be great if you could help me to resolve this. Please let me know if there is a work around for this in the interim.

Edit: I use Visual Studio 2019

Thanks

Santhosh



7 Replies

YP Yuvaraj Palanisamy Syncfusion Team September 13, 2021 06:07 PM UTC

Hi Santhosh Kumar, 
 
Greetings from Syncfusion. 
 
We have analyzed your query and we have checked the reported problem “SfButton throws exception when inside the in Xamarin.Forms shell navigation” and it was working fine at our end. Also, we have tested the below configuration. 
 
Configuration Detail: 
 
Syncfusion package version: 19.2.0.60 
 
Android target device: Samsung Galaxy API 10.

Xamarin.Forms version: 5.0.0.2020
 
 
Also, we have attached the test sample for your reference. Please find the sample from the below link. 
 
  
Also, we would like to suggest to resolve this by by using Task.Delay() method as per the below code example. 
 
private async void ShowButton_Clicked(object sender, EventArgs e)  
 
            const string routePath = nameof(ButtonPage);  
            await Task.Delay(50);  
            await Shell.Current.GoToAsync($"{routePath}?UserID=101");  
 
  
Could you please check the above sample, if still you are facing the problem, please revert us the configuration details which is different from above and if possible, please revert us with the modified sample with issue reproduced state which is helpful to serve you better solution at the earliest. 
 
Regards, 
Yuvaraj. 



SK Santhosh Kumar September 14, 2021 09:22 AM UTC

Dear Yuvaraj,


I will try this solution and let you know.

I'm also having a problem with SfListview:

I have a label and Sfcombobox in my SfListview. The source for the combobox is dependent on the label value in each list item. For example, if the label has dr name, then the combobox will have address of the hospitals where he works. It is OK until this part.


The list view has 100 items but only 6 items shows up for the initial display. The problem starts now:

  1. the items loaded in the combobox for the first 6 items repeats for the rest of the items: I resolved it by setting up the ListViewCachingStrategy="CreateNewTemplate" and ItemsSourceChangeCachingStrategy="ClearItems"
  2. Now the combobox loads up perfectly for all list items. But if i make a selection in the first listitem and scroll down the list and then come back again to the first item, the selection vanishes and it appears as if the user has not selected anything on the combo.

Is there anything that i need to do to have the selections stay put?


Thanks

Santhosh




YP Yuvaraj Palanisamy Syncfusion Team September 15, 2021 03:34 PM UTC

Hi Santhosh,  
  
We have checked the reported queries from our side.  
  
Query  
Response  
the items loaded in the combobox for the first 6 items repeats for the rest of the items: I resolved it by setting up the ListViewCachingStrategy="CreateNewTemplate" and ItemsSourceChangeCachingStrategy="ClearItems"  
We would like to inform you that the SfListView is completely developed with UI Virtualization(Item recycling) concept and it only creates the element only which are in view on initial loading. While scrolling, we have cache the created elements and recycled it by updating only the BindingContext of the SfListView item. So, we can overcome the reported scenario by binding data for the ComboBox.  
  
You can also refer to our user guidance document to skip reusing items while scrolling in the following link,  
Now the combobox loads up perfectly for all list items. But if i make a selection in the first listitem and scroll down the list and then come back again to the first item, the selection vanishes and it appears as if the user has not selected anything on the combo.  
As we have mentioned above, you can overcome the reported scenario by binding the SfComboBox.SelectedItem to a model property.   
  
Please refer to the following documentation regarding SelectedItem,  
  
Please refer to the following code snippets regarding the same,  
<listView:SfListView x:Name="listView"   
                    ItemsSource="{Binding ContactInfo}"   
                    ItemSpacing="10"  
                    AutoFitMode="Height">  
    <listView:SfListView.ItemTemplate>  
        <DataTemplate>  
            <Frame BorderColor="Blue">  
                <Grid>  
                    <Grid.RowDefinitions>  
                        <RowDefinition Height="0.5*"/>  
                        <RowDefinition Height="0.5*"/>  
                    </Grid.RowDefinitions>  
  
                    <sfCombo:SfComboBox  Grid.Row="0" Text="Selecione uma cor"   
                                        DataSource="{Binding ContactDetails}"  
                                        SelectedItem="{Binding ComboBoxSelectedItem, Mode=TwoWay}"   
                                        DisplayMemberPath="ContactName" >  
                        <sfCombo:SfComboBox.ItemTemplate>  
                            <DataTemplate>  
                                <StackLayout >  
                                    <Label Text="{Binding ContactName}" VerticalTextAlignment="Center" />  
                                </StackLayout>  
                            </DataTemplate>  
                        </sfCombo:SfComboBox.ItemTemplate>  
                    </sfCombo:SfComboBox>  
                    <Label Grid.Row="1" Text="{Binding Location}"/>  
                </Grid>  
            </Frame>  
        </DataTemplate>  
    </listView:SfListView.ItemTemplate>  
</listView:SfListView>  
  
We have attached the tested sample and the video in the following link,  
  
Please check our sample and let us know if you need further assistance.  
  
Yuvaraj 



SK Santhosh Kumar replied to Yuvaraj Palanisamy September 20, 2021 04:01 AM UTC

Dear Yuvaraj,


First query regarding the java exception: It doesn't work after adding the delay of 50 millisecs. I'm yet to check by increasing the delay further.


Second query about the listview:

  1. I have two models: one for the listview data and one for the combobox.
  2. The combo box is populated in the descendant added event of the listview. I do this because, the datasource for the combobox is based on a parameter from the listview's model and this is the only event where i can intercept the combobox while loading.
  3. Once the combobox is loaded and user makes a selection, the listview's model gets updated on the selection changed event of the combobbox. this is the model that will be updated to the database.

All the above works fine functionality wise. The only problem i have is that the user selection on the combobox is not sustained across scrolling of the listview.


I use a Lenovo Tab M10 FHD plus. with Android 10 as minimum version (API 29-Q)


Thanks


Santhosh



YP Yuvaraj Palanisamy Syncfusion Team September 21, 2021 02:39 PM UTC

 
# SfButton: java exception- shell navigate to SfButton page.

Could you please check by increasing the delay further and let us know. if still you are facing the problem, please share us the following details.
 
·       Button package version 
·       Android OS version and device 
·       Button code snippet used in your project or if possible please share the modified sample with issue reproduced state which will be helpful to provide you better solution at the earliest.  
 
# SfListView query 

 
Thank you for the update.  
  
We have checked the reported query “the user selection on the combobox is not sustained across scrolling of the listview” from our side. We suggest you to bind the SelectedItem to the the model property to maintain the selected item while scrolling.   
  
Please refer to the following code snippets for more reference,  
<sfCombo:SfComboBox  Grid.Row="0"   
                DataSource="{Binding ContactDetails}"  
                SelectionChanged="SfComboBox_SelectionChanged"  
                SelectedItem="{Binding ComboBoxSelectedItem, Mode=TwoWay}"   
                DisplayMemberPath="ContactName" >  
  
  
We have prepared a sample based on your scenario and attached in the following link,  
  
Please check our sample and let us know if you still facing the same issue? If not, please modify our sample based on your scenario and revert us back with the issue replication video. It will be really helpful for us to check on it and provide you the solution as soon as possible.  
  
Yuvaraj 



SK Santhosh Kumar replied to Yuvaraj Palanisamy September 22, 2021 10:24 AM UTC

Dear Yuvaraj,


# SfButton: java exception- shell navigate to SfButton page.

I have increased the delay upto 300 milliseconds, the problem still occurs. I could not increase the delay further as there is an evident delay in the loading of the target page. Below is what the button_click event has:

 private async void btnDrListBE_Clicked(object sender, EventArgs e)

        {

            await Task.Delay(300);

            await Shell.Current.GoToAsync($"//{nameof(Menu)}/{nameof(BEDrListEntry)}");

        }

The button does nothing else. The exception message comes once in 5-10 attempts and does not always occur.

Button package version : 19.2.0.60
·       Android OS version and device : Android version 10, device: Lenovo TB-X606V 

# SfListView query 

the combobox is bound to a model. Below is what i'm doing. Value is the property in the model:




Thanks


Santhosh



YP Yuvaraj Palanisamy Syncfusion Team September 23, 2021 11:18 AM UTC

Hi Santhosh,

 
# SfButton: java exception- shell navigate to SfButton page 
 
We are unable to reproduce the stated issue at our end due to a lack of knowledge about your project layout scenario. Hence, could you please modify the sample with your shell layout scenario to reproduce the reported issue so that we can assist you with a better solution as soon as possible. 
 
#Regarding SfListView query  
  
We would like to inform you that we need to invoke the PropertyChanged event for the model property which bound to theSfComboBox.SelectedItem API to update the run time changes in the UI.  
  
Please refer to the following code snippets for more reference,  
public class ContactInfo_NestedListView : INotifyPropertyChanged  
{  
    private object comboBoxSelectedItem;  
  
    public object ComboBoxSelectedItem  
    {  
        get { return comboBoxSelectedItem; }  
        set   
        {   
            comboBoxSelectedItem = value;   
            this.RaisedOnPropertyChanged("ComboBoxSelectedItem");  
        }  
    }  
    ...  
      
    public event PropertyChangedEventHandler PropertyChanged;  
  
    public void RaisedOnPropertyChanged(string _PropertyName)  
    {  
        if (PropertyChanged != null)  
        {  
            PropertyChanged(thisnew PropertyChangedEventArgs(_PropertyName));  
        }  
    }  
}  
  
Please ensure that the value property is a type of object and it invokes the Propertychanged event. If you still facing the same issue, kindly modify our sample to replicate the issue or share the following details which will be helpful for us to check on it and provide you the solution as soon as possible.  
  • Share SfListView and SfComboBox code snippets
  • Share Model and ViewModel files
  • Share issue reproducing video
  • Share device configuration details
  • Share Syncfusion and Xamarin.Forms versions
 
Regards, 
Yuvaraj. 


Loader.
Up arrow icon