Jump to content

Why won't this simple code compile?

- - - - -

  • Please log in to reply
5 replies to this topic

#1
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
Hi guys, I have some extremely simple code that won't compile. It doesn't produce a compile error or anything, it just hangs on compilation using the blueJ IDE. (What we use at school)

import java.lang.*;
public class star
{

    private int x; //in case having an empty constructor was the reason, which it wasn't
    private int[] xPoints = {50, 100, 50, 125, 150, 175, 250, 200, 250, 150};
    private int[] yPoints = {250, 150, 100, 100, 50, 100, 100, 150, 250, 200};
    public star()
    {
        x = 0; //in case having an empty constructor was the reason, which it wasn't
    }


    public int[] getXPoints(){
        return xPoints;
    }
    public int[] getYPoints(){
        return yPoints;
    }
    public int getLength(){
        return xPoints.length();
    }
}
Any ideas what's going on? Anyone able to get it to compile?
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Well, I can't say for sure. Have you tried compiling the code with the standard Java Compiler?

Also, since you don't have any main() method, this class won't run on it's own. There aren't any hooks with which to run it, and BlueJ may have just automatically detected there was no main() method and didn't attempt to run it for you. :P

Finally...
import java.lang.*;
This import is unnecessary, java.lang is automatically imported.
Wow I changed my sig!

#3
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
This is a seperate source file from the rest of the project where a main function is defined. I was just trying to get it to compile, and yeah I added the import to see if it would fix it. I don't actually know how to use the standard java compiler, all I've ever used is bluej, I thought it used the Java SDK already.
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]

#4
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Well, I tried compiling it. This:
        return xPoints.length();
is a compile error, "Cannot find symbol". It should be
        return xPoints.length;
Other than that it compiled to a star.class file with no issues.
Wow I changed my sig!

#5
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
I'll try that tomorow in class, I'm gunna laugh if that's all it is. Thanks
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]

#6
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
Yup, it was the parenthesis. I'm annoyed that it didn't give a compile error and instead just hanged. Oh well, I can't do anything about it because it's what my school uses and all.
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users