why my executable jar file created in Netbeans cant write/output a .txt file. . .my program must create a text file and write with it, how can it doesn't work when i convert it to .jar but if i run it in netbeans it work fine?..
well, i created the program using netbeans ide 6.1 it has features that automatically create and build jar files of the programs. so i just created a script to run so that i can just double click to run it her is the code of the script..
java -jar "/home/viber/JAVAFINAL/dist/JAVAFINAL.jar"
How are you creating the file ? If it is done with an absolute path then we need to see the code to tell you what might be going wrong. If it is created with a relative path in your program then the file certainly won't be created in the same place that it was created when the program was run from NB. It would be created in the directory from where you are running teh program now, i.e. your script.
Edit : Don't be shy to post your code, you have already been asked for it. It's only you who would be benefited since your query might get sorted out faster. Also if you are afraid we would steal your code, don't worry we won't. We just steal it when we have appraisals coming up and that too of the colleagues who trust us the most ;)
well. it is done by absolute path. the program runs ok in netbeans and it produce a .txt file inside my netbeans project folder(JAVAFINAL)..but when my programs convert it to .jar file using netbeans it doesn't work...
Now I see the reason for the problem. I am guessing your username is "viber" on your computer and you are running this application is user "viber" and your O.S is Unix/Linux based.
Now when you create the "txt" file what path have you hardcoded in your program ? Does it create the file in the current directory or have you hardcoded the some path inside "/home/viber", eg "/home/viber/sample.txt".
If you have not done the latter the problem is just of simple file permissions on your Linux / Unix box. By default a normal user is not allowed to create or edit files inside the "/", only the "root" user can create/edit/delete any file he wants.
If any other user in Linux wishes to create/edit/delete files in any folder other that his "home", you will need to grant him permissions on the folder explicitly using either the chown,chgrp or by adding that user specifically to some group and allowing that group to access to modify the contents of that folder.
You can learn more about file permissions in Unix here.
Alternatively you could just change your working directory to your "home" i.e. "/home/viber" and execute the JAR file as :-
it is done by absolute path. the program runs ok in netbeans and it produce a .txt file inside my netbeans project folder(JAVAFINAL)..but when my programs convert it to .jar file using netbeans it doesn't work...
thanks for the reply...
@stephen your correct my username is viber and it has permission..but still doesn't work.
note: the programs runs fine it produce a .txt file inside NB project folder name JAVAFINAL ex. /home/viber/JAVAFINAL/out.txt and the jar file is located in JAVAFINAL/dist/...
Since you are already getting an exception, can you print out the exact StackTrace of what is being thrown up at you. java.lang.NullPointerException s occur when you are trying to invoke a method/access a property etc on an object reference set to Null.
For e.x. the following code snippet would throw a NullPointerException on the second line.
alpha = alpha.substring(1); // Calling a method on an object
// reference set to nul
thanks you for the reply...
Yes now there is an exception when running in jar form her it is.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
note the line 2471 is the line where int result=compiler.run(null, null,out,"-Xmaxerrs","1", filetoRun); is placed..
how come i didnt see this error running in netbeans, now as my program is converted to executable jar i see this error?....
This is a problem of your JDK (JAVA_HOME) path not being set. Thats the reason the program doesn't get a java compiler. And if you read the ToolProvider docs, it says that the method getSystemJavaCompiler returns null if no compiler is provided.
In your Linux system, set the PATH variable to %JAVA_HOME% then export the path, by writing EXPORT PATH on the next line. For this to take effect you need to logout of your X-window system, so just do a ctrl-alt-backspace and login again, and then try to run the program.
**how to solve invalid keystore error in android studio here is error report----------------------->
here is error report--------> error:Error:java.lang.RuntimeException: com.android.ide.common.signing.KeytoolException: Failed to read key palash from store "D:\MyApplication3.idea\workspace.xml": Invalid keystore format ...