• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Class not found error in main method

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am getting a class not found error. I have a main class "NetBeansTestExample2". I have created a PrintGrades2 class in it. And i created a test class using Tools->create/update test. Now in the main class i.e "NetBeansTestExample2", I am using the following command:


in my main method.
I am getting the error:


 error: cannot find symbol
 Result result = JUnitCore.runClasses(PrintGrades2Test);
 symbol:   variable PrintGrades2Test
 location: class NetBeansTestExample2



The complete error message is:
 



  Compiling 2 source files to D:..............\NetBeansTestExample2\build\classes
  D:........\NetBeansTestExample2\src\netbeanstestexample2\NetBeansTestExample2.java:24: error: cannot find symbol
  Result result = JUnitCore.runClasses(PrintGrades2Test);
  symbol:   variable PrintGrades2Test
  location: class NetBeansTestExample2
  1 error
  D:........\NetBeansTestExample2\nbproject\build-impl.xml:929: The following error occurred while executing this line:
 D:.........\NetBeansTestExample2\nbproject\build-impl.xml:269: Compile failed; see the compiler error output for details.
 BUILD FAILED (total time: 1 second)





I am working on Netbeans IDE 8.1 and my main method is given below:



Some body please guide me.

Zulfi.
 
Sheriff
Posts: 3108
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JUnitCore.runClasses is expecting Class<?>... so you should be specifying PrintGrades2Test.class
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have added the .class extension but now I am getting following error:



run:
C:\Users\....\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:48:
Cancelled by user.
BUILD FAILED (total time: 4 seconds)



My java code is now:




The run.xml code is:



Somebody please guide me.

Zulfi.
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have found that this issue was reported at NetBeans site also:

https://netbeans.org/bugzilla/show_bug.cgi?id=217710



& they say that this issue can be resolved by installing latest 8.2 version of NetBeans. However, I am still getting this problem.




C:\Users\HP\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:48:
Cancelled by user.
BUILD FAILED (total time: 2 seconds)



Some body please guide me some alternative for it.How to use a main method to report the failure and successes.

I have also attached the image.
Zulfi.
run.xml-prob.jpg
[Thumbnail for run.xml-prob.jpg]
 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anytime you see a red icon instead of a line number, or a red wiggly line under some code, that means that line won't compile and you should not run it.  Fix the compile error first.
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your response. I tried to remove the error by attaching the package name but still I am getting error:




The error says that:


cannot find symbol: class PrintGrades2Test

May split declaration into declaration and assignment.




Please guide me.

Zulfi.
 
Ron McLeod
Sheriff
Posts: 3108
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, try putting PrintGrades2 and PrintGrades2Test in to proper packages (don't use default package).

Next, import PrintGrades2Test with its fully qualified package name in to your NetBeansTestExample2 class.
 
Ron McLeod
Sheriff
Posts: 3108
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zulfi Khan wrote:I tried to remove the error by attaching the package name but still I am getting error:


This won't work because PrintGrades2Test is not actually in the JavaJUNITExample8_2 package.

See my last comment (which I was writing at the same time as you) and put all classes in proper packages.
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Currently I have this sort of directory structure:

I have the following directory structure:
JavaJUNITExample8_2\src\javajunitexample8_2\JavaJUNitExample8_2.java
JavaJUNITExample8_2\src\PrintGrades2.java
JavaJUNITExample8_2\test\PrintGrades2Test.java

I have tried two approaches:
1st approach

JavaJUNITExample8_2\src\javajunitexample8_2\JavaJUNitExample8_2.java
JavaJUNITExample8_2\src\javajunitexample8_2\PrintGrades2.java
JavaJUNITExample8_2\src\javajunitexample8_2\PrintGrades2Test.java

2nd approach
JavaJUNITExample8_2\src\javajunitexample8_2\JavaJUNitExample8_2.java
JavaJUNITExample8_2\src\PrintGrades2.java
JavaJUNITExample8_2\src\PrintGrades2Test.java

But both are not working. I dont know much about it.

Please guide me.

Zulfi.

 
Ron McLeod
Sheriff
Posts: 3108
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zulfi Khan wrote:1st approach

JavaJUNITExample8_2\src\javajunitexample8_2\JavaJUNitExample8_2.java
JavaJUNITExample8_2\src\javajunitexample8_2\PrintGrades2.java
JavaJUNITExample8_2\src\javajunitexample8_2\PrintGrades2Test.java


Can you share a screen capture of the Projects tab in NetBeans so that we can see what the IDE shows as the project structure?
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,Thanks for your time.

I am attaching a picture.

I first created the JavaJUNITExample8_2 application and then added the PrintGrades2 using the New option & PrintGradesTest using Tools create/update test.

Thanks for your time.
Zulfi.
package-prob.jpg
[Thumbnail for package-prob.jpg]
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I tried the 1st option again. Now there is no error on the line. All red marks removed but I am getting falling error now:



Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
at javajunitexample8_2.JavaJUNITExample8_2.main(JavaJUNITExample8_2.java:23)
C:\Users\HP\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 2 seconds)




Zulfi.
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am attaching the image again.

Zulfi.
no-red-mark.jpg
[Thumbnail for no-red-mark.jpg]
 
Ron McLeod
Sheriff
Posts: 3108
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zulfi Khan wrote:Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
at javajunitexample8_2.JavaJUNITExample8_2.main(JavaJUNITExample8_2.java:23)
C:\Users\HP\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 2 seconds)


I don't use NetBeans, but to me this looks like a run-time problem, not a compile-time issue.

Do you see any errors if you just perform a Clean-and-Build (can use the hammer and brush icon)  without trying to run anything?

Also, what does your PrintGrades2Test class look like?
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I used the hammer icon & used clean & build & hammer with brush did the same.

I got following error:



ant -f "D:\\java prog\\ttu_Independent_Study_SE\\8P2NB\\JavaJUNITExample8_2" -Dnb.internal.action.name=rebuild clean jar
init:
deps-clean:
Updating property file: D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\build\built-clean.properties
Deleting directory D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\build
clean:
init:
deps-jar:
Created dir: D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\build
Updating property file: D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\build\built-jar.properties
Created dir: D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\build\classes
Created dir: D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\build\empty
Created dir: D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\build\generated-sources\ap-source-output
Compiling 3 source files to D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\build\classes
D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\src\javajunitexample8_2\JavaJUNITExample8_2.java:23: error: cannot find symbol
       Result result = JUnitCore.runClasses(PrintGrades2Test.class);
 symbol:   class PrintGrades2Test
 location: class JavaJUNITExample8_2
1 error
D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\nbproject\build-impl.xml:930: The following error occurred while executing this line:
D:\java prog\ttu_Independent_Study_SE\8P2NB\JavaJUNITExample8_2\nbproject\build-impl.xml:270: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 1 second)


My PrintGrades2test.java






Zulfi.

 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The new project tab is attached.

Zulfi.
new-proj-tab.jpg
[Thumbnail for new-proj-tab.jpg]
 
Ron McLeod
Sheriff
Posts: 3108
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see a package statement for PrintGrades2Test - is it in the default package?

I installed NetBeans to try your code and it did work for me.  Since I don't use NetBeans, I'm not familiar with what output you should expect when compiling and running.

 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am now getting run time exception:


Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.junit.runner.Computer.getSuite(Computer.java:26)
at org.junit.runner.Request.classes(Request.java:69)
at org.junit.runner.JUnitCore.run(JUnitCore.java:127)
at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:76)
at javajunitexample8_2.JavaJUNITExample8_2.main(JavaJUNITExample8_2.java:23)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 17 more
C:\Users\HP\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)



I have added the package statement in PrintGrades2Test.java:



Zulfi.
 
Ron McLeod
Sheriff
Posts: 3108
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding the hamcrest-core to your libraries. See my screen cap.
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your time and advice. It worked.

God bless you.

Zulfi.
 
Ron McLeod
Sheriff
Posts: 3108
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome - glad I was able to help
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic