Bookmark Topic Watch Topic
  • New Topic

Strange Compiler Error  RSS feed

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Report post to moderator
I haven't coded in awhile, so I'm probably making some really big and stupid mistake, but I'm trying to create a program that stores a username and an automatically generated password, and let the user log in with it. I do realize that I'm using a fixed array, but I didn't want to go through the hassle of using something like ArrayList because I'm not as familiar with the syntax and I just wanted to do something to get myself back in the Java mindset. Right, so here are the errors I've been getting. I've never gotten them before.

----jGRASP exec: javac -g C:\Documents and Settings\Jacob\My Documents\javaprograms\AccountStuff.java

AccountStuff.java:32: illegal start of expression
public static void createAccountDll() throws IOException {
^
AccountStuff.java:32: illegal start of expression
public static void createAccountDll() throws IOException {
^
AccountStuff.java:32: ';' expected
public static void createAccountDll() throws IOException {
^
AccountStuff.java:32: ';' expected
public static void createAccountDll() throws IOException {
^
AccountStuff.java:32: not a statement
public static void createAccountDll() throws IOException {
^
AccountStuff.java:32: ';' expected
public static void createAccountDll() throws IOException {
^
AccountStuff.java:40: illegal start of expression
public static void createAccount(tempUName) {
^
AccountStuff.java:40: illegal start of expression
public static void createAccount(tempUName) {
^
AccountStuff.java:40: ';' expected
public static void createAccount(tempUName) {
^
AccountStuff.java:40: ';' expected
public static void createAccount(tempUName) {
^
AccountStuff.java:55: ']' expected
User user[numOfUsers] = new User(tempUName,tempPass);
^
AccountStuff.java:55: illegal start of expression
User user[numOfUsers] = new User(tempUName,tempPass);
^
AccountStuff.java:60: illegal start of expression
public static void saveUser() throws IOException{
^
AccountStuff.java:60: illegal start of expression
public static void saveUser() throws IOException{
^
AccountStuff.java:60: ';' expected
public static void saveUser() throws IOException{
^
AccountStuff.java:60: ';' expected
public static void saveUser() throws IOException{
^
AccountStuff.java:60: not a statement
public static void saveUser() throws IOException{
^
AccountStuff.java:60: ';' expected
public static void saveUser() throws IOException{
^
AccountStuff.java:73: reached end of file while parsing
}

And here is the code:



I don't know what is going on, but I'm confused. Please help. I'll be grateful.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Report post to moderator
Dude, get thee to an ide. It will save you a lot of trouble, most of the mistakes you're making will be picked up as you're typing. You're missing closing brackets, declarations for parameters and local variables. Is user a class or an array?, you treat them as both. You cast an int to a string and don't handle thrown exceptions. Eclipse or netbeans won't let you make mistakes like this.
 
Jacob Steingart
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Report post to moderator
o.o now that i read over it i'm making tons of mistakes. and users is the array and User is the Object.
 
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Report post to moderator


Here you are declaring the createAccountDll() method inside the logIn() method. This is not allowed in Java. You need to complete the logIn() method first before you write the others.
And as suggested above, its always good to use an IDE so that typing mistakes are avoided even before compilation.


Hope this helps
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by gebuh Boose:
Dude, get thee to an ide. It will save you a lot of trouble, most of the mistakes you're making will be picked up as you're typing. ... Eclipse or netbeans won't let you make mistakes like this.


Many people, myself included, believe it's better for new developers to learn using a plain text editor and a command line compiler. Just as a carpenter should know how to use a hammer before using an air gun. A lot can be learned by figuring out compile errors. Making mistakes is an important part of the learning process. As is understanding how those mistakes present themselves, and how to fix them. Learning theory research has shown this. Having an IDE quick fix issue will result in less retention. Moreover, there will be times when an IDE may not be available; for example when remotely logged into a headless server troubleshooting an issue that is costing your company a few thousand dollars a minute.

The other concern is that the developer has to spend more time learning the IDE than the language. Or they do not learn the differentiation between what is th language and what's the IDE.

IDE's are great tools and I use one (IntelliJ IDEA) every day. I love it and it makes me far more productive. But I'm able to use it to its fullest because of the fundamental and low-level understanding I have of programming. Conversely, I've seen developers coming out of college who have used an IDE since day one, and they can't understand the simplest error messages that show up in log files. A classic example is the magic number error. Finally, some of these developers can only develop using the IDE they are use to. Because they do not truly understand the underlying language, they are less able to switch to an alternate IDE. Again, because they know how to do something in their IDE, rather than knowing how something is done in their IDE.

Any way, just my 2 cents and my humble opinion.
[ July 28, 2008: Message edited by: Mark Vedder ]
 
Marshal
Posts: 56604
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by gebuh Boose:
Dude, get thee to an ide.
Disagree.

Although an IDE will pick up such errors earlier, and the error messages from Eclipse are much easier to understand than from the Sun compiler, there is enough of a learning curve for Java without having to learn the IDE as well.
 
hangman
Ranch Hand
Posts: 215
Eclipse IDE Oracle Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
I found that in helping people get up to speed, jEdit is a comforatble middle ground between an IDE and a more basic text editor.

jEdit helps you a little bit, but only with some of the more mundain typing ans syntax. You still have to learn most of the compiler rules by using "javac" from the command line.

Plus jEdit is free and runs on Solaris
 
Campbell Ritchie
Marshal
Posts: 56604
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'd forgotten about jEdit; I used to use JCreator LE as if it were a text editor before I realised it would call "compile" for me. At the risk of going off on a tangent, there are nice text editors, eg NotePad++ and NotePad2 for Windows which support automatic indentation and bracket highlighting, which make that sort of error easier to find.
[ July 29, 2008: Message edited by: Campbell Ritchie ]
 
Jacob Steingart
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'm a HUGE fan of editors. I use jGrasp, an editor used a lot by college kids learning Java. Anyways, I need to take the time to go and fix my syntax errors which, on my current schedule, could take awhile. I'll let you guys know if I have any other problems.
 
Jacob Steingart
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Report post to moderator
Ok, I now have something that compiles, but I'm getting a runtime error, again, one that I'm not particularly familiar with. Here it is (I remembered to post my constructor this time!).

----jGRASP exec: java AccountStuff

java.lang.OutOfMemoryError: Java heap space
at AccountStuff.<clinit>(AccountStuff.java:7)
Exception in thread "main"
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

I can't see what is wrong. Here is my code:



Just as a reminder, this is not finished code, so it doesn't have certain things like the ability to log in after you've created an account. It also doesn't contain the necessary encryption for creating/saving passwords/user info for much of anything, and I may or may not create that: this is just a small program to help me get back into the swing of things (and no, I don't think I'm going to add GUI to this, though if I did I could make some really corny jokes ).

Thanks in advance. I'm sure that someone who actually knows how to write Java will figure it out.
[ July 29, 2008: Message edited by: Jacob Steingart ]
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
java.lang.OutOfMemoryError: Java heap space
at AccountStuff.<clinit>(AccountStuff.java:7)


This itself means the JVM is out of memory, so it cannot continue.

Hope this helps
 
Campbell Ritchie
Marshal
Posts: 56604
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
It would have been better to start a new thread for the new error, but . . .

Read the line number; that is where you run out of space. You require several bytes per object and you are creating 1000000000 of them in the same line. Most computers only have 1GB or 2GB of available RAM, which you are trying to fit 1000000000 objects into . . . Even -Xmx won't work on my PC with 1GB RAM.

I haven't used JGrasp for some time, but you are obviously using command-line arguments via JGrasp, as well as its sophisticated editing capabilities, so you are getting the advantages of an IDE and of command-line together. Good choice
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
ooh boy...u making tonnes of grammatical errors....knocking the living daylights out of your compiler....
please work on you syntax part first...and be sure to use an IDE. Also i see you not following the java coding conventions any way closely....
coding conventions help to write legible code and read it also.

 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi viresh wali welcome to Javaranch

..u making tonnes of grammatical errors....

grammatical errors in the program?

And where are they?
 
Campbell Ritchie
Marshal
Posts: 56604
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by viresh wali:
ooh boy...u making tonnes of grammatical errors....knocking the living daylights out of your compiler....
please work on you syntax part first...and be sure to use an IDE. Also i see you not following the java coding conventions any way closely....
coding conventions help to write legible code and read it also.

Kindly read these FAQs, and these FAQs, especially this one. That is no way to talk to the other Ranchers, thank you very much.
 
Jacob Steingart
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Report post to moderator
I suppose I can take... whatever large number of slots I created in the array and size it down to something more reasonable, such as 50, being that no one is actually going to be using the program . That worked up until the point of actually saving the file, that is, it created the file but didn't write anything and threw me a NullPointerException, this specifically:


at AccountStuff.saveUser(AccountStuff.java:74)
at AccountStuff.createAccount(AccountStuff.java:66)
at AccountStuff.createAccountDll(AccountStuff.java:37)
at AccountStuff.logIn(AccountStuff.java:24)
at AccountStuff.main(AccountStuff.java:12)


I think something went wrong in createAccount(), though I'm not entirely sure. The only thing I can think of would be if something happened during object initialization. Any hints?
 
Campbell Ritchie
Marshal
Posts: 56604
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please read the line where the NullPointerException (NPE) occurred carefully.

Something to the left of a . or to the left of a [ or to the right of a ( has not been initialised.

BTW: It is not a good idea to put a number in a for-loop. Use the .length attribute of the array being used.
 
Campbell Ritchie
Marshal
Posts: 56604
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
A for loop iterating an array should read
 
Campbell Ritchie
Marshal
Posts: 56604
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't ask the same question twice. You have changed this thread to ask about the NPE, and you have also asked about the NPE here.

Since you have got the compiler error sorted out, I shall close this thread.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!