DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    May 2006

    Arrow <identifier> expected error...cant fix ;(

    im creating a random player match generator and im experimenting with java for its implementation I am getting this "<identifier> expected" error" and I really cannot figure out how to make it go away!

    here is the code. The implemenation of main() is not completed yet so just ignore it for now.

    import java.util.*;
    import java.lang.*;
    import java.awt.*;
    import java.io.*;
    public class wnrandom
        public static void main (String[] args)
            Player playr = new Player();
        public class Player
            private String name;
            public void SetName(String pName)
                name = pName;
            public String GetName()
                return name;
    public class Match
            private ArrayList<Player> match = new ArrayList<Player>();
            public void SetMatch(Player p1, Player p2)
            public void PrintMatch()
                System.out.println( (match.get(0)).GetName() + " vs " +
                                    (match.get(1)).GetName() );
    the error is:
    linux1[10]% javac wnrandom.java
    wnrandom.java:39: <identifier> expected
    private ArrayList<Player> match = new ArrayList<Player>();
    1 error
    The ^ is supposed to be where the < is in <Player>

    where is it bolded is where the problem lies. i am sure this is a completely noob problem :/.

    thanks in advance.

  2. #2
    Join Date
    Mar 2004
    I tried to compile it, but I'm using 1.4 so I had to remove the generics. I receive a different error, "non-static variable this cannot be referenced from a static context". It points at "playr" in the main method. I have no idea why, the main method should be able to instantiate the inner class. And I see no place where its using "this". This one has me stumped.

    Ah, nevermind. It just hit me. (been a long night) Since Player is an inner class, it doesn't technically exist until wnrandom is instantiated.

    wnrandom w = new wnrandom();
    Player playr = w.new Player();

    Change that and see if the other error doesn't go away.
    Last edited by Phaelax; 05-17-2006 at 08:42 AM.

  3. #3
    Join Date
    May 2006
    OK, well if I modify my code to make it so there are no inner classes within wnrandom (just move the bottom curly brace up), it gives me the same error.

Similar Threads

  1. Error : Microsoft VBScript comp Expected 'Case'
    By wordsmith in forum VB Classic
    Replies: 1
    Last Post: 09-30-2005, 11:51 AM
  2. Newb If Syntax: End of statement expected.
    By emailbuilder88 in forum ASP.NET
    Replies: 6
    Last Post: 04-09-2005, 06:50 PM
  3. .NET SP2 Released
    By Jay Glynn in forum .NET
    Replies: 16
    Last Post: 08-08-2002, 12:43 PM
  4. Returning errors from SQL Server Stored Procs
    By Khalizan in forum VB Classic
    Replies: 1
    Last Post: 11-28-2001, 01:32 AM
  5. Replies: 0
    Last Post: 07-12-2001, 12:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.