Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: java.lang.ExceptionInInitializerError

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java.lang.ExceptionInInitializerError

    Hi iam a beginner in Java i have written this code below but its doing what i want it to.

     
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package db;
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
     
     
    public abstract class Example extends JFrame implements ActionListener{
     
       public  Example(){
        Container con=getContentPane();
        con.setLayout(new FlowLayout()); 
     
        JLabel Myname=new JLabel ("Name");
        JTextField TxtName=new JTextField(20);
        JLabel RegNumber=new JLabel ("Reg No.");
        JButton SaveButton= new JButton("Save");
        con.add(Myname);
        con.add(TxtName);
        con.add(RegNumber);
        con.add(SaveButton);
        SaveButton.addActionListener(This);
        }
         public void actionPerformed(ActionEvent e, Object SaveButton) {
         Object Source=e.getSource();        
          if (Source==SaveButton)
          System.out.println("Thank You");
        }
     
            public static void main(String[] args) {
     
            JFrame MyFrame=new JFrame ("Detela loves Java");
            MyFrame.setVisible(true);
     
        }
     
    }

    thank you
    Last edited by GregBrannon; July 13th, 2014 at 06:07 AM. Reason: Fixed highlight tags.

  2. #2
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    411
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: java.lang.ExceptionInInitializerError

    Please use code tags when posting code. What exactly is the problem you are having?
    Is the code showing errors or producing invalid output?

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,345
    My Mood
    Mellow
    Thanks
    254
    Thanked 784 Times in 769 Posts

    Default Re: java.lang.ExceptionInInitializerError

    Welcome to the forum! Thanks for taking the time to (almost) learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    We won't assume what you mean by "but its (not) doing what i want it to." Please give the details, post the complete messages of all errors you want help with, and ask specific questions. You should also comment your code so that you can outline what the code is supposed to be doing as well as communicate that to others reading your code.

    I'm curious, adding Swing components to the content pane hasn't been necessary since Java 1.4. What source are you using to learn this?

  4. #4
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.ExceptionInInitializerError

    Thanks for your response. i am using Netbean 8.0 and It gives an error message saying,

    java.lang.ExceptionInInitializerError
    Caused by: java.lang.RuntimeException: Uncompilable source code - db.Example is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
    at db.Example.<clinit>(Example.java:16)


    [JAVA CODE]

    package db;

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;



    public abstract class Example extends JFrame implements ActionListener{

    public Example(){
    Container con=getContentPane();
    con.setLayout(new FlowLayout());

    /* i want to put a name label,text filed,and button on a container and when the is clicked, a thank you message button shows */

    JLabel Myname=new JLabel ("Name");
    JTextField TxtName=new JTextField(20);
    JLabel RegNumber=new JLabel ("Reg No.");
    JButton SaveButton= new JButton("Save");
    con.add(Myname);
    con.add(TxtName);
    con.add(RegNumber);
    con.add(SaveButton);
    SaveButton.addActionListener(This);
    }
    public void actionPerformed(ActionEvent e, Object SaveButton) {
    Object Source=e.getSource();
    if (Source==SaveButton)
    System.out.println("Thank You");
    }

    [/QUOTE]

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,337
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: java.lang.ExceptionInInitializerError

    When you override a method, you must copy the method's signature EXACTLY as it is defined. Any changes to the signature prevents it from being an override.

    The compiler can not find the correct definition for the actionPerformed() method. Read the API doc to see how to correctly define it and change the code.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: July 2nd, 2013, 05:59 PM
  2. java.lang.NullPointerExpectation:null (in java.awt.Container) when adding a JPanel
    By Freshtilldeath0 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 31st, 2012, 07:19 AM
  3. [SOLVED] Java run time error: 'java.lang.NullPointerException"
    By ChandanSharma in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 20th, 2011, 12:53 PM
  4. AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    By nasi in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 25th, 2010, 11:37 PM
  5. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM

Tags for this Thread