Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7598425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:24:16+00:00 2026-05-30T22:24:16+00:00

I keep getting a compile error on the return menuFont line it says there

  • 0

I keep getting a compile error on the return menuFont line it says there is no variable menuFont. Could someone please tell how to fix this.

import java.awt.Font;
import java.awt.FontFormatException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


public class loadFiles {
Font getFont(){
            try {
                Font menuFont = Font.createFont( Font.TRUETYPE_FONT, new FileInputStream("font.ttf"));

            } catch (FileNotFoundException e) {
                System.out.println("Cant find file.");
                e.printStackTrace();
            } catch (FontFormatException e) {
                System.out.println("Wrong file type.");
                e.printStackTrace();
            } catch (IOException e) {
                System.out.println("Unknown error.");
                e.printStackTrace();
            }
            return menuFont;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:24:17+00:00Added an answer on May 30, 2026 at 10:24 pm

    The basic problem with your code is that the Font object is only in scope for the duration of the try block, so it’s no longer available in your return statement at the end of the method. Two options:

    Move the variable declaration outside the try block:

    Font menuFont = null;
    try {
        menuFont = Font.createFont(...);
    }
    catch (...) {
    
    }
    return menuFont;
    

    Or, do return Font.creatFont(...) inside the try, thus avoiding the need for the variable in the first place (and, obviously, return null at the end of the method).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says, keep getting this error when trying to compile. From Googling
I keep getting the error: Type was not found or was not a compile-time
With the following code, I keep getting error C2535 when I compile. It's complaining
I keep getting this error compile error /Users/dean/src/carolian/app/views/layouts/events.html.erb:10: syntax error, unexpected ',', expecting ')'
I'm trying to compile an MPI_Exchange function but keep getting the below errors. Error:
I can't seem to get this program to compile. I keep getting the error:
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting a PermGen error on my Tomcat 6 server. I know what
I keep getting an error like this: Sass::SyntaxError: Properties aren't allowed at the root
For some reason I keep getting error C3861: '__typeof': identifier not found when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.