• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[newbie] See anything wrong here?

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I copied two classes so that I can troubleshoot them by first using the command prompt. Original files were written within Eclipse.

Environment
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)




Output
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:13: ';' expected
if (args.length > 0) _name = args[0]);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:14: 'else' without 'if'
else
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:21: illegal start of type
try
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:21: ';' expected
try
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: illegal start of type
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: <identifier> expected
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: ';' expected
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: illegal start of type
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: <identifier> expected
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: ';' expected
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: <identifier> expected
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: <identifier> expected
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: ';' expected
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: illegal start of type
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: <identifier> expected
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:27: ';' expected
if (_modifiers.length() > 0) System.out.print(_modifiers + " ");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:28: illegal start of type
System.out.print("class" + _name);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:28: ';' expected
System.out.print("class" + _name);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:28: invalid method declaration; return type required
System.out.print("class" + _name);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:28: illegal start of type
System.out.print("class" + _name);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:28: ')' expected
System.out.print("class" + _name);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:28: ';' expected
System.out.print("class" + _name);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:28: illegal start of type
System.out.print("class" + _name);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:28: <identifier> expected
System.out.print("class" + _name);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:28: ';' expected
System.out.print("class" + _name);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: illegal start of type
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: <identifier> expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: ';' expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: illegal start of type
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: <identifier> expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: ';' expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: illegal start of type
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: <identifier> expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: ';' expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: illegal start of type
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: ';' expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: <identifier> expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: illegal start of type
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: ';' expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: <identifier> expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: illegal start of type
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: ')' expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: ';' expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: illegal start of type
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:29: ';' expected
if ((_superclass != null) && (_superclass != Object.class)) System.out.print("extends " + _superclass.getName());
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:31: <identifier> expected
System.out.print("\n{n");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:31: illegal start of type
System.out.print("\n{n");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:32: invalid method declaration; return type required
printConstructors(_cl); //see file ReflectionHelper.java
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:32: <identifier> expected
printConstructors(_cl); //see file ReflectionHelper.java
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:33: <identifier> expected
System.out.println();
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:34: invalid method declaration; return type required
printMethods(_cl);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:34: <identifier> expected
printMethods(_cl);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:35: <identifier> expected
System.out.println();
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:36: invalid method declaration; return type required
printFields(_cl);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:36: <identifier> expected
printFields(_cl);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:37: <identifier> expected
System.out.println("}");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:37: illegal start of type
System.out.println("}");
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:40: illegal start of type
catch (ClassNotFoundException e)
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:45: <identifier> expected
System.exit(0);
^
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:45: illegal start of type
System.exit(0);
^
60 errors

Tool completed with exit code 1


So far I have tried removing the tab characters.

2. I have a small project that is made up of two classes:
ReflectionTest.java
ReflectionHelper.java

If I compile ReflectionTest.java, would it automatically look up the classes called i.e. ReflectionHelper.java. The methods are called statically. Is it required to set the classpath before?


C:\Users\Administrator\Desktop\Java_console>SET CLASSPATH=C:\Users\Administrator
\Desktop\Java_console

C:\Users\Administrator\Desktop\Java_console>echo %CLASSPATH%
C:\Users\Administrator\Desktop\Java_console

C:\Users\Administrator\Desktop\Java_console>javac ReflectionTest.java ??
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's an extra closing parenthesis in the first line that shows an error.
 
Henry Wong
author
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:13: ';' expected
if (args.length > 0) _name = args[0]);
^


You have mismatch parens. The expression is not valid.

C:\Users\Administrator\Desktop\Java_console\ReflectionTest.java:14: 'else' without 'if'
else
^


Well, basically, the previous "if" is already terminated, so having an else here is not valid.

And the rest are probably a chain reaction of errors. I recommend that you fix the first two (or even just the first one), and recompile again.

Henry
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. that was it. Now it only seems to have a problem calling static methods within another class:

Output of command line:
Directory of C:\Users\Administrator\Desktop\Java_console

05/16/2009 01:04 PM <DIR> .
05/16/2009 01:04 PM <DIR> ..
05/08/2009 02:00 PM 41 cleanup.bat
05/11/2009 06:43 PM 1,797 Command Prompt.lnk
05/16/2009 12:53 PM 2,407 ReflectionHelper.class
05/16/2009 12:41 PM 1,945 ReflectionHelper.java
05/16/2009 01:36 PM 1,293 ReflectionTest.java
5 File(s) 7,483 bytes
2 Dir(s) 50,628,554,752 bytes free

C:\Users\Administrator\Desktop\Java_console>SET CLASSPATH="C:\Users\Administrato
r\Desktop\Java_console"

C:\Users\Administrator\Desktop\Java_console>javac ReflectionTest.java
ReflectionTest.java:32: cannot find symbol
symbol : method printConstructors(java.lang.Class)
location: class homenetwork.bkr.training.ReflectionTest
printConstructors(_cl); //see file ReflectionHelper.java
^
ReflectionTest.java:34: cannot find symbol
symbol : method printMethods(java.lang.Class)
location: class homenetwork.bkr.training.ReflectionTest
printMethods(_cl);
^
ReflectionTest.java:36: cannot find symbol
symbol : method printFields(java.lang.Class)
location: class homenetwork.bkr.training.ReflectionTest
printFields(_cl);
^
3 errors

echo %CLASSPATH%
"C:\Users\Administrator\Desktop\Java_console"

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If printConstructors() and friends are methods in ReflectionHelper, then you need to either say that:

ReflectionHelper.printConstructors(_cl);

or you need to statically import the methods into this class, like

import static ReflectionHelper.*;

Word to the wise: don't blame Eclipse bugs for compiler errors! If your code doesn't compile, there's something wrong with it, not something wrong with Eclipse. Occam's Razor applies here.

 
Henry Wong
author
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Users\Administrator\Desktop\Java_console>javac ReflectionTest.java
ReflectionTest.java:32: cannot find symbol
symbol : method printConstructors(java.lang.Class)
location: class homenetwork.bkr.training.ReflectionTest
printConstructors(_cl); //see file ReflectionHelper.java
^


You are trying to call the printConstructors() method of your current class -- which doesn't exist. There is no mention of another class, anywhere in that statement.

Henry
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:If printConstructors() and friends are methods in ReflectionHelper, then you need to either say that:

ReflectionHelper.printConstructors(_cl);

or you need to statically import the methods into this class, like

import static ReflectionHelper.*;

Word to the wise: don't blame Eclipse bugs for compiler errors! If your code doesn't compile, there's something wrong with it, not something wrong with Eclipse. Occam's Razor applies here.



Thanks...I had forgotten about that

ReflectionHelper.printConstructors(_cl);//works
 
Henry Wong
author
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Word to the wise: don't blame Eclipse bugs for compiler errors! If your code doesn't compile, there's something wrong with it, not something wrong with Eclipse. Occam's Razor applies here.


Yeah... And hopefully, the statement about reporting the bug was a joke. Because it would be pretty embarrassing if it was true...

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic