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

Thread: InvocationTargetException when using Graphics2D#drawString

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default InvocationTargetException when using Graphics2D#drawString

    I'm using openJDK 11.0.2 on ubuntu (docker image).

    Code:

     
    package test;
     
    import java.awt.*;
    import java.awt.image.BufferedImage;
     
    public class Main {
        public static void main(String[] args) {
            BufferedImage mapImage = new BufferedImage(128, 128, BufferedImage.TYPE_INT_RGB);
            Graphics2D canvas = mapImage.createGraphics();
            canvas.drawString("test", 1, 1);
        }
    }

    Error:
    Exception in thread "main" java.lang.InternalError: java.lang.reflect.InvocationTargetException
    at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFacto ry.java:86)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.desktop/sun.font.FontManagerFactory.getInstance(FontManage rFactory.java:74)
    at java.desktop/java.awt.Font.getFont2D(Font.java:497)
    at java.desktop/java.awt.Font$FontAccessImpl.getFont2D(Font.java:2 37)
    at java.desktop/sun.font.FontUtilities.getFont2D(FontUtilities.jav a:139)
    at java.desktop/sun.java2d.SunGraphics2D.checkFontInfo(SunGraphics 2D.java:670)
    at java.desktop/sun.java2d.SunGraphics2D.getFontInfo(SunGraphics2D .java:831)
    at java.desktop/sun.java2d.pipe.GlyphListPipe.drawString(GlyphList Pipe.java:46)
    at java.desktop/sun.java2d.pipe.ValidatePipe.drawString(ValidatePi pe.java:165)
    at java.desktop/sun.java2d.SunGraphics2D.drawString(SunGraphics2D. java:2929)
    at test.Main.main(Main.java:10)
    Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl .newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl .newInstance(NativeConstructorAccessorImpl.java:62 )
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessor Impl.newInstance(DelegatingConstructorAccessorImpl .java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Construc tor.java:490)
    at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFacto ry.java:84)
    ... 11 more
    Caused by: java.lang.NullPointerException
    at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfigura tion.java:1262)
    at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontC onfiguration.java:225)
    at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.j ava:107)
    at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11 FontManager.java:719)
    at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java: 367)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java :312)
    at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35 )
    at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java: 56)
    ... 16 more

    Any help is greatly appreciated.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: InvocationTargetException when using Graphics2D#drawString

    Those 3 lines of code compile and execute ok for me in java 10 on Windows 10.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: InvocationTargetException when using Graphics2D#drawString

    This leads me to believe it's a problem with the latest openjdk 11 jvm. If anyone has any further insight, please let me know.

Similar Threads

  1. drawString elements
    By KAJLogic in forum Java Theory & Questions
    Replies: 3
    Last Post: September 2nd, 2013, 06:27 PM
  2. Something weird with Graphics and drawString...
    By JamEngulfer221 in forum AWT / Java Swing
    Replies: 15
    Last Post: December 11th, 2011, 07:28 AM
  3. drawString
    By frozen java in forum Java Theory & Questions
    Replies: 17
    Last Post: June 14th, 2011, 04:36 PM
  4. drawString and JTextField
    By that_guy in forum AWT / Java Swing
    Replies: 9
    Last Post: January 29th, 2011, 02:43 AM
  5. Click to start and drawString fonts
    By Campos in forum Java Applets
    Replies: 3
    Last Post: July 24th, 2009, 02:24 PM