Next thing:
java.lang.NoSuchMethodError:
java.util.Date.from(Ljava/time/Instant;)Ljava/util/Date;
its running on desktop but not deployed on mobile..
Thanks for any suggestion..
Most of the java.util.Date class works on mobile (Android and iOS). However there a few cases that are not available.
On Android or iOS if you try
Date date = Date.from(Instant.now());
that refers to the Java 8 static method Date.from(Instant), you'll get the exception you mentioned:
W System.err: Caused by: java.lang.NoSuchMethodError: No static method from(Ljava/time/Instant;)Ljava/util/Date; in class Ljava/util/Date; or its super classes (declaration of 'java.util.Date' appears in /system/framework/core-oj.jar)
To solve this issue, you can use the usual constructor instead, which is in turn what the static method uses:
// Android, iOS
Date date = new Date(Instant.now().toEpochMilli()));
Alternatively you can use the new java.time package.
Related
Trying to use Prism 8, ContainerLocator, IHttpClientFactory and Platform-Specific Service registration with DryIoc Extensions (not Magician) in a Xamarin Forms application
I have these nuget packages installed
Prism.DryIoc.Extensions
Prism.Forms
My main Xamarin Application inherits from PrismApplicationBase.
In platform code (eg Android) I have IPlatformInitializer implented by MainActivity and for platform-specific services I use:
LoadApplication(new App(this));
as documented here:
https://prismlibrary.com/docs/dependency-injection/platform-specific-services.html
This line causes the IContainerExtension to be resolved in the shared code
protected override IContainerExtension CreateContainerExtension()
...but I can't find a way to successfully return a valid IContainerExtension implementation.
I've attempted:
https://prismlibrary.com/docs/dependency-injection/container-locator.html
var createContainerExtension = () => new DryIocContainerExtension();
ContainerLocator.SetContainerExtension(createContainerExtension);
But the code given here can't even compile - the DryIocContainerExtension class created is defined INTERNAL and isn't available to my application code.
If I use...
PrismContainerExtension.Init();
or
return ContainerLocator.Current;
...as worked previously (eg Prism 7.2) I get a runtime error as described here:
https://githubmemory.com/repo/dansiegel/Prism.Container.Extensions/issues/180
ValueFactory attempted to access the Value property of this instance.
Please can someone advise what I'm doing wrong, or do I have to get my company to pay for Magician to resolve my issue?
I upgraded to Xamarin.Forms 4.2. For Android, it crashed immediately after launch.
The error message is
Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code).
After tracing through the code, the app has launched and there is no code left to execute. Then, it crashed.
Thanks Lucas. As suggested, in SplashActivity.cs, change the class declaration to
public class SplashActivity : global::Android.Support.V7.App.AppCompatActivity
I have my UWP Application inherited from Base class, which inherits from MvxApplication<Setup, CoreApp>:
public sealed partial class App : WindowsApplication
{
public App()
{
InitializeComponent();
}
}
public class WindowsApplication : MvxApplication<Setup, CoreApp>
{
}
public class Setup : MvxWindowsSetup<CoreApp>
{
public override IEnumerable<Assembly> GetViewAssemblies()
{
// need to do this as otherwise I receive the message that corresponding view to view model is not found
var assemblies = base.GetViewAssemblies().ToList();
assemblies.Add(typeof(Forms.App).Assembly);
return assemblies;
}
}
However, when launching it, receiving the following error message:
The type MvxContentPagePresentationAttribute is not configured in the
presenter dictionary
As I understand, all that is not proper way to launch Xamarin.Forms MvvmCross application, as UWP App and Setup should be inherited from something like MvxFormsApplication and MvxFormsWindowsSetup<CoreApp, Forms.App> respectively (to have Xamarin.Forms app properly initialized).
But:
MvxFormsApplication is not generic and doesn't provide ability of passing Forms-generic setup.
even if I inherit the App from MvxFormsApplication and use this.RegisterSetupType<MvxFormsWindowsSetupInheritor>();, Visual Studio compiler never allows me to compile the project because of some weird error message (something like The name “WindowsApplication” does not exist in the namespace “…”) (this might be some issue of Visual Studio, but I have VS 15.7 version, which expects the code to work (again, MvvmCross declares they support UWP and XF)).
So, from my understanding, if there is Xamarin.Forms app, there must be also some way of passing actually Xamarin.Forms App class to the UWP App class initialization.
MvvmCross, again, stands for UWP and Xamarin.Forms support, but I can't see any clear example of the way to setup such type of application.
MvvmCross documentation as always is quite "modest". There are some instructions about setting up MvvmCross UWP app as well as setting up MvvmCross XF iOS/Android, but the only word about MvvmCross XF UWP is:
You are now free to place your custom renderers in a different
assembly. All you have to do to make it work is to add your assembly
to the Setup.ViewAssemblies collection.
(in official website docs)
(which is still sounds weird, as iOS and Android versions don't need that additional code, which makes me think that such (current) documentation isn't quite actualized)
and
UWP, WPF
Extend App from MvxApplication. ( App : MvxApplication { } )
from MvvmCross.Forms package readme.txt file, when all other platforms, again, expect inheritance for the app classes from MvxForms*-based ones.
MvvmCross guys, any thoughts on that?
When I set up a new Xamarin.Forms project, I always follow the Playground sample in the MvvmCross GitHub as this example evolves along with the API and is always up-to-date, as it is part of the MvvmCross solution, so any commits need to preserve its functionality. So if you want to see how everything should look in a minimal UWP + Xamarin.Forms project see the Playground.Forms.UI and Playground.Forms.Uwp projects in the linked folder.
I'm trying to migrate a program from java 8 to java 9.
In my program I found the following code.
//Run JavaFX Application Thread/Toolkit
PlatformImpl.startup(() -> {
});
It tries to start the JavaFX Toolkit
Unfortunately, the PlatformImpl.startup is no longer supported in java 9.
Which substitute is there for it?
How can I start the JavaFX Toolkit?
Thank you
The startup() method is one of the methods that was promoted from the non-public class PlatformImpl to the public API Platform class in the Java 9 release. It is now fully documented in the API documentation.
Thus the equivalent call in Java 9 is
Platform.startup(() -> { });
Note that the use cases for this method are fairly rare, and the API docs go to some lengths to emphasize this:
In general it is not necessary to explicitly call this method, since it is invoked as a consequence of how most JavaFX applications are built.
...
As noted, it is normally the case that the JavaFX Application Thread is started automatically. It is important that this method only be called when the JavaFX runtime has not yet been initialized. Situations where the JavaFX runtime is started automatically include:
For standard JavaFX applications that extend Application, and use either the Java launcher or one of the launch methods in the Application class to launch the application, the FX runtime is initialized automatically by the launcher before the Application class is loaded.
For Swing applications that use JFXPanel to display FX content, the FX runtime is initialized when the first JFXPanel instance is constructed.
For SWT application that use FXCanvas to display FX content, the FX runtime is initialized when the first FXCanvas instance is constructed.
When an application does not follow any of these common approaches, then it becomes the responsibility of the developer to manually start the JavaFX runtime by calling this startup method.
Calling this method when the JavaFX runtime is already running will result in an IllegalStateException being thrown - it is only valid to request that the JavaFX runtime be started once.
So, while you are in the process of making the changes you need to update your application to be Java 9 compatible, you might want to carefully consider if you need to call startup() at all; maybe there is a more standard and robust approach to starting your JavaFX application anyway.
I'm using Xamarin.Forms and Prism 6.3.0
I have a class in the iOS project where I want to use the IEventAggregator. When I'm passing the IEventAggregator as a parameter to the constructor of the class, the application crashes.
A clarification, I'm trying to publish from the iOS class, not to subscribe to an event published by Xamarin.Forms.
How can I use the IEventAggregator inside a class in iOS project of Xamarin.Forms?
I don't know if there is a more elegant solution, but there is one that is working. You'll have to add the dependency to your container manually with the correct injection parameters.
In your platform specific project (iOS in this case, but it holds for Android, too) change the following line
this.LoadApplication(new App());
to
var app = new App();
this.LoadApplication();
Given your App is a PrismApplication you can now access the IUnityContainer and register your type manually
var app = new App();
app.Container.RegisterType(typeof(IServiceService),
typeof(MyServiceService),
string.Empty,
new ContainerControlledLifetimeManager(),
new InjectionConstructor(new ResolvedParameter(typeof(IEventAggregator))));
this.LoadApplication(app);
Now Unity should be able to resolve MyServiceService correctly and your app should not crash anymore. Maybe you have to remove
[assembly: Xamarin.Forms.Dependency(typeof(MyServiceService)]
but I have not tried if it crashed if it's not removed.
The answer to the question is here
In short, in the class in the iOS project add the using statement using Microsoft.Practices.Unity; and in the constractor of the class add
var ea = ((App)Xamarin.Forms.Application.Current).Container.Resolve<IEventAggregator>();
in order to get the EventAggregator.
Then you can use it to publish a message i.e.
ea.GetEvent<SomeEvent>().Publish(somePayload);