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

Thread: Just Teaching Myself Java--Trivial Problem

  1. #1
    Junior Member
    Join Date
    May 2012
    Location
    Connceticut
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Just Teaching Myself Java--Trivial Problem

    Hi All:

    I'm a VB user. I'm planning to write a research simulation in Java over this summer because it is a better web development language. Iv'e got my GUI started and I want to call a class called Driver from Main:

    Here is the entire class Driver

    public class Driver {
    System.out.println ("ABC");
    }

    I'm getting an error-- "misplaced constructs"

    What is wrong with this trivial code.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Just Teaching Myself Java--Trivial Problem

    I moved this thread, please don't post questions in the Member Introductions forum. Please read this: http://www.javaprogrammingforums.com...e-posting.html

    The code doesn't make sense, because you can't have a statement like that outside of a method or a constructor. When would that code ever be called?
    Last edited by KevinWorkman; May 14th, 2012 at 07:39 AM.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Just Teaching Myself Java--Trivial Problem

    That System.out.println("ABC"); call is sitting out in the middle of nowhere. You need to give it either a method or a constructor to be inside. To do that, just create a constructor for Driver, and then put the call inside the constructor.

    The only thing you can do outside of methods and constructors (as far as I know) is create variables.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  4. #4
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: Just Teaching Myself Java--Trivial Problem

    Seeing that you are crossing over from VB and considering you already have a GUI set up, I'm surprised that you are having a problem with something this fundamental. Did you perhaps use a WYSIWYG gui generator? Anyway, I suggest you start here: The Java™ Tutorials
    Specifically in the Trails Covering the Basics section.

  5. #5
    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: Just Teaching Myself Java--Trivial Problem

    Looks like this post: Trivial Problem - Dev Shed
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    May 2012
    Location
    Missouri
    Posts
    12
    My Mood
    Relaxed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Just Teaching Myself Java--Trivial Problem

    You cant start a statement without a constructor.

  7. #7
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Just Teaching Myself Java--Trivial Problem

    You don't have a constructor nor any methods. You need to put it inside either a constructor or a method.

    Preferably a constructor if that's the entire class.

    Not sure what you mean by "statement"

    You can have a class with nothing in it except a class declaration (which is what you have right now, except you have something else in it.)

    This is a constructor:

    public Driver()
    {


    }

    As for a "statement"

    This is a valid statement;

    int i = 5;
    Last edited by javapenguin; May 13th, 2012 at 08:42 PM.

Similar Threads

  1. Teaching a Non-Programmer How to Program?
    By KevinWorkman in forum The Cafe
    Replies: 47
    Last Post: April 26th, 2012, 01:42 AM
  2. Having a problem with java IO
    By DanTheSand in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: December 7th, 2011, 02:16 AM
  3. Help TEACHING Java
    By ducky123 in forum The Cafe
    Replies: 5
    Last Post: August 3rd, 2011, 01:25 AM
  4. java problem
    By Mj Shine in forum Java Theory & Questions
    Replies: 1
    Last Post: August 14th, 2009, 12:24 AM
  5. [SOLVED] JAVA JList Problem in visual images
    By antitru5t in forum AWT / Java Swing
    Replies: 4
    Last Post: April 15th, 2009, 03:09 PM