using JavaBeans as ActiveX in C#.Net

ibjs

New member
Joined
Jan 26, 2005
Messages
2
Hello folks,

I am a newbie to c#.net. In my very first project I have to gain access to JavaBeans which are accessable as dll. Has anybody an idea how this works.
Compilation is ok but an exception always occurs at runtime. For I use a german version of Microsoft Visual C#.NET I have to translate the exceptions message into English, I hope you can figure out what it means.
Here is the exception:

A non caught exception of type System.NullReferenceException has occured.
Additional info: the object reference was not fixed to an object instance.

My JavaBeans name is LabelBean (exists in LabelBean.dll). I added LabelBean to my project references. Heres a code sniplet:

=====================
...
using LabelBean;
...
namespace MyFirst
{
public class Form1 : System.Windows.Forms.Form
{
private LabelBean.LabelBeanClass bean;
}
public Form1()
{
InitializeComponent();

// this line throws the exception at runtime
this.bean = new LabelBean.LabelBeanClass();
}
...
}
=====================


I appreciate any help. I really have got stuck with this JavaBean.

Thank you.

ibjs
 
I dont have a clue about what JavaBeans is. :(

But the designer should be handling the initialization of your code when you drag your Control onto the Form. For example, when you drag a Button onto your form, the Windows Designer should create the following code for you:
Code:
//
        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>

        private System.Windows.Forms.Button button1;

        private void InitializeComponent()
        {

// 
// button1
// 
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            this.button1.Location = new System.Drawing.Point(50, 70);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(144, 51);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.Click += new System.EventHandler(this.button1_Click);
        }
Note the key line:
Code:
this.button1 = new System.Windows.Forms.Button();
Without this, the button Object is Null, and would throw a NullException if one tried to use it. It sounds like your ActiveX control is not getting initialized for some reasion. When you drag a new copy of your control onto the Form (you might want to test this in a new, blank project), what code does the Windows Designer produce for you?


Hmmm... ok, something in your code looks funny too. Are you sure that you have your brackets right? This looks fishy to me:
Code:
public class Form1 : System.Windows.Forms.Form
{
private LabelBean.LabelBeanClass bean;
}
That close bracket after declaring your bean variable looks wrong, it would be ending the Class definition way prematurely, right?
 
Hi Mike_R,

thanks for your quick reply ;-)
Nearly the same your email arrived I could fix this problem!

For everyone who will be hard-pushed in future with ActiveX generated out of JavaBeans:
There is a tool in the java package for creating the dlls. DO NOT USE THE packager.exe from jdk1.4.x - it doesnt work properly although everything looks all right. Instead use the packager.exe of jdk 1.5 and everything works fine.

Thanks again Mike_rR, everything now works as you described ;-))

Good speed!

ibjs
 
Back
Top