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

Thread: class,interface, or enum expected?

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default class,interface, or enum expected?

    Sorry if I'm bothering anyone, I'm very new to java and i need some help with a code in my java file.

    class,interface, or enum expected

    On these lines:
    package stickemu.Tools;
    package stickemu.Types;
    package stickemu.Lobby;
    Before them i have
    package stickemu;
    But the error shows for only them lines

    Here's the actual java file(Main.java)
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
     
    package stickemu;
    package stickemu.Tools;
    package stickemu.Types;
    package stickemu.Lobby;
     
    import java.util.Properties;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.nio.charset.Charset;
    import java.net.InetSocketAddress;
    import stickemu.Tools.*;
    import stickemu.Types.*;
    import stickemu.Lobby.*;
     
    import org.apache.mina.core.session.IdleStatus;
    import org.apache.mina.filter.codec.ProtocolCod…
    import org.apache.mina.filter.codec.textline.Te…
    import org.apache.mina.transport.socket.nio.Nio…
    import org.apache.mina.filter.executor.Executor…
     
    /**
    *
    * @author Simon
    */
    public class Main{
    public static String IP = "5.175.221.236";
    private static final int PORT = 80;
    private static LobbyServer LS;
     
    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
     
    NioSocketAcceptor SocketAcceptor = new NioSocketAcceptor();
    SocketAcceptor.getSessionConfig().setIdl… IdleStatus.BOTH_IDLE, 10 );
    SocketAcceptor.getSessionConfig().setRea… 2048 );
    SocketAcceptor.setHandler(new StickNetworkHandler());
    ExecutorFilter executor = new ExecutorFilter();
    SocketAcceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" ), "\0", "\0")));
    SocketAcceptor.getFilterChain().addLast(… executor);
    LS = new LobbyServer();
     
    Properties ConfigProps = new Properties();
    try {
    ConfigProps.load(new FileInputStream("config.properties"));
    } catch (FileNotFoundException fnf)
    {
    System.out.println("Unable to start server: config.properties was not found.");
    return;
    } catch (IOException e)
    {
    System.out.println("Unable to start server: Error reading from config.properties.");
    return;
    }
     
    Main.IP = ConfigProps.getProperty("server_IP");
    DatabaseTools.user = ConfigProps.getProperty("db_user");
    DatabaseTools.pass = ConfigProps.getProperty("db_pass");
    DatabaseTools.server = ConfigProps.getProperty("db_server");
    DatabaseTools.database = ConfigProps.getProperty("db_database");
     
     
    try
    {
    SocketAcceptor.bind(new InetSocketAddress(PORT));
     
    System.out.printf("Server started on port %s \n", PORT);
    System.out.println();
    }
     
    catch (Exception e)
    {
    System.out.printf("Unable to bind to port %s, Exception thrown: %s \n", PORT, e);
    System.out.println();
    return;
    }
     
    DatabaseTools.dbConnect();
    }
     
    public static LobbyServer getLobbyServer()
    {
    return LS;
    }
     
    }

    Please help me fix, been searching up fixes but i can't find anything to help!

    Thanks !
    Last edited by Eimaj; September 28th, 2012 at 01:31 PM.


  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: class,interface, or enum expected?

    A class can only be in one package.
    The compiler is confused by the extra package statements and is looking to find a definition for: class,interface, or enum after the first package statement.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class,interface, or enum expected?

    Thank you,
    I also just tried removing the following, but now i get the following errors in the compiler.
    Main.java:15: error: package stickemu.Tools does not exist
    import stickemu.Tools.*;
    ^
    Main.java:16: error: package stickemu.Types does not exist
    import stickemu.Types.*;
    ^
    Main.java:17: error: package stickemu.Lobby does not exist
    import stickemu.Lobby.*;
    ^
    Main.java:19: error: package org.apache.mina.core.session does not exist
    import org.apache.mina.core.session.IdleStatus;
                                       ^
    Main.java:20: error: package org.apache.mina.filter.codec does not exist
    import org.apache.mina.filter.codec.ProtocolCodecFilter;
                                       ^
    Main.java:21: error: package org.apache.mina.filter.codec.textline does not ex
    t
    import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
                                                ^
    Main.java:22: error: package org.apache.mina.transport.socket.nio does not exi
     
    import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
                                               ^
    Main.java:23: error: package org.apache.mina.filter.executor does not exist
    import org.apache.mina.filter.executor.ExecutorFilter;
                                          ^
    Main.java:32: error: cannot find symbol
        private static LobbyServer LS;
                       ^
      symbol:   class LobbyServer
      location: class Main
    Main.java:86: error: cannot find symbol
        public static LobbyServer getLobbyServer()
                      ^
      symbol:   class LobbyServer
      location: class Main
    Main.java:39: error: cannot find symbol
            NioSocketAcceptor SocketAcceptor = new NioSocketAcceptor();
            ^
      symbol:   class NioSocketAcceptor
      location: class Main
    Main.java:39: error: cannot find symbol
            NioSocketAcceptor SocketAcceptor = new NioSocketAcceptor();
                                                   ^
      symbol:   class NioSocketAcceptor
      location: class Main
    Main.java:40: error: cannot find symbol
            SocketAcceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 1
    );
                                                           ^
      symbol:   variable IdleStatus
      location: class Main
    Main.java:42: error: cannot find symbol
            SocketAcceptor.setHandler(new StickNetworkHandler());
                                          ^
      symbol:   class StickNetworkHandler
      location: class Main
    Main.java:43: error: cannot find symbol
            ExecutorFilter executor = new ExecutorFilter();
            ^
      symbol:   class ExecutorFilter
      location: class Main
    Main.java:43: error: cannot find symbol
            ExecutorFilter executor = new ExecutorFilter();
                                          ^
      symbol:   class ExecutorFilter
      location: class Main
    Main.java:44: error: cannot find symbol
            SocketAcceptor.getFilterChain().addLast( "codec", new ProtocolCodecFil
    r( new TextLineCodecFactory( Charset.forName( "UTF-8" ), "\0", "\0")));
                                                                  ^
      symbol:   class ProtocolCodecFilter
      location: class Main
    Main.java:44: error: cannot find symbol
            SocketAcceptor.getFilterChain().addLast( "codec", new ProtocolCodecFil
    r( new TextLineCodecFactory( Charset.forName( "UTF-8" ), "\0", "\0")));
     
           ^
      symbol:   class TextLineCodecFactory
      location: class Main
    Main.java:46: error: cannot find symbol
            LS = new LobbyServer();
                     ^
      symbol:   class LobbyServer
      location: class Main
    Main.java:62: error: cannot find symbol
            DatabaseTools.user = ConfigProps.getProperty("db_user");
            ^
      symbol:   variable DatabaseTools
      location: class Main
    Main.java:63: error: cannot find symbol
            DatabaseTools.pass = ConfigProps.getProperty("db_pass");
            ^
      symbol:   variable DatabaseTools
      location: class Main
    Main.java:64: error: cannot find symbol
            DatabaseTools.server = ConfigProps.getProperty("db_server");
            ^
      symbol:   variable DatabaseTools
      location: class Main
    Main.java:65: error: cannot find symbol
            DatabaseTools.database = ConfigProps.getProperty("db_database");
            ^
      symbol:   variable DatabaseTools
      location: class Main
    Main.java:83: error: cannot find symbol
            DatabaseTools.dbConnect();
            ^
      symbol:   variable DatabaseTools
      location: class Main
    24 errors
    Please help!

  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: class,interface, or enum expected?

    package stickemu.Tools does not exist
    You need to find the definitions for those packages and make sure they are on the classpath for the compiler.
    Are those packages in a jar file or are they files in a folder?

    How are you compiling the program? What is the command line you are using?
    The javac command has a -cp option that is used to specify the classpath.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class,interface, or enum expected?

    My compiler
    "C:\Program Files\Java\jdk1.7.0\bin\javac.exe" -cp . Main.java
    pause
    stickemu is the folder they are in, and then Tools,Game,Lobby are folders again.

  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: class,interface, or enum expected?

    With this package: stickemu.Tools the Tools folder must be in the stickemu folder
    The stickemu folder must be in the current folder.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class,interface, or enum expected?

    Sorry i don't understand,
    could you make it clear what the problem is?

  8. #8
    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: class,interface, or enum expected?

    what the problem is
    The compiler can not find the packages the import statements refer to.

    The classpath needs to point to the folder that contains the first folder on the package path: stickemu
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class,interface, or enum expected?

    So how can i fix this?

  10. #10
    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: class,interface, or enum expected?

    Set the -cp option to point to the folder with stickemu folder. Make sure the other classes are in the folders that reflects their packages.

    Try using google to get more info on how to use packages and classpaths in java.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class,interface, or enum expected?

    Sorry i really am a newbie in Java.
    But like this?
    "C:\Program Files\Java\jdk1.7.0\bin\javac.exe" -cp . stickemu/Main.java
    pause
    If not please correct me for me!

  12. #12
    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: class,interface, or enum expected?

    What happens when you execute that command?

    The command line to use depends on where the files and folders are located.
    Please copy the full contents of the console window where you enter the javac command.
    Also enter the dir command to list the contents of the folder.

    On windows: To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    Last edited by Norm; September 28th, 2012 at 02:48 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class,interface, or enum expected?

    Here it is, Hope you can help!
    "C:\Program Files\Java\jdk1.7.0\bin\javac.exe" -cp . stickemu/Main.java
    pause

  14. #14
    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: class,interface, or enum expected?

    Please re-read post #12.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    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: class,interface, or enum expected?

    If you don't understand my answer, don't ignore it, ask a question.

  16. #16
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class,interface, or enum expected?


    C:\Users\Jay\Desktop\StickEMU - Release\src>"C:\Program Files\Java\jdk1.7.0\bin\
    javac.exe" -cp . stickemu/Main.java
    stickemu\Main.java:19: error: package org.apache.mina.core.session does not exis
    t
    import org.apache.mina.core.session.IdleStatus;
    ^
    stickemu\Main.java:20: error: package org.apache.mina.filter.codec does not exis
    t
    import org.apache.mina.filter.codec.ProtocolCodecFilter;
    ^
    stickemu\Main.java:21: error: package org.apache.mina.filter.codec.textline does
    not exist
    import org.apache.mina.filter.codec.textline.TextLineCode cFactory;
    ^
    stickemu\Main.java:22: error: package org.apache.mina.transport.socket.nio does
    not exist
    import org.apache.mina.transport.socket.nio.NioSocketAcce ptor;
    ^
    stickemu\Main.java:23: error: package org.apache.mina.filter.executor does not e
    xist
    import org.apache.mina.filter.executor.ExecutorFilter;
    ^
    .\stickemu\Types\StickClient.java:21: error: package org.apache.mina.core.sessio
    n does not exist
    import org.apache.mina.core.session.IoSession;
    ^
    .\stickemu\Types\StickClient.java:32: error: cannot find symbol
    private IoSession session;
    ^
    symbol: class IoSession
    location: class StickClient
    .\stickemu\Types\StickClient.java:52: error: cannot find symbol
    public StickClient(IoSession _session, String new_UID)
    ^
    symbol: class IoSession
    location: class StickClient
    .\stickemu\Types\StickClient.java:223: error: cannot find symbol
    public IoSession getIoSession()
    ^
    symbol: class IoSession
    location: class StickClient
    stickemu\Main.java:39: error: cannot find symbol
    NioSocketAcceptor SocketAcceptor = new NioSocketAcceptor();
    ^
    symbol: class NioSocketAcceptor
    location: class Main
    stickemu\Main.java:39: error: cannot find symbol
    NioSocketAcceptor SocketAcceptor = new NioSocketAcceptor();
    ^
    symbol: class NioSocketAcceptor
    location: class Main
    stickemu\Main.java:40: error: cannot find symbol
    SocketAcceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10
    );
    ^
    symbol: variable IdleStatus
    location: class Main
    .\stickemu\Tools\StickNetworkHandler.java:34: error: package org.apache.mina.cor
    e.session does not exist
    import org.apache.mina.core.session.IdleStatus;
    ^
    .\stickemu\Tools\StickNetworkHandler.java:35: error: package org.apache.mina.cor
    e.service does not exist
    import org.apache.mina.core.service.IoHandlerAdapter;
    ^
    .\stickemu\Tools\StickNetworkHandler.java:36: error: package org.apache.mina.cor
    e.session does not exist
    import org.apache.mina.core.session.IoSession;
    ^
    .\stickemu\Tools\StickNetworkHandler.java:38: error: cannot find symbol
    public class StickNetworkHandler extends IoHandlerAdapter
    ^
    symbol: class IoHandlerAdapter
    .\stickemu\Tools\StickNetworkHandler.java:45: error: cannot find symbol
    public void sessionOpened(IoSession session) throws Exception
    ^
    symbol: class IoSession
    location: class StickNetworkHandler
    .\stickemu\Tools\StickNetworkHandler.java:78: error: cannot find symbol
    public void exceptionCaught( IoSession session, Throwable cause ) throws Exc
    eption
    ^
    symbol: class IoSession
    location: class StickNetworkHandler
    .\stickemu\Tools\StickNetworkHandler.java:84: error: cannot find symbol
    public void messageReceived( IoSession session, Object message ) throws Exce
    ption
    ^
    symbol: class IoSession
    location: class StickNetworkHandler
    .\stickemu\Tools\StickNetworkHandler.java:123: error: cannot find symbol
    public void sessionIdle( IoSession session, IdleStatus status ) throws Excep
    tion
    ^
    symbol: class IoSession
    location: class StickNetworkHandler
    .\stickemu\Tools\StickNetworkHandler.java:123: error: cannot find symbol
    public void sessionIdle( IoSession session, IdleStatus status ) throws Excep
    tion
    ^
    symbol: class IdleStatus
    location: class StickNetworkHandler
    .\stickemu\Tools\StickNetworkHandler.java:130: error: cannot find symbol
    public void sessionClosed(IoSession session) throws Exception {
    ^
    symbol: class IoSession
    location: class StickNetworkHandler
    .\stickemu\Tools\DatabaseTools.java:21: error: package org.gjt.mm.mysql does not
    exist
    import org.gjt.mm.mysql.Driver;
    ^
    stickemu\Main.java:43: error: cannot find symbol
    ExecutorFilter executor = new ExecutorFilter();
    ^
    symbol: class ExecutorFilter
    location: class Main
    stickemu\Main.java:43: error: cannot find symbol
    ExecutorFilter executor = new ExecutorFilter();
    ^
    symbol: class ExecutorFilter
    location: class Main
    stickemu\Main.java:44: error: cannot find symbol
    SocketAcceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilte
    r( new TextLineCodecFactory( Charset.forName( "UTF-8" ), "\0", "\0")));
    ^
    symbol: class ProtocolCodecFilter
    location: class Main
    stickemu\Main.java:44: error: cannot find symbol
    SocketAcceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilte
    r( new TextLineCodecFactory( Charset.forName( "UTF-8" ), "\0", "\0")));

    ^
    symbol: class TextLineCodecFactory
    location: class Main
    .\stickemu\Tools\StickNetworkHandler.java:44: error: method does not override or
    implement a method from a supertype
    @Override
    ^
    .\stickemu\Tools\StickNetworkHandler.java:77: error: method does not override or
    implement a method from a supertype
    @Override
    ^
    .\stickemu\Tools\StickNetworkHandler.java:83: error: method does not override or
    implement a method from a supertype
    @Override
    ^
    .\stickemu\Tools\StickNetworkHandler.java:122: error: method does not override o
    r implement a method from a supertype
    @Override
    ^
    .\stickemu\Tools\StickNetworkHandler.java:129: error: method does not override o
    r implement a method from a supertype
    @Override
    ^
    32 errors

    C:\Users\Jay\Desktop\StickEMU - Release\src>pause
    Press any key to continue . . .
    Is this the correct thing your looking for?

  17. #17
    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: class,interface, or enum expected?

    Did you read the error message? Now the compiler can not find another package: org.apache.mina...

    Where is dir command used to show what was in the folder?

    Read the tutorial given in post#15
    Last edited by Norm; September 28th, 2012 at 02:58 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #18
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class,interface, or enum expected?

    I really REALLY am confused with what your trying to say to me, As i stated i am VERY VERY new to java. i really don't understand the problem and i don't understand what your trying to show or tell me to do. Please explain a bit more noob friendly.

    Thanks

  19. #19
    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: class,interface, or enum expected?

    Have you read the tutorial about packages: Creating and Using Packages (The Java™ Tutorials > Learning the Java Language > Packages)

    If you have questions after reading the tutorial, copy the parts you don't understand, paste them here and ask your questions about it.
    Last edited by Norm; September 28th, 2012 at 03:14 PM. Reason: spelling
    If you don't understand my answer, don't ignore it, ask a question.

  20. #20
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class,interface, or enum expected?

    I've read it but i don't know how this helps me, neither do i know how it can help me. :/

  21. #21
    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: class,interface, or enum expected?

    Sorry, I don't think you could have read through the 7 or so pages so quickly.
    If you don't understand my answer, don't ignore it, ask a question.

  22. #22
    Junior Member
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: class,interface, or enum expected?

    Sorry i didn't seen "Next Page" , I'll continue reading.

Similar Threads

  1. class String replaceAll does not behave as i expected
    By Samaras in forum What's Wrong With My Code?
    Replies: 8
    Last Post: August 19th, 2012, 04:41 PM
  2. enum class creation to hold time on android
    By jobsfind39 in forum Object Oriented Programming
    Replies: 3
    Last Post: June 21st, 2012, 10:04 AM
  3. [SOLVED] Error: Class,interface or enum expected
    By FJIW in forum What's Wrong With My Code?
    Replies: 10
    Last Post: September 18th, 2011, 03:08 PM
  4. .'class' expected - what to do?!?! URGENT
    By Rads23 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 17th, 2011, 06:05 PM
  5. Trouble using enum in constructor when creating a class
    By willmer in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 13th, 2011, 10:48 AM