error while running java program - java

i am facing problem while compiling a java program i am using command promt to run the program . i have kept the file name and class name both same . also i set the path , i have also set the classpath .
the only reason i can come up with is that the may be the file gets saved with a ".txt" extension inside of a ".java" extensions, as filename.java.txt.
it shows the error
javac : file not found <file name.java>
if anyone have any idea about this please tell me.

If you are using Notepad, or a similar program to save your files, surround the entire file name in quotes in the save bar.
For example, instead of writing
program.java
Select "All Files" instead of "Text files", and then in the save text box, write
"program.java"
How your save file should look:
If this is the case, I would recommend using a text editor that is specifically for coding such as Notepad++ or Sublime Text

If you are on Windows Operating System then give the file Name in double quotes like this
"MyJavaFile.java"
then press Save button , it will save your file with java extension

Related

Given property file not found

so I'm trying to run my program and I keep getting the error when I run my main class it says that given property file isn't found, below are two images of the file location and the arguments I've putten in and the error that appears, I'm struggling to realize why the file isn't being located, any help?
Because Windows in its wisdom thinks that hiding extensions of known file types is a good ting. You files is called input_parameters.prp and inputs.in, I guess.
If you give those names it would probably find this files.
To be sure you can open a cmd or powershell windows and run the dir command in that folder to see the complete names.

Why vscode is having trouble saving a java file ? Which setting should I review?

In vs code I hit Ctr+N and then Ctr+Shift+S,which is the sortcut for the 'save as' option . When I try to save a file as .java , it saved automatically as class file.Of course this also happens when I try to save the file without using the sortucts,so the only way to create a java file is after the creation of a txt file. Did anyone ever had the same problem with me ? thank you all in advance .
Do you act like this?
New a file -> Save -> In the 'Save as type' drop-down list select 'Java'.
If you look at it, you will find this: Java(*.class; *.java; *.jav; .java; .jav). And the '.class' was before the '.java', this means the file will be saved with the '.class' filename extension.
It's caused by the VSCode, but for now, you need manually to change the filename extension when you save the file.

How to intercept Tess4J's output and put it in a logfile?

I am using Tess4J JNA wrapper and I want its console output to appear in a logfile (any kind of text file).
tessInstance.setTessVariable("debug_file", "tesseract.log");
also I have a file called "logfile" in tessdata/configs/ with the following text:
debug_file tesseract.log
The result was simply Tesseract console outputs disappear, but no tesseract.log file.
I did these according to Tesseract-OCR's FAQ.
Tess4J does not have any documentation on how to properly set this in code. I couldn't even find a list of variables, but currently I am only interested in how to put console outputs of Tess4J into a text file through code.
EDIT: The following line of code will make the Tesseract's output disappear from console but the .log file has nothing in it and can't be deleted until the program is shut down.
That statement alone should suffice. Look for the file in your project's root directory. You can specify an absolute path, e.g., "C:\\Temp\\tesseract.log", if desired.

How to solve java file mapped to not java file type text

I wanted to add a java class to a project, but I did a mistake and added it as a text file. Then, I removed it and tried to add it again as a java class, but unfortunately it doesn't work anymore. And I get the following error:
Unable to parse template "Class" Error message: ABC.java mapped to not java file type text
As I searched, I faced some solutions like
this one but I can't find File Type under Editor or anything similar that I can change as suggested in the solution.
Any help would be appreciated.
PS: I am using IntelliJ 2018.3.4.
Thanks in advance,
Go on File->Settings and a dialog will open. In that dialog navigate on the left part to Editor/File Types and then you need to choose from the section Recognized File Types Java Class and remove from bottom section the problematic extension (note you have a small minus button on the right)
https://www.jetbrains.com/help/idea/creating-and-registering-file-types.html
This is a variant of Markov's answer that worked in my scenario.
Try going to File->Settings->Editor->File Types and to the Recognized File Types tab. Click the "Auto-detect file type by content" choice, and delete the name of the file you are trying to create from the "File Name Patterns" section by using the minus button.
Select required file type in top list (Recognized File Types) -- do it for "Text files"
In bottom list (Registered Patterns) select undesired pattern -- "SomeFileName.java"
Click on "-" (Minus) button to remove pattern from the list
Repeat 1-2-3 for other undesired patterns
If desired, you can also do this manually by editing config file while IDE is closed. Because it's IDE-wide setting, it is not stored in .idea folder (which has project settinsg only) -- the file to look for is called filetypes.xml and shoudl be located in ~/Library/Preferences/IntelliJIdeaXX/options ( see http://devnet.jetbrains.net/docs/DOC-181 for other OS etc )
Certainly inelegant, but you can simply copy the contents of the file to the clipboard (ctrl-c or similar), delete the file (maybe make a temporary backup somewhere outside the project), then in IntelliJ go to the desired package, right click, select new, select Java Class, name it correctly, and then you can paste in the contents of your file (ctrl-v or similar).

Associating file types with program and saving files with extensions other than .java

For my program I have 2 questions:
The program I am creating will act like MS Office. How do I associate Word, Excel, and PowerPoint files with my program?
My program lets the user use a lot of code associated with Java (JPanel). Is there any other format to save a file other than a *.java file (Such as *.A2W Alice files)? Also I can't understand how Alice reads and saves *.A2W!
Can somebody help me?
For the first, it depends on the operating system, which you have not specified. If it's on Windows, there is a pair of Windows commands: assoc and ftype. Each type of file is given a "type name." assoc associates an extension with a type, and ftype associates a type with a command to execute.
For example, on my workstation I'm using now, I have .jar associated with jarfile assoc .jar=jarfile and jarfile associated with "C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %* ftype jarfile="C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %*
Note: You need to be in the administrators group to do this.
For the second question (which probably should have been in a separate question), .java is not a file format. .java files are actually just plain text files. The code for most programming languages is like that, so it's equivalent to a .txt file so you can read and write it in any editor you prefer. The file extension merely lets the java compiler know that the code is in fact java code even though it's in a plain text format.
The java compiler, however, will not normally compile code that has an extension other than .java If I try, I get the error error: Class names, 'myFile.blah', are only accepted if annotation processing is explicitly requested This leads me to believe that there is a way to get it to compile anyway, possibly by providing it with some custom annotation processors? I'm not sure, I have never done anything like that. Still, if the code is Java code, you can just let it have a .java extension.
How do I associate Word, Excel, and PowerPoint files with my program?
Java Web Start can request file associations for file types.

Categories

Resources