Minimize Ja.NET Forums
 
  Ja.NET Forums  Ja.NET SE  Using  Getting runtime java.lang.ExceptionInInitializerError
Previous Previous
 
Next Next
New Post 9/9/2009 9:58 AM
  rvanamb
1 posts
No Ranking


Getting runtime java.lang.ExceptionInInitializerError 
Modified By rvanamb  on 9/10/2009 7:00:03 AM)

Hi,

First I want to say that I love the work you have done developing Ja.NET. This is a really useful tool to have in the tool box!

First issue is that I am getting a runtime exception when calling java code from a .NET 3.5 WPF application (code below).

A first chance exception of type 'java.lang.ExceptionInInitializerError' occurred in janet.awt.dll
java.lang.ExceptionInInitializerError: The type initializer for 'org.apache.harmony.awt.nativebridge.NativeBridge' threw an exception.

Second issue: Is there a way to add the Java gui component to a StackPanel? or (not prefered) a Windows Form?

Build steps:

1) create java app in Netbeans (JDK 1.6.0_16-b01)

2) C:\Ja.NET\bin\javac.exe -bam:javaapplication.dll .\JavaApplication\src\javaapplication\*.java

3) create C# project

4) add references to C:\Ja.NET\jre\bin\default\*.dll

5) add reference to javaapplication.dll

************************************ Java code ************************************

NewJPanel.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication;

/**
 *
 * @author rvanamb
 */
public class NewJPanel extends javax.swing.JPanel implements javax.swing.event.ChangeListener {

    /** Creates new form NewJPanel */
    public NewJPanel(){
        this.setName("Form");
        this.setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));

        this.jColorChooser1 = new javax.swing.JColorChooser();
        this.jColorChooser1.setName("jColorChooser1");
        //this.jColorChooser1.setLayout(this.getLayout());
        this.jColorChooser1.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT);
        this.jColorChooser1.setAlignmentY(java.awt.Component.TOP_ALIGNMENT);
        this.add(this.jColorChooser1);

        this.jPanel1 = new javax.swing.JPanel();
        this.jPanel1.setName("jPanel1");
        //this.jPanel1.setLayout(this.getLayout());
        this.jPanel1.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT);
        this.jPanel1.setAlignmentY(java.awt.Component.BOTTOM_ALIGNMENT);
        this.add(this.jPanel1);

        this.jColorChooser1.getSelectionModel().addChangeListener(this);

        this.validate();
    }

 
    public void stateChanged(javax.swing.event.ChangeEvent e) {
        this.jPanel1.setBackground(this.jColorChooser1.getColor());
    }

    // Variables declaration - do not modify
    private javax.swing.JColorChooser jColorChooser1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration

}

Main.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication;

/**
 *
 * @author rvanamb
 */
public class Main {

    public static javax.swing.JFrame show()
    {
        javax.swing.JFrame frame = new javax.swing.JFrame();
        frame.setSize(500, 550);
        NewJPanel newJPanel = new NewJPanel();
        frame.add(newJPanel);
        frame.validate();
        frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

        return frame;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        show();
    }

}


************************************ C# code ************************************

Window1.xaml

<Window x:Class="EmbededJava.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Embedded Java" Height="353" Width="343">
        <StackPanel Name="stackPanel1" Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="300" MinWidth="300" Height="312" Width="320">
        <StackPanel Name="stackPanel2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Orientation="Horizontal" >
            <Label>Java App 1</Label>
            <Button Height="23" Name="button_init_1" Width="75" Click="button_init_1_Click">Init</Button>
        </StackPanel>
        <StackPanel Name="stackPanel3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Orientation="Horizontal" >
            <Label>Java App 2</Label>
            <Button Height="23" Name="button_init_2" Width="75" Click="button_init_2_Click">Init</Button>
        </StackPanel>
        </StackPanel>
</Window>
 

Window1.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace EmbededJava
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void button_init_1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                javax.swing.JFrame frame = javaapplication.Main.show();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }

        private void button_init_2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                javaapplication.NewJPanel newJPanel = new javaapplication.NewJPanel();
                //this.stackPanel2.Children.Add(newJPanel);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
    }
}

 

 
New Post 9/15/2009 2:46 PM
  Dave
15 posts
No Ranking


Re: Getting runtime java.lang.ExceptionInInitializerError 

Hi rvanamb,

Sorry for taking so long to respond to this question... I have been very busy with my "real ... regular " job these days.  :-)

Unfortunately, at this point in time, I have not had a chance to update the swing, and awt components in Ja.NET SE to use WPF as the underlying UI engine.  The swing/awt code included in Ja.NET SE at this point, comes from the Apache Harmony project, and still uses native (i.e. JNI calls ) to the Windows APIs to attempt to do its thing.   I want to replace all of that (i.e. the JNI & native code) with WPF/managed code, but have not had a chance to do it yet.   As you probably have already seen, the swing and awt code allready compiles cleanly into .NET assemblies as part of the Ja.NET SE build,  ....but the native methods only get compiled into "exception throwing" at this point, rather than JNI calls.  Thats why you are seeing exceptions when you try to reference the swing classes.

Someday, ... hopefully soon, I'll have the time to make the code changes to the Ja.NET SE swing and awt modules so that what you are attempting to do.... will just work.    Actually, I'm currently starting to do that work for swt(i.e. eclipse) as I'm working on getting the WPF based version of eclipse up and running on .NET/CLR.

-Dave

 
Previous Previous
 
Next Next
  Ja.NET Forums  Ja.NET SE  Using  Getting runtime java.lang.ExceptionInInitializerError
Syndicate