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 10 of 10

Thread: small disaster with upgrade to 1.7.0_17-b02

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Location
    Boston
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default small disaster with upgrade to 1.7.0_17-b02

    I have a java gui that was written for me a few years ago to provide a user interface for a command line application. After updating my jre to 1.7.0_17-b02, the application will no longer start. I opened the src in eclipse and ran it in the debugger and I get a list of exceptions. I get the same exceptions at runtime if I run it from the command line with java -jar.

    log4j:WARN No appenders could be found for logger (com.intensivek.winmolconn.WinMolconn).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at com.intensivek.myapp.dialogs.OptionsDialog.initCom ponents(OptionsDialog.java:62)
    at com.intensivek.myapp.dialogs.OptionsDialog.<init>( OptionsDialog.java:41)
    at com.intensivek.myapp.appmain.<init>(appMain.java:2 63)
    at com.intensivek.myapp.appmain$1.run(appMain.java:22 2)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    Looking at the src that is referenced here, this stuff is pretty bland,

    (OptionsDialog.java:62) is:
    border.setTitleFont(border.getTitleFont().deriveFo nt(Font.BOLD));

    (OptionsDialog.java:41) is:
    initComponents();

    It seems as if the issue is with the function, private void initComponents() {}, so I have included that function below.

    private void initComponents() {
    	setTitle(myApp.TITLE + " - Options");
    	getContentPane().setLayout(new MigLayout("fill"));
     
    	oPanel = new JPanel(new MigLayout("fillx"));
    	TitledBorder border = new TitledBorder("Option");
    	border.setTitleFont(border.getTitleFont().deriveFont(Font.BOLD));
    	oPanel.setBorder(border);
     
    	oAutosaveCheckbox = new JCheckBox("Autosave GUI Configuration On Exit");
    	oAutosaveCheckbox.setSelected(OptionsManager.getInstance().isAutosave());
    	oPanel.add(oAutosaveCheckbox, "spanx, wrap");
     
    	oFilenameLabel = new JLabel("Exe PATH:");
    	oFilenameTextfield = new JTextField(OptionsManager.getInstance().getExecutablePath());
    	oFilenameButton = new JButton("Open");
    	oFilenameButton.addActionListener(this);
    	oPanel.add(oFilenameLabel);
    	oPanel.add(oFilenameTextfield, "growx, pushx");
    	oPanel.add(oFilenameButton);
     
    	add(oPanel, "spanx, growx, wrap");
     
    	okButton = new JButton("Ok");
    	okButton.addActionListener(this);
    	add(okButton);
     
    	cancelButton = new JButton("Cancel");
    	cancelButton.addActionListener(this);
    	add(cancelButton,"gap push");
    }

    I hope at this point that the rest of the exceptions are a cascade from something going wrong early in the application setup. I need to get this figured out. Are there any know issues with the most recent upgrade that may affect the execution of the code above?

    These are the includes from the src file with the above function,
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
     
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JDialog;
    import javax.swing.JFileChooser;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.border.TitledBorder;
     
    import net.miginfocom.swing.MigLayout;
     
    import com.intensivek.myapp.appMain;
    import com.intensivek.myapp.utils.OptionsManager;

    I am a c++/c/fortran programmer, so I am out of my depth here. I can post more of the code if that would be useful.

    I looked at the sub forums to see if there was an appropriate one for this question, but nothing stood out to me. Please move this post if it was misplaced.

    LMHmedchem


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: small disaster with upgrade to 1.7.0_17-b02

    Start by finding which variable on line 62 has the null value. Then backtrack to see why it has the null value.
    Add a println() statement to print out the values of all the variables so you can see which one is null.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Location
    Boston
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: small disaster with upgrade to 1.7.0_17-b02

    Quote Originally Posted by Norm View Post
    Start by finding which variable on line 62 has the null value. Then backtrack to see why it has the null value.
    Add a println() statement to print out the values of all the variables so you can see which one is null.
    Thanks, I will try that. I assume I have to test this in debug mode and put a breakpoint somewhere, or will it still print the variables even with the exception?

    LMHmedchem

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: small disaster with upgrade to 1.7.0_17-b02

    Using println() statements are not related to debug mode.
    The println needs to be placed before the statement with the exception.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Location
    Boston
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: small disaster with upgrade to 1.7.0_17-b02

    This is the block of code with the issue, line in question (#62),

    60	oPanel = new JPanel(new MigLayout("fillx"));
    61	TitledBorder border = new TitledBorder("Option");
    62	border.setTitleFont(border.getTitleFont().deriveFont(Font.BOLD));
    63	oPanel.setBorder(border);

    The only thing on line 62 that looks like a variable is Font. Both setTitleFont() and getTitleFont() are in javax.swing.border, and deriveFont() is in java.awt. I'm not sure what I can print here.

    I added,
    System.out.println( Font.BOLD );

    to the line before 62 and ran the app as java -jar from the command line, but I just get the same error output and there is nothing extra printed. Would that imply that "Font" is null?

    Thanks for your patience.

    Sorry, I forgot to export the edited code to my jar file before running it. When I do, I get a value of 1 printed for System.out.println( Font.BOLD ). I'm not sure what else I can print there.

    LMHmedchem

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: small disaster with upgrade to 1.7.0_17-b02

    border.setTitleFont(border.getTitleFont().deriveFo nt(Font.BOLD));
    The following two are variables or are used where a variable would be used.
    border
    border.getTitleFont()
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Location
    Boston
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: small disaster with upgrade to 1.7.0_17-b02

    I added the following to the line before the exception,
    	System.out.println( " " );
    	System.out.println( "test print" );
    	System.out.println( Font.BOLD );
    	System.out.println( border );
    	System.out.println( border.getTitleFont() );
    	System.out.println( " " );

    The results to the terminal are,
    test print
    1
    javax.swing.border.TitledBorder@129373c
    null

    This means that border.getTitleFont() is returning null. I guess my question at this point is why does this suddenly not work when it was fine for several years.

    There are some bug reports for this,
    Bug ID: 7117283 NullpointerException when using TitleBorder.getTitleFont
    and it appears to be an issue with java 7. These reports are not new, so I assume this has been fixed or there is a workaround.

    Does anyone have anymore information on this, or can someone suggest a workaround?

    LMHmedchem

  8. #8
    Junior Member
    Join Date
    Apr 2013
    Location
    Boston
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: small disaster with upgrade to 1.7.0_17-b02

    I posted a reply to this, but it did not post, presumably because it had a link to a bug report. I would suggest that it would be alright to allow links to bugs.sun.com without moderator approval, since such a link would be unlikely to contain spam.

    At any rate, based on the print output, it appears as if border.getTitleFont() is returning null. There are several bug reports on this and it seems to have appeared with java 7. None of the reports were new, so I would guess that this has been resolved. Does anyone have any additional information or a workaround to suggest?

    LMHmedchem

  9. #9
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: small disaster with upgrade to 1.7.0_17-b02

    This is a look and feel problem, as the default font for TitledBorder uses the Font specified by UIManager.getFont("TitledBorder.font"), which may return null values. My advice would be to work around this by calling setTitledFont directly with a newly created font not based upon the getTitledFont method.

  10. #10
    Junior Member
    Join Date
    Apr 2013
    Location
    Boston
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: small disaster with upgrade to 1.7.0_17-b02

    One of the questions I have is why this worked up until recently, meaning that this code has existed for years and has never thrown this exception before. If there was an error in javax.swing.border such that getTitleFont() started improperly returning null, then that should have been corrected, right? Is this likely still a bug, or has the syntax for this function changed, etc? In short, why is it returning null now when it never has before?

    It's hard to say since I didn't write this, but one of the issues we were trying to resolve was to make sure that the gui had a reasonable appearance at different dpi settings, up to 144dpi (%150). I am wondering if hard coding TitledBorder.font would have a negative impact on that aspect. If I was going to use setTitledFont directly, what would I set the font to and what would that look like? I suppose I would have to know what font was used by the default look and feel. It seems as if we had some look and feel options available at one point (in a menu), but I'm not sure those are still there.

    Just to get it going, I have added the following to the six places in the code where setTitleFont() was called.

    Font myFont = new Font("ariel", Font.BOLD, 17);
    border.setTitleFont(myFont);

    This gets the app working again. The original look and feel must be located here in the original src code. Where can I look to find out what font was originally being set?

    LMHmedchem

Similar Threads

  1. Java Upgrade
    By PhiloEpisteme in forum Java SE APIs
    Replies: 0
    Last Post: September 10th, 2012, 02:13 PM
  2. Small problem, help please?
    By Jonathansafc in forum What's Wrong With My Code?
    Replies: 33
    Last Post: September 3rd, 2011, 06:46 PM
  3. Small help needed
    By javabeg in forum Java Theory & Questions
    Replies: 4
    Last Post: March 15th, 2011, 09:50 AM
  4. small problem ... I need help
    By Ashar in forum Loops & Control Statements
    Replies: 4
    Last Post: December 4th, 2009, 11:26 AM