[mono-android] Antwort: Re: Custom Application Object

BernhardGessler at cs-ag.de BernhardGessler at cs-ag.de
Mon Mar 21 10:50:36 EDT 2011


Thanks, this resolved the problem.




Morten Nilsen <mortenn at hapro.no> 
Gesendet von: monodroid-bounces at lists.ximian.com
21.03.2011 15:21
Bitte antworten an
monodroid at lists.ximian.com


An
"'monodroid at lists.ximian.com'" <monodroid at lists.ximian.com>
Kopie

Thema
Re: [mono-android] Custom Application Object






Hi,
You will need to add this constructor to your class:
 
Public MyApp(IntPtr handle)
  : base(handle)
{
}
 
This is due to the code path from C# to Java and the two runtime 
environments.
 
  -- Regards, Morten
 
From: monodroid-bounces at lists.ximian.com 
[mailto:monodroid-bounces at lists.ximian.com] On Behalf Of 
BernhardGessler at cs-ag.de
Sent: Monday, March 21, 2011 3:14 PM
To: monodroid at lists.ximian.com
Cc: HagenBackhaus at cs-ag.de
Subject: [mono-android] Custom Application Object
 

Hi, 

i am, trying to have my own application object: 

using Android.App; 

namespace CSMobile.UI 
{ 
    [Application()] 
    class MyApp : Application 
    { 
        private string _test; 

        public string Test 
        { 
            get { return _test; } 
            set { _test = value; } 
        } 

        public override void OnCreate() 
        { 
            base.OnCreate(); 

            Program_Logic logic = new Program_Logic(); 
            logic.LoadConfig(this); 
        }         
    } 
} 


But when i start the Application the following error throws: 

03-21 15:03:43.280  5877  5877 I MonoDroid: UNHANDLED EXCEPTION: 
System.NotSupportedException: Unable to activate instance of type 
CSMobile.UI.MyApp from native handle 459ebe48 ---> 
System.MissingMethodException: No constructor found for 
CSMobile.UI.MyApp::.ctor(System.IntPtr) 
03-21 15:03:43.280  5877  5877 I MonoDroid:   at 
Android.Runtime.TypeManager.CreateProxy (System.Type type, IntPtr handle) 
[0x00000] in <filename unknown>:0 
03-21 15:03:43.280  5877  5877 I MonoDroid:   at 
Android.Runtime.TypeManager.CreateInstance (IntPtr handle, System.Type 
targetType) [0x00000] in <filename unknown>:0 
03-21 15:03:43.280  5877  5877 I MonoDroid:   --- End of inner exception 
stack trace --- 
03-21 15:03:43.280  5877  5877 I MonoDroid: at 
Android.Runtime.TypeManager.CreateInstance (intptr,System.Type) <0x0057c> 
03-21 15:03:43.280  5877  5877 I MonoDroid: at Java.Lang.Object.GetObject 
(intptr,System.Type,bool) <0x00223> 
03-21 15:03:43.280  5877  5877 I MonoDroid: at 
Java.Lang.Object._GetObject<Android.App.Application> (intptr,bool) 
<0x0004f> 
03-21 15:03:43.280  5877  5877 I MonoDroid: at 
Java.Lang.Object.GetObject<Android.App.Application> (intptr,bool) 
<0x0002b> 
03-21 15:03:43.280  5877  5877 I MonoDroid: at 
Android.App.Application.n_OnCreate (intptr,intptr) <0x00023> 
03-21 15:03:43.280  5877  5877 I MonoDroid: at (wrapper dynamic-method) 
object.e64d49ee-e048-4001-b616-2396f819a424 (intptr,intptr) <0x0002b> 

If I remove the OnCreate Method my app starts without crashing. But it 
crashes with the same exception as soon as i call 

this.ApplicationContext 

in one of my activities. 

Thaks for your help in advance 

Bernhard Geßler_______________________________________________
Monodroid mailing list
Monodroid at lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/mailman/private/monodroid/attachments/20110321/1be68042/attachment.html 


More information about the Monodroid mailing list