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

  • SEARCH
  • Home
  • 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 6833765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:01:12+00:00 2026-05-26T23:01:12+00:00

Error: Syntax error on token setDefaultCloseOperation, Identifier expected after this token Current Code: package

  • 0

Error: Syntax error on token “setDefaultCloseOperation”, Identifier
expected after this token

Current Code:

package me.geekplaya.Launcher;

import javax.swing.*;

public class Launcher {

//Create and setup the window.
JFrame frame = new JFrame("Simple GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel textLabel = new JLabel("I'm a label in the window", SwingConstants.CENTER);
textLabel.setPrefferedSize(new Dimension(300, 100));
frame.getContentPane().add(textLabel, BorderLayout.CENTER);

//Display the window.
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
}
  • 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-26T23:01:13+00:00Added an answer on May 26, 2026 at 11:01 pm

    A Class body can only contain: variable definitions, method definitions, or inner class definitions. A method body contains zero or more statements. Your statements must be put inside a method body. You have them defined in the class body. For example:

    public class Launcher {
    
        public void method1() {
           // this is an instance method you can put code here too.
           // Only instances of the class Launcher can call this method.
        }
    
        public static void main( String[] args ) {
            // this is a class method (i.e. static) it belongs to the class Launcher
            // your code must go in here.
        }
    }
    

    The compiler is trying to tell you that it doesn’t recognize those statements as one of those possible choices (variable def, method def, or inner class def). The reason it’s on the 2nd line and not the first is because the first line could be defining an instance variable. Local variables and instance variables can have the same syntax. Variables defined in the Class body are instance variables (unless marked static), and variables defined in a method body are local variables to that method.

    Just as an aside you don’t have to set the preferred width of the JLabel. JLabel will resize itself to fix the text it’s given. It’s usually better to let JLabel pick its size based on its content because that content could change, and if you hard code 300 pixels wide and 100 pixels tall that might not be enough depending on the label’s content:

    textLabel.setPrefferedSize(new Dimension(300, 100)); // this can be removed
    

    If you want the window to be bigger set the preferred size of the JFrame and remove the pack() call. JFrame.pack() tells the JFrame to set its size based on the size of the contents in the JFrame. If you want the JFrame to be in control of its dimensions just set them directly.

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

Sidebar

Related Questions

I get the errors Syntax error on token marketrate, VariableDeclaratorId expected after this token...
Syntax error on token ;, { expected after this token. I got this error
I'm getting this error: Syntax error on token ;, , expected On this very
This code run on Turbo C but not on gcc compiler Error:syntax error before
Syntax error on Token Void, @ expected run cannot be resolved to a type
Hi I wrote this code, and I dont understand why give me syntax error
I am getting syntax error with the following statement REPLACE INTO users (screenname, token,
Parse error: syntax error, unexpected $end in blah/blah/blah.php line 1 This is the error
This is the error: Parse error: syntax error, unexpected '}' in /home/idghosti/public_html/testground/mma/include/footer.php on line
I'm getting this error whenever I attempt to declare a class: Parse error: syntax

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.