Hello Everyone,
(writing this text a second time, since the Forum Save Draft does not work )
I have a project a have been working on a few months and for some silly reason I updated the Xamarin Forms packages before the final deployment, and now I have some issues. I do not remember changing anything in the code. This issue appeared 1 day apart.
I am using a Shared Project, with iOS and Android. After the update of the packages, the iOS works fine, but the Android crashes. Here is the error :
Java.Lang.RuntimeException: java.lang.reflect.InvocationTargetException
at --- End of managed exception stack trace ---
at java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at at dalvik.system.NativeStart.main(Native Method)
at Caused by: java.lang.reflect.InvocationTargetException
at at java.lang.reflect.Method.invokeNative(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:515)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at ... 2 more
at Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.MissingMethodException: No constructor found for FormsPortable.ALCBasePage::.ctor(FormsPortable.RootPage)
at System.Activator.CreateInstance (System.Type,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo,object[]) [0x000fd] in /Users/builder/data/lanes/2058/58099c53/source/mono/mcs/class/corlib/System/Activator.cs:270
at System.Activator.CreateInstance (System.Type,object[],object[]) [0x00000] in /Users/builder/data/lanes/2058/58099c53/source/mono/mcs/class/corlib/System/Activator.cs:224
at System.Activator.CreateInstance (System.Type,object[]) [0x00000] in /Users/builder/data/lanes/2058/58099c53/source/mono/mcs/class/corlib/System/Activator.cs:219
at FormsPortable.RootPage..ctor () [0x00071] in /Users/path/FormsPortable/RootPage.cs:36
at FormsPortable.RootPage.getInstance () [0x00016] in /Users/path/FormsPortable/RootPage.cs:17
at FormsPortable.App.GetMainPage () [0x00001] in /Users/path/FormsPortable/App.cs:22
at FormsPortable.App..ctor () [0x00008] in /Users/path/FormsPortable/App.cs:16
at FormsPortable.Android.MainActivity.OnCreate (Android.OS.Bundle) [0x0001b] in /Users/path/FormsPortable/Android/MainActivity.cs:46
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:2707
at at (wrapper dynamic-method) object.b2c0b6b6-10c0-4cb7-836c-6835a64ef178 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
at at md582bcd42a84ef341846534077897dfd3b.MainActivity.n_onCreate(Native Method)
at at md582bcd42a84ef341846534077897dfd3b.MainActivity.onCreate(MainActivity.java:28)
at at android.app.Activity.performCreate(Activity.java:5451)
at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at at android.app.ActivityThread.access$900(ActivityThread.java:169)
at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
at at android.os.Handler.dispatchMessage(Handler.java:102)
at at android.os.Looper.loop(Looper.java:136)
at at android.app.ActivityThread.main(ActivityThread.java:5479)
at ... 5 more
And the flow is the following :
Android Project - MainActivity.cs file
using System;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Xamarin.Forms.Platform.Android;
using Android.Media;
namespace FormsPortable.Android{
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity {
protected override void OnCreate (Bundle bundle){
base.OnCreate (bundle);
Xamarin.Forms.Forms.Init (this, bundle);
MainApp.getInstance ().mainActivity = this;
LoadApplication (new App ());
}
}
}
Shared Project - App.cs file
using System;
using Xamarin.Forms;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
namespace FormsPortable{
public class App : Xamarin.Forms.Application{
public static RootPage RootPageInstance;
public App (){
MainPage = GetMainPage ();
}
public static Page GetMainPage (){
RootPageInstance = RootPage.getInstance ();
return RootPageInstance;
}
}
}
Shared Project - RootPage.cs file
using System;
using Xamarin.Forms;
using System.Linq;
using System.Diagnostics;
namespace FormsPortable{
public class RootPage : MasterDetailPage{
#region Constructor & Singleton
private static RootPage _instance;
public static RootPage getInstance(){
if (_instance == null){
Debug.WriteLine ("[RootPage] is Null. Setting up...");
_instance = new RootPage();
}
return _instance;
}
#endregion
public RootPage (){
DependencyService.Get<IApp> ().WriteToConsole ("[FORMS] [RootPage] [INIT] Starting...");
var menuPage = new MenuPage ();
DependencyService.Get<IApp> ().WriteToConsole ("[FORMS] [RootPage] [INIT] Menu Setup.");
Master = menuPage;
Detail = new NavigationPage (new PG_Home ()) {
BarBackgroundColor = Definitions.Color255,
BarTextColor = Color.Gray,
};
Page loadingPage = (Page)Activator.CreateInstance (typeof(ALCBasePage), this); THIS is the line that crashes.
Navigation.PushModalAsync(loadingPage, true);
DependencyService.Get<IApp> ().WriteToConsole ("[FORMS] [RootPage] [INIT] Done.");
}
}
}
Shared Project - ALCBasePage.cs file
using System;
using Xamarin.Forms;
namespace FormsPortable{
public class ALCBasePage : ContentPage{
private ActivityIndicator indicator;
public ALCBasePage (){
InitALCPage (null);
}
public ALCBasePage (object parameter = null){
InitALCPage (parameter);
}
private void InitALCPage(object parameter = null){
BackgroundColor = Definitions.Color255;
indicator = new ActivityIndicator{
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
Color = Color.Black,
IsVisible = false
};
indicator.WidthRequest = 35;
indicator.HeightRequest = 35;
IsBusyLoading (true);
string lbl = Definitions.Translation ("TR-00001");
if (parameter != null)
lbl = parameter as string;
Title = lbl;
}
public void IsBusyLoading(bool state){
Content = new StackLayout {
Children = {
indicator
}
};
indicator.IsRunning = state;
indicator.IsVisible = state;
}
}
}
- Why is the Constructor not found ?
- Why would it work for iOS and not for Android ?
Could please someone point me in the right direction. Have a deliverable today.