I want each Entry type in my in my StackLayout to have a margin. I'm trying to specify a style as follows:
<StackLayout IsVisible="{Binding IsLoggingIn, Converter={StaticResource BooleanConverter}}">
<StackLayout.Resources>
<Style TargetType="{x:Type Entry}">
<Setter Property="Margin" Value="0,0,0,20"/>
</Style>
</StackLayout.Resources>
<Entry ... />
<Entry ... />
</StackLayout>
Unfortunately, it results in a NullReferenceException:
04-13 16:26:15.406 E/mono (17167): Unhandled Exception:
04-13 16:26:15.406 E/mono (17167): System.NullReferenceException: Object reference not set to an instance of an object.
04-13 16:26:15.406 E/mono-rt (17167): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
With a bit more stack trace for reference:
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at MyApp.Views.Login.InitializeComponent () [0x00012] in C:\dev\PathTo\MyApp\obj\Debug\MyApp.Views.Login.xaml.g.cs:22
at MyApp.Views.Login..ctor () [0x00008] in C:\dev\PathTo\MyApp\Views\Login.xaml.cs:9
at MyApp.App.SetupLoginPage () [0x00001] in C:\dev\PathTo\MyApp\App.xaml.cs:94
at MyApp.App+<OnStart>d__4.MoveNext () [0x001ad] in C:\dev\PathTo\MyApp\App.xaml.cs:60
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4009/3a62f1ea/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
at Android.App.SyncContext+<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:35
at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/4009/3a62f1ea/source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in /Users/builder/data/lanes/4009/3a62f1ea/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Java.Lang.IRunnable.cs:81
at (wrapper dynamic-method) System.Object:d83972de-0492-4d07-a14d-24725ac1bfd1 (intptr,intptr)
What could be causing this, and how can I fix it? For the record, if I specify the margin inline e.g. <Entry margin="0,0,0,20"/>, it works fine.
I think your syntax is wrong. Shouldn't it be this;
<StackLayout.Resources>
<ResourceDictionary>
<Style TargetType="Entry">
<Setter Property="Margin" Value="0,0,0,20"/>
</Style>
</ResourceDictionary>
</StackLayout.Resources>
Note how I changed the TargetType and added the ResourceDictionary tag around it.
Related
I want to make a animation like
<Style.Animations>
<Animation Duration="0,0,1" PlaybackDirection="Normal" FillMode="None">
<KeyFrame KeyTime="0.5">
<Setter Property="Width" Value="{TemplateBinding Width}" />
<Setter Property="Height" Value="{TemplateBinding Height}" />
</KeyFrame>
</Animation>
</Style.Animations>
but it tell me Unable to cast object of type 'Avalonia.Animation.AnimatorKeyFrame' to type 'Avalonia.IStyledEleme;
How can I Solve the problem?
I am trying to build Xamarin Forms Android App but it's not getting compiled in Release mode, while Debug works fine.
Error Detail:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(5,5):
Error MSB4018: The "LinkAssemblies" task failed unexpectedly.
Mono.Linker.Steps.XmlResolutionException: Failed to process XML
description: --->
Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly:
'Prism.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Prism.Core, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null' at Mono.Cecil.BaseAssemblyResolver.Resolve
(Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters
parameters) [0x0015e] in
/Users/builder/data/lanes/6102/8255f42f/source/monodroid/external/xamarin-android/external/mono/external/cecil/Mono.Cecil/BaseAssemblyResolver.cs:172
at Mono.Linker.AssemblyResolver.Resolve
(Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters
parameters) [0x0005c] in <947dd92f52fa43c1922f96c7b9774bdc>:0 at
Mono.Linker.LinkContext.Resolve (Mono.Cecil.IMetadataScope scope)
[0x00007] in <947dd92f52fa43c1922f96c7b9774bdc>:0 --- End of inner
exception stack trace --- at Mono.Linker.LinkContext.Resolve
(Mono.Cecil.IMetadataScope scope) [0x00030] in
<947dd92f52fa43c1922f96c7b9774bdc>:0 at
Mono.Linker.Steps.ResolveFromXmlStep.GetAssembly
(Mono.Linker.LinkContext context, Mono.Cecil.AssemblyNameReference
assemblyName) [0x00000] in <947dd92f52fa43c1922f96c7b9774bdc>:0 at
Mono.Linker.Steps.ResolveFromXmlStep.ProcessAssemblies
(Mono.Linker.LinkContext context, System.Xml.XPath.XPathNodeIterator
iterator) [0x00010] in <947dd92f52fa43c1922f96c7b9774bdc>:0 at
Mono.Linker.Steps.ResolveFromXmlStep.Process () [0x00037] in
<947dd92f52fa43c1922f96c7b9774bdc>:0 --- End of inner exception
stack trace --- at Mono.Linker.Steps.ResolveFromXmlStep.Process ()
[0x000a9] in <947dd92f52fa43c1922f96c7b9774bdc>:0 at
Mono.Linker.Steps.BaseStep.Process (Mono.Linker.LinkContext context)
[0x00010] in <947dd92f52fa43c1922f96c7b9774bdc>:0 at
Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context)
[0x0001c] in <947dd92f52fa43c1922f96c7b9774bdc>:0 at
MonoDroid.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline,
Mono.Linker.LinkContext context) [0x00000] in
<947dd92f52fa43c1922f96c7b9774bdc>:0 at
MonoDroid.Tuner.Linker.Process (MonoDroid.Tuner.LinkerOptions options,
Mono.Linker.ILogger logger, Mono.Linker.LinkContext& context)
[0x00071] in <947dd92f52fa43c1922f96c7b9774bdc>:0 at
Xamarin.Android.Tasks.LinkAssemblies.Execute
(Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x002d4] in
<947dd92f52fa43c1922f96c7b9774bdc>:0 at
Xamarin.Android.Tasks.LinkAssemblies.Execute () [0x0021f] in
<947dd92f52fa43c1922f96c7b9774bdc>:0 at
Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute
() [0x00023] in
/Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:573
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask
(Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost,
Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext,
Microsoft.Build.BackEnd.TaskHost taskHost,
Microsoft.Build.BackEnd.ItemBucket bucket,
Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x001f6]
in
/Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:784
(MSB4018) (VSTSBuild.Droid)
Also I noticed that it's building in Release mode as well if I enable 'Use Shared Mono Runtime' but if it's disabled then I am having issue building the solution.
Okay, I found out that issue was with LinkerSettings. Previously my Linker Settings was like this:
<linker>
<assembly
fullname="Prism.Core" />
<assembly
fullname="Prism.Forms" />
<assembly
fullname="Prism.Unity.Forms" />
<assembly
fullname="Prism.Plugin.Popups" />
</linker>
Which I updated to:
<linker>
<assembly
fullname="Prism.Forms">
<type
fullname="Prism.Common.ApplicationProvider"
preserve="all" />
<type
fullname="Prism.Services.PageDialogService"
preserve="all" />
<type
fullname="Prism.Services.DeviceService"
preserve="all" />
<type
fullname="Prism.Ioc*"
preserve="all" />
<type
fullname="Prism.Modularity*"
preserve="all" />
<type
fullname="Prism.Navigation*"
preserve="all" />
<type
fullname="Prism.Behaviors.PageBehaviorFactory"
preserve="all">
<method
name=".ctor" />
</type>
<type
fullname="Prism.Services.DependencyService"
preserve="all">
<method
name=".ctor" />
</type>
</assembly>
<assembly
fullname="Prism">
<type
fullname="Prism.Navigation*"
preserve="all" />
<type
fullname="Prism.Logging.EmptyLogger"
preserve="all">
<method
name=".ctor" />
</type>
</assembly>
</linker>
Now App is building fine in Release mode as well.
I did some research but I could't find an answer specific to my problem. I have an XF app and using the following code to style my Label:
<Style x:Key="Heading2Text" TargetType="Label">
<Setter Property="FontSize">
<Setter.Value>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="iOS" Value="{DynamicResource Heading2TextFontSizeiOS}"/>
<On Platform="Android" Value="{DynamicResource Heading2TextFontSizeAndroid}"/>
</OnPlatform>
</Setter.Value>
</Setter>
</Style>
And in my resource:
Current.Resources["Heading2TextFontSizeiOS"] = 10.75 * vScale;
Current.Resources["Heading2TextFontSizeAndroid"] = 20.5 * vScale;
This is giving me an error: Specified cast is not valid
But if I specify the value like the below code then it works.
<Style x:Key="Heading2Text" TargetType="Label">
<Setter Property="FontSize">
<Setter.Value>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="iOS" Value="14"/>
<On Platform="Android" Value="20"/>
</OnPlatform>
</Setter.Value>
</Setter>
</Style>
Anyone knows what I'm doing wrong here?
Edits:
I realized what the problem is. Current.Resources["Heading2TextFontSizeiOS"] is an object hence the error. Any one has any suggestion how to work around this?
vScale is declared in the App.xaml.cs like this:
public static double vScale;
And in the resource class:
vScale = height > 700 ? 1.4 : height / 568;
This is the exception I'm getting:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Specified cast is not valid.
at Xamarin.Forms.OnPlatform`1[T].op_Implicit (Xamarin.Forms.OnPlatform`1[T] onPlatform) [0x00036] in D:\a\1\s\Xamarin.Forms.Core\OnPlatform.cs:75
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0003b] in <d4a23bbd2f544c30a48c44dd622ce09f>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00054] in <d4a23bbd2f544c30a48c44dd622ce09f>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <d4a23bbd2f544c30a48c44dd622ce09f>:0
at Xamarin.Forms.BindableProperty.TryConvert (System.Object& value) [0x000cf] in D:\a\1\s\Xamarin.Forms.Core\BindableProperty.cs:341
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00041] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:386
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0003d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:572
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:356
at Xamarin.Forms.Setter.Apply (Xamarin.Forms.BindableObject target, System.Boolean fromStyle) [0x000ba] in D:\a\1\s\Xamarin.Forms.Core\Setter.cs:75
at Xamarin.Forms.Style.ApplyCore (Xamarin.Forms.BindableObject bindable, Xamarin.Forms.Style basedOn) [0x0001e] in D:\a\1\s\Xamarin.Forms.Core\Style.cs:132
at Xamarin.Forms.Style.Xamarin.Forms.IStyle.Apply (Xamarin.Forms.BindableObject bindable) [0x0002b] in D:\a\1\s\Xamarin.Forms.Core\Style.cs:95
at Xamarin.Forms.MergedStyle.SetStyle (Xamarin.Forms.IStyle implicitStyle, System.Collections.Generic.IList`1[T] classStyles, Xamarin.Forms.IStyle style) [0x00156] in D:\a\1\s\Xamarin.Forms.Core\MergedStyle.cs:180
at Xamarin.Forms.MergedStyle.set_Style (Xamarin.Forms.IStyle value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\MergedStyle.cs:37
at Xamarin.Forms.NavigableElement+<>c.<.cctor>b__20_0 (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Shell\NavigableElement.cs:16
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:624
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:422
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0003d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:572
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:122
at Xamarin.Forms.VisualElement.set_Style (Xamarin.Forms.Style value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:394
There are two different things to look at.
First:
That is a current limitation in using XAML-based DynamicResource with OnPlatform.
This should work but does not:
<Style x:Key="Heading2Text" TargetType="Button">
<Style.Setters>
<Setter Property="FontSize">
<OnPlatform x:TypeArguments="x:Double">
<On Platform="Android">
<DynamicResource Key="Heading2TextFontSizeAndroid" />
</On>
</OnPlatform>
</Setter>
</Style.Setters>
</Style>
You can do it in code:
someLabelInstance.SetDynamicResource(Label.FontSizeProperty, "Heading2TextFontSizeAndroid");
Resources["Heading2TextFontSizeAndroid"] = 10 * 4.0;
Note: I have seen this issue floating around for a number of years, so if there is a way to directly use a DynamicResource w/OnPlatform in XAML vs. converting it to a StaticResource, I would love to see it 😉
It will work if you convert it to use a StaticResource, but of course that defeats the possible if you really need to change those properties in a dynamic way.
Second:
Do you really need this to be a dynamically bound property?
Seems like this might be a device specific calculation you are performing and thus is can be done once. Also static resources are faster and use less memory as all dynamic resources are basically bound properties.
If vScale = height > 700 ? 1.4 : height / 568; can be calculated BEFORE you instance your ContentPage and does not change during the life of that page instance, you can use a StaticResource and just update its value first.
Example:
App level Resource:
<sys:Double x:Key="Heading2TextFontSizeAndroid">20</sys:Double>
Page level Resource style:
<Style x:Key="Heading2Text" TargetType="Button">
<Style.Setters>
<Setter Property="FontSize">
<OnPlatform x:TypeArguments="x:Double">
<On Platform="Android">
<StaticResource Key="Heading2TextFontSizeAndroid" />
</On>
</OnPlatform>
</Setter>
</Style.Setters>
</Style>
Code:
// Before you instance the page that `Heading2TextFontSizeAndroid` will be use in
vScale = height > 700 ? 1.4 : height / 568;
Resources["Heading2TextFontSizeAndroid"] = vScale;
// Now you can instance the page and `vScale` is applied
var page = new SomeContentPage();
I used this demo to use background location services for my Android project (since Geolocator wouldn't background on Android). I haven't had any problems until yesterday when it gave me the following error:
[ServiceConnection] OnServiceConnected Called
Service Connected
[LocationService] You are about to get location updates via
[Mono] Assembly Ref addref Mono.Security[0xa7dd6ba0] -> System[0xadd5aac0]: 15
[Mono] DllImport attempting to load: '/system/lib/liblog.so'.
[Mono] DllImport loaded library '/system/lib/liblog.so'.
[Mono] DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
[Mono] Searching for '__android_log_print'.
[Mono] Probing '__android_log_print'.
[Mono] Found as '__android_log_print'.
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Java.Lang.IllegalArgumentException: invalid provider: null
[MonoDroid] at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <ab9e0fea7db841c1a1450c120052eb14>:0
[MonoDroid] at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <ab9e0fea7db841c1a1450c120052eb14>:0
[MonoDroid] at Android.Locations.LocationManager.RequestLocationUpdates (System.String provider, System.Int64 minTime, System.Single minDistance, Android.Locations.ILocationListener listener) [0x0007e] in <21f1b0b5ad7242d7afaeceae3e6dbac8>:0
[MonoDroid] at Divco.LocationService.StartLocationUpdates () [0x0003c] in /Users/ediewoelfle/Developer/ancient-bastion-mobile/Droid/Services/LocationService.cs:78
[MonoDroid] at Divco.LocationServiceConnection.OnServiceConnected (Android.Content.ComponentName name, Android.OS.IBinder service) [0x0004f] in /Users/ediewoelfle/Developer/ancient-bastion-mobile/Droid/Services/LocationServiceConnection.cs:42
[MonoDroid] at Android.Content.IServiceConnectionInvoker.n_OnServiceConnected_Landroid_content_ComponentName_Landroid_os_IBinder_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_name, System.IntPtr native_service) [0x00019] in <21f1b0b5ad7242d7afaeceae3e6dbac8>:0
[MonoDroid] at (wrapper dynamic-method) System.Object.31(intptr,intptr,intptr,intptr)
[MonoDroid] --- End of managed Java.Lang.IllegalArgumentException stack trace ---
[MonoDroid] java.lang.IllegalArgumentException: invalid provider: null
[MonoDroid] at android.location.LocationManager.checkProvider(LocationManager.java:2317)
[MonoDroid] at android.location.LocationManager.requestLocationUpdates(LocationManager.java:490)
[MonoDroid] at md587a0a65fe57ffee4ef3988209babfc12.LocationServiceConnection.n_onServiceConnected(Native Method)
[MonoDroid] at md587a0a65fe57ffee4ef3988209babfc12.LocationServiceConnection.onServiceConnected(LocationServiceConnection.java:38)
[MonoDroid] at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1535)
[MonoDroid] at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1563)
[MonoDroid] at android.os.Handler.handleCallback(Handler.java:751)
[MonoDroid] at android.os.Handler.dispatchMessage(Handler.java:95)
[MonoDroid] at android.os.Looper.loop(Looper.java:154)
[MonoDroid] at android.app.ActivityThread.main(ActivityThread.java:6316)
[MonoDroid] at java.lang.reflect.Method.invoke(Native Method)
[MonoDroid] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
[MonoDroid] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="42" android:versionName="0.1" package="com.divcodelivery.divco">
<uses-sdk android:minSdkVersion="23" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application android:label="Divco" android:icon="#drawable/logo_size_icon">
<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.divcodelivery.divco.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/file_paths"></meta-data>
</provider>
</application>
</manifest>
I have located the null locationProvider, however, I am unsure WHY.
I'm trying to create a pop up window that shows a clock (actually what i want is a countdown timer but one thing at a time!), the trouble is when i call the method to show the pop up window containing the clock, the app crashes.
The method is being called from an Activity not a fragment.
Here is the code:
public void clockPopup()
{
LayoutInflater inflater =(LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
View myPopup = inflater.Inflate (Resource.Layout.PopUpClockTimer, null);
RunOnUiThread (() => {
PopupWindow popup = new PopupWindow (myPopup);
});
}
The stack trace is as follows:
[mono] Unhandled Exception:
[mono] Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
[mono] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
[mono] at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in <filename unknown>:0
[mono] at Android.Views.LayoutInflater.Inflate (Int32 resource, Android.Views.ViewGroup root) [0x00000] in <filename unknown>:0
[mono] at FrogPoint.Droid.MainActivity.clockPopup () [0x00020] in /Users/jakememery/Desktop/working Frogpoint/FrogPoint1.2_database/FindTheMonkey.Droid/MainActivity.cs:1548
[mono] at FrogPoint.Droid.MainActivity+<getBeaconData>c__async3.MoveNext () [0x00258] in /Users/jakememery/Desktop/working Frogpoint/FrogPoint1.2_database/FindTheMonkey.Droid/MainActivity.cs:1215
[mono] --- End of stack trace from previous location where exception was thrown ---
[mono] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
[mono] at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0
[mono] at FrogPoint.Droid.MainActivity+<RangingBeaconsInRegion>c__async0.MoveNext () [0x0035d] in /Users/jakememery/Desktop/working Frogpoint/FrogPoint1.2_database/FindTheMonkey.Droid/MainActivity.cs:675
[mono] --- End of managed exception stack trace ---
[mono] android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.AnalogClock
[mono] at android.view.LayoutInflater.createView(LayoutInflater.java:620)
[mono] at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
[mono] at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
[mono] at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
[mono] at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
[mono] at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
[mono] at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
[mono] at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
[mono] at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
[mono] at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
[mono] at dalvik.system.NativeStart.run(Native Method)
[mono] Caused by: java.lang.reflect.InvocationTargetException
[mono] at java.lang.reflect.Constructor.constructNative(Native Method)
[mono] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[mono] at android.view.LayoutInflater.createView(LayoutInflater.java:594)
[mono] ... 10 more
[mono] Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
[mono] at android.os.Handler.<init>(Handler.java:200)
[mono] at android.os.Handler.<init>(Handler.java:114)
[mono] at android.widget.AnalogClock.<init>(AnalogClock.java:57)
[mono] at android.widget.AnalogClock.<init>(AnalogClock.java:67)
Here is the XML i'm trying to inflate:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/customborder"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:orientation="vertical">
<TextView
android:id="#+id/textout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Time sensitive offer" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/logo76" />
<AnalogClock
android:id="#+id/tabAnalogClock"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<DigitalClock
android:id="#+id/tabDigitalClock"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dismiss" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Can anybody see where i'm going wrong here please?
It seems i simply needed to call the method like this:
RunOnUiThread (() => {
clockPopup();
});
It doesn't crash now. But unfortunately neither does it display the pop up. But that's for another post.
You are missing either:
popup.ShowAtLocation(...);
or
popup.ShowAsDropDown(...);
to actually display the popup window.