DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 7 of 7

Thread: Simple problem

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Posts
    9

    Simple problem

    can someone explain me why i cant compile this
    class k{

    String[][] first = new String[1][3];

    first[0][0]= "p";

    }

  2. #2
    Join Date
    Mar 2006
    Posts
    37
    You did not define a main() in your class.
    it should be
    Code:
    class k
    {
     public static void main(String[] myArgs)
      {
    
           String[][] first = new String[1][3];
    
           first[0][0]= "p";
      {
    }
    All Programs need a starting position. In Java The Main() method is that starting position. Once I added that into your program I was able to compile and run the code.

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    255
    Quote Originally Posted by javatier
    You did not define a main() in your class.
    it should be
    Code:
    class k
    {
     public static void main(String[] myArgs)
      {
    
           String[][] first = new String[1][3];
    
           first[0][0]= "p";
      {
    }
    All Programs need a starting position. In Java The Main() method is that starting position. Once I added that into your program I was able to compile and run the code.
    Your explanation is not related to compilation.
    Happiness is good health and a bad memory.

  4. #4
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    255
    Quote Originally Posted by eruditionist
    can someone explain me why i cant compile this
    class k{

    String[][] first = new String[1][3];

    first[0][0]= "p";

    }
    The first line is okay since it is a declaration statement, so the compiler will not complain about it. However, the second line is an assignment and it needs to be declared in some method or a static code block, failing which you get a compilation error.
    Happiness is good health and a bad memory.

  5. #5
    Join Date
    Feb 2006
    Posts
    9
    This is the actual code

    class j
    {


    String[][] first = new String[1][3];
    first[0][0]= "p";
    void method(){
    System.out.println(first[0][0]);

    }
    }


    class k{
    public static void main(String[] args){

    j one = new j();
    System.out.println(one.method());

    }
    }

  6. #6
    Join Date
    Feb 2006
    Posts
    9
    and it says identifier expected.

  7. #7
    Join Date
    Oct 2005
    Posts
    107
    A method must have an identifier...public, private, protected

Similar Threads

  1. Replies: 0
    Last Post: 07-05-2005, 11:07 PM
  2. Java Applet Compiler problem?
    By mdl in forum Java
    Replies: 3
    Last Post: 03-07-2005, 02:34 AM
  3. Replies: 0
    Last Post: 12-13-2001, 12:06 PM
  4. Simple SQL Parameter problem
    By Eric in forum Database
    Replies: 1
    Last Post: 11-10-2000, 02:05 AM
  5. Simple report problem
    By Gary Thompson in forum authorevents.kurata
    Replies: 1
    Last Post: 04-20-2000, 08:13 PM

Bookmarks

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links