• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with my code  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.Before i 'm sorry if i will make mistake i dont speak very good english.One week ago i bought a book.Java from 0 to expert.First time i stay a lot for enviroment variables.After i did i tried some simple code and it's work.Now i tried to make a package with 2 class.When i compile with javac it's work but after i got one error.And i saw after the other programs that was good in one time now doesnt want to work anymore.

I can't understand what it's wrong i did all the step from the book.
https://s15.postimg.org/br7n6fw3v/image.jpg The main source after compile and the eror
https://s13.postimg.org/nudslovh3/image.jpg the package with the class and after compile
It must show on the cm after compile:
"Suntem in ClasaUnu"
"Suntem in ClasaDoi'
enviroment variables that i entroduce are:
user variables for Admin:
classpath:->C:\Program Files\Java\jre\lib\rt.jar;.
path:->C:\Program Files\Java\jdk\bin;.

System variables
CLASSPATH :->C:\Program Files\Java\jdk;C:\Program Files\Java\jre;.
Path :-> C:\WINDOWS;C:\WINDOWS\SYSTEM;C:\Program Files\Java\jdk\bin;C:\Program Files\Java\jre\bin
I search a lto and i didn't find if somebody want you can enter in my PC with team viewer.Please help me somebody with this error.Thanks for everything and sorry for my bad english.
 
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Please use code tags as explained here instead of posting images.

you should not need CLASSPATH variable set.

Try removing it and compiling and running your program without -cp switch.

I recommend using Notepad++ instead of MS Notepad for editing java source files.
 
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To copy from the Windows Command Prompt screen: Find the little icon at the top left corner. Right-click that icon and a context menu will appear. One of the options is "Edit" (or the equivalent in Romanian, although your computer's language looks to be English) and it has an arrow next to it. Follow that to get a sub-menu.

First click on "Mark". Then use the arrow keys or the mouse to highlight what you want to copy, and when you have the right data highlighted then press Enter and that text gets put into the clipboard.

You can then paste that text anywhere, like in this forum for example.
 
Bartender
Posts: 1840
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To compile your application: 
javac FILE_NAME
e.g. javac TestPachet.java

to RUN your application
java FULL_CLASS_NAME
e.g. java TestPachet
java com.mypackage.MyClass

note that this is NOT a filename, but it will go looking for FULL_CLASS_NAME.class in the classpath.
in this case  TestPachet.class in the same directory, or from the current directory com\mypackage\MyClass.class

It is easiest if you have all of your code "in one place" so you only need the current directory as a classpath.
 
Iovitu George
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sorry because i was late.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Admin\Desktop>cd JAVA PROGRAMS

C:\Users\Admin\Desktop\JAVA PROGRAMS>java AplicatieUnu
Aplicatie independenta

C:\Users\Admin\Desktop\JAVA PROGRAMS>javac -cp C:\Temp TestPachet.java

C:\Users\Admin\Desktop\JAVA PROGRAMS>java -cp C:\Temp TestPachet
Error: Could not find or load main class TestPachet

C:\Users\Admin\Desktop\JAVA PROGRAMS>


SO now it run the program but still when i compile test pachet didn't work should i delete all varyables from system?
 
Iovitu George
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MY CODE FOR TEST PACHET is
TestPachet.java code:>
import pachet.exemplu.*;
public class TestPachet{
public static void main(String[] args)
{
ClasaUnu cu=new ClasaUnu();
ClasaDoi cad=new ClasaDoi();

}
}

THe package with the two class
ClasaUnu.java location C:\Temp\pachet\exemplu code :>package pachet.exemplu;
public class ClasaUnu{
public ClasaUnu(){
System.out.println("Suntem in ClasaUnu");
}
}

COde for ClasaDoi.java location C:\Temp\pachet\exemplu code >
package pachet.exemplu;
public class ClasaDoi{
public ClasaDoi(){
System.out.println("Suntem in ClasaDoi");
}
}
 
Ranch Foreman
Posts: 3068
37
 
Iovitu George
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes because i tried every forum and still i have that error.I don't know why because i copy the code exactly from my book javac -cp C:\Temp TestPachet.java works but java -cp C:\Temp TestPachet receive an error
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

Please indent your code correctly, otherwise the code tags won't work well.
Why are you using the -cp option to compile your code? Is that the correct location of classes you are using as dependencies? Where are these .java files? If you use C:\Temp as a CLASSPATH, the will expect to find all the files in that location. TestPachet.class is not in that location. Please run the dir instruction on that JAVA PROGRAMS folder and show us what happens.
 
Iovitu George
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know  in the book it say to use cp if we don't want to change the medium variable CLASSPATH .
ClasaUnu.java and ClasaDoi.java are C:\Temp\pachet\exemplu and in the JAVA PROGRAMS is TestPachet.java
 
Iovitu George
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Directory of C:\Users\Admin\Desktop\JAVA PROGRAMS

08/23/2016  04:27 PM    <DIR>          .
08/23/2016  04:27 PM    <DIR>          ..
08/19/2016  05:54 PM               385 AplicatiaDoi.class
08/19/2016  06:03 PM               153 AplicatiaDoi.html
08/19/2016  05:56 PM               182 AplicatiaDoi.java
08/22/2016  03:47 PM               519 AplicatieUnu.class
08/19/2016  09:12 AM               224 AplicatieUnu.java
08/23/2016  04:26 PM                 0 cd
08/20/2016  12:30 PM               376 ClasaDoi.class
08/20/2016  12:27 PM               118 ClasaDoi.java
08/20/2016  12:30 PM               376 ClasaUnu.class
08/20/2016  12:30 PM               121 ClasaUnu.java
08/19/2016  08:14 AM             1,211 copilator.lnk
08/23/2016  04:26 PM                 0 java
08/21/2016  01:28 PM    <DIR>          Mine
08/23/2016  04:27 PM               357 TestPachet.class
08/21/2016  12:45 PM               161 TestPachet.java
              14 File(s)          4,183 bytes
               3 Dir(s)  419,083,595,776 bytes free

C:\Users\Admin\Desktop\JAVA PROGRAMS>
 
Iovitu George
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Users\Admin\Desktop>cd C:\Temp\pachet\exemplu

C:\Temp\pachet\exemplu>dir
Volume in drive C has no label.
Volume Serial Number is 0248-F6C0

Directory of C:\Temp\pachet\exemplu

08/22/2016  09:57 PM    <DIR>          .
08/22/2016  09:57 PM    <DIR>          ..
08/22/2016  09:19 PM         3,932,214 1.jpg
08/22/2016  09:23 PM         3,932,214 2.jpg
08/22/2016  09:27 PM         3,932,214 3.bmp
08/22/2016  09:28 PM         3,932,214 4.bmp
08/22/2016  09:28 PM         3,932,214 5.bmp
08/22/2016  09:18 PM               376 ClasaDoi.class
08/20/2016  07:30 PM               118 ClasaDoi.java
08/22/2016  09:18 PM               376 ClasaUnu.class
08/20/2016  07:38 PM               116 ClasaUnu.java
               9 File(s)     19,662,056 bytes
               2 Dir(s)  419,083,407,360 bytes free

C:\Temp\pachet\exemplu>
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my reply  in the cross post.

Crossposting isn't an issue if you inform people of where you have asked the question.
That way we don't answer questions that have already been answered.
 
Iovitu George
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys thanks a lot for everything i find the error somebody help me . i must put java -cp .;C:\Temp TestPachet
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thse files are in the wrong places. You shoul‍d not put anything in a Temp folder, otherwise it might be deleted automatically. Those files have a package name, so they sh‍ould be inside folders of that name. Maybe there are correctly‑named folders inside your Temp directory.
 
Iovitu George
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know because when i look in C for the Temp folder was no folder and i create a folder with this name....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!