Intellij output too much information - java

Wondering if there is anyway I can clean the output of intellij when executing a java app with arguments. I require to see only the arguments and all the information before the app name have no use for me and hoping I can turn them off for now.
e.g.:
"C:\Program Files\Java\jdk1.7.0_11\bin\java" -Didea.launcher.port=7538 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.0\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_11\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_11\jre\lib\ext\zipfs.jar;C:\Users\asd\IdeaProjects\Assignment1\out\production\Assignment1;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain Problem2 25 -5 10 5frf
As you can see, the arguments are the last 4 words in this. I would just simply like to see the app.java arg1 arg2 ...

Despite that I don't think you can change this, what about this simple Java solution:
class Something{
public static void main(String[] args){
for (String arg : args){
System.out.println(arg);
}
System.out.println("--------");
}
}
Seems I'm right. Here is the documentation for the "Run"-View. It doesn't include any information on doing something like this.
An idea to not forget to remove this in final releases would be to add a //TODO Remove this. IntelliJ can list all ToDo's in a list and before you ship it out you just look over all todos and remove it.
Another idea would be emulating a #define from C by simply having a public static final boolean RELEASED which you set to true when you release the code. You can check for that flag and modern Java compilers will most likely optimize the output-block away.

Related

New to Java , error already

package day1.examples;
public class String2 {
public static void main(String[] args) {
String x = "Andrei Vlad";
System.out.println("Hello" + x);
}
}
I keep getting this error when i run it
Error: Main method not found in class day1.examples.String2, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
and on line error it says type mysmatch cannot convert from java lang string etc..
Thank you
It works for me:
[steve#newbox ~]$ cd /tmp=
[steve#newbox tmp]$ mkdir -p day1/examples
[steve#newbox tmp]$ cat > day1/examples/String2.java
package day1.examples;
public class String2 {
public static void main(String[] args) {
String x = "Andrei Vlad";
System.out.println("Hello" + x);
}
}
[steve#newbox tmp]$ javac -classpath . day1/examples/String2.java
[steve#newbox tmp]$ java -classpath . day1.examples.String2
HelloAndrei Vlad
[steve#newbox tmp]$
The most likely explanation is that you have managed to get Eclipse rather confused.
My initial idea was that this was a homoglyph problem. But provided that you have copy-and-pasted the code correctly, the evidence disproves that.
The other idea I had was that you had mistakenly created your own version of the String class (in the day1.examples package). However, that should have resulted in compilation errors in the initialization of x.
I'd start by trying with a clean of the project. Seems weird you would need to do so with only one class in a single package but it will recompile all of your code for you. Everytime I have an issue that I don't think I should have I always F5 (refresh) my packages and then clean. You'd be surprised how many issues it fixes.
Go to Project --> Clean
Then try running again.
The code says that there are somethink wrong with your main class but all seems ok.
In Eclipse rigth click on your projects-> run-> run configurations and check if all is ok.

Can't find symbol even though class is in the same folder

I have looked at all the other stuff, mine is a compatibility issue I think, or PATH maybe. I have a bunch of classes I've been using since about 2008 and now the java command and the javac command can't find the classes even though they are in the same directory/folder. I have C:\Program Files\Java\jdk1.6.0_25\bin in the Path variable, but nothing in the Classpath. I normally have the compiled classes in the same folder with the java I'm compiling. I've been doing the same thing for 5 years! I have recompiled the lowest level class which is called WotifCat01. The compiler comes back with
WotifCat00.java:27:cannot find symbol
Symbol : WotifCat01
import java.io.*;
/** Find/replace program **/
class WotifCat00
{
private static int cnt;
private static String[][] filnamStrg={ {"Data/reftfile.txt","Data/AccumData/allreftfile.txt","","",""},
{"Data/reft1file.txt","Data/AccumData/allreft1file.txt","","",""},
{"Data/reft2file.txt","Data/AccumData/allreft2file.txt","","",""},
{"Data/reft3file.txt","Data/AccumData/allreft3file.txt","","",""},
{"Data/reft4file.txt","Data/AccumData/allreft4file.txt","","",""},
{"Data/work1file.txt","Data/AccumData/alltextsrc.txt","","",""},
{"","","","",""} };
private static String[] args1={"","","","",""};
public static void main(String[] args) {
while (filnamStrg[cnt][0] != "") {
args1[0] = filnamStrg[cnt][0];
args1[1] = filnamStrg[cnt][1];
WotifCat01 wotifCat01 = new WotifCat01();
wotifCat01.main(args1);
cnt++;
}
}
}
I've used this setup for a while and it worked fine on my laptop till now with Windows 7. I suspect something I've installed has overwritten something. This has to be really simple but I can't see it. I've removed jdk1.7.0_25 back to 1.6 but no change.
I backed up the classpath and deleted it. Now works fine. It contained IBM DB2 paths. DB2 I had installed in 2011 so discounted it, but it did have java paths in it so it must have overrode the path. I am not sure how DB2 managed to do so 2 years after install, I may have inadvertently activated something. Thanks for your input.
Neil Mc

Getting "class does not have a static void main method accepting String[]" error even though main signature is correct

My DrJava was working fine, but now I keep getting the folowing error whenever I run anything:
Static Error: This class does not have a static void main method accepting String[].
So it will compile OK, but then it shoots out the error . This happens even though everything I test does indeed have a public static void main(String[] args) in it. It seems like a classpath/resources type of error. I appreciate any tips
EDIT: my class
public class Test{
public static void main(String[] args){
System.out.println(" hashmap ");
}
}
There's nothing wrong with the code, so the problem must be with the environment.
Check that you're actually executing that class. Find out where the class that's executed is specified and check it's correct
Check that you're compiling the class. Maybe the code you're looking at has not been compiled and you're trying to execute an old version that was compild before you coded a main()
Check your classpath. Is the compiled class accessible in the classpath of the java command
You don't need to reinstall java, nor is it a java version issue. It may be the way that your are running the program.
To check if it is a problem with your code, do the following:
Make a new folder and put Test.java in it.
Open up Command Line Or Terminal and change to that folder .
Type javac Test.java. Test.class should be in the folder now.
If you want, open up the class with a text editor. This is what I get:
˛∫æ2
<init>()VCodeLineNumberTablemain([Ljava/lang/String;)V
SourceFile Test.java hashmap Testjava/lang/Objectjava/lang/SystemoutLjava/io/PrintStream;java/io/PrintStreamprintln(Ljava/l ang/String;)V! *∑±
% ≤∂±
Back to the command line or terminal, type java Test.
If you get an error, which you shouldn't, I don't know what to say. It should produce the string " hashmap " on to the command line or terminal.
Why re-installing Dr. Java may not work is because you may be using the same working directory, causing same run settings to be used. Dr. Java may be running an external program, one without a main method.
I think that you should install the Eclipse IDE for Java. It is much easier to get around, it looks nicer, and it runs the file or project that you are looking at currently.
Sometimes this problem happens because may be mistake in saving file.you always your file using double quotes and with the .java extension which is main class means that class containing main method.
you should save your file by class name which is public .if there is two classes and both have main method then you should save your file by class name that is public and that class will be run.As like your compiler looking for main method in public static void main(String [] args) that is contract for jvm to run a programme
so it is not able to found that main method that is static and it looking for your Dr class.java
See this Example it have two main methods and practice these kinds of question.I also got this kind of problem in starting.
public class TestFirst
{
public static void main(String [] args){
System.out.println(" TestFirst ");
}
}
class Test{
public static void main(String [] args){
System.out.println(" hashmap ");
}
}
if you save pro-gramme by "TestFirst.java" then o/p will come TestFirst if you do some mistake in main method because we have saved our programme by TestFirst then you will get error like you got.
# 2nd mistake may be this
debian#debian:~/Geany_java$ javac Test1.java
debian#debian:~/Geany_java$ java Test1
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:349)
at Test1.main(Test1.java:11)
your classpath has not set properly See above Compiling successfully but running showing same kind of error you got.Which OS is using I can guide you properly.
Check that actually your file have the .java termination nor the .dj
There is nothing wrong with the code.
It is the executing environment which might have problem. Please share the details.
Check if program compiled correctly.
Check time-stamo of .class file.
Check permissions on folder/directory where class-files are getting generated.
Check if DrJAVA has appropriate permission on the directory.
Did you create a file, compiled it with out main?
Check class-path. Might be possible that previous class file is still being found by JDK in classpath.
Try compiling .java file from cmdLine instead of editor.
As others have mentioned, your code is fine. There must be a problem with your environment. I recently experienced a similar issue when investigating and answering this question.
Basically, in that question, the code Void.class instanceof Class resulted in a compiler error because a user-made Class.class existed in the classpath, so one Class (the Java built-in java.lang.Class) didn't match with the given Class (user-made).
Something similar may be at work here. It is possible that there is a user-made String.class in your classpath. Then in your main signature, String[] args would mean an array of your String, when Dr. Java must be looking for a main method taking an array of the Java built-in String, i.e. java.lang.String[]. If you have a custom String class in your classpath (or in your project?), then the Java compiler will choose it over the built-in String. If you were to compile and run your Test class from the command line, then you would get the runtime error: Exception in thread "main" java.lang.NoSuchMethodError: main.
Following #S0urceC0ded's suggestion, you may find this when looking at Test.class in a text editor:
main([LString;)V // A user-made String class
instead of what it's supposed to be:
main([Ljava/lang/String;)V // The built-in java.lang.String class
If so, remove your own String class (at least the .class file, but also the .java file so the .class file isn't re-created) from the classpath, and compile and run your Test class again.
Without a look at your environment, I can't tell for sure that this is the issue. But it can explain it.
If you are using Dr.Java as IDE, then you need to make sure that the main class containing 'public static void main' should be at the very top of your program. Otherwise Dr.Java throws this error during runtime.

Problems using Matlab Builder JA

First of all I would like to thank in advance everyone for reading such a long post. I really appreciate your help.
The thing is that I've been doing some research on how to "connect" Matlab and Java for a project I am working on for university. I figured that the most suitable option was using Matlab Builder JA, but I'm having a lot of troubles with it.
I follow step by step the instructions described on a tutorial (the link of the video in below) but get compilation errors over and over, and I really don't know how to fix them. The tutorial is about creating a Java package (demo.jar) with MATLAB ("com.demo"), which contains a class (MLTestClass) with a function makeSqr(n) which returns an n × n square matrix. Then I go to Eclipse, I add to the project both libraries javabuilder.jar and demo.jar and then create the following class:
public class Driver {
public static void main (String[] args) {
MLTestClass x = null;
Object result [] = null;
try {
x = new MLTestClass ();
result = x.makeSqr (1, 5);
System.out.println (result [0]);
} catch (MWException e) {
e.printStackTrace();
}
}
}
Of course I import com.demo.* and com.mathworks.toolbox.javabuilder.*.
Here are the errors the console gives me:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getProxyLibraryDir(MCRConfiguration.java:163)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.get(MCRConfiguration.java:77)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.<clinit>(MCRConfiguration.java:87)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getMCRRoot(MCRConfiguration.java:92)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ModuleDir.<clinit>(MCRConfiguration.java:66)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getModuleDir(MCRConfiguration.java:71)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.<clinit>(MWMCR.java:1573)
at com.demo.DemoMCRFactory.(DemoMCRFactory.java:122)
at com.demo.MLTestClass.(MLTestClass.java:63)
at Driver.main(Driver.java:12)
Caused by: java.lang.NullPointerException
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ProxyLibraryDir.get(MCRConfiguration.java:143)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ProxyLibraryDir.<clinit>(MCRConfiguration.java:158)
... 10 more
Just in case, link tutorial (it's the video): http://www.mathworks.nl/products/javabuilder/description2.html
Anyone has any ideas what the problem could be? It says something about NullPointerException, but I don't know how to solve it as the constructor is provided by the class created with MATLAB. I didn't have any issues installing MCR, and by the way I have MacOS, which I hope is not the source of the problem :).
Again, sorry for the long post and thank you for your time.
Béntor.
Yes, please install MCR. The installation also mentions about setting environmental variables like LD_LIBRARY_PATH etc. If you are using eclipse, i would recommend you update the environmental variables
right click->
properties ->
run/debug settings->
environmental variables
I also had to make sure that variable MCR_CACHE_ROOT pointed to different directory since my home directory was not big enough.
You have install MCR (avaliable in http://www.mathworks.com/products/compiler/mcr/index.html)
None of the above solutions helped me (I already had MCR installed and Macs use DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH), and noone else online seemed to know. Finally in desperation, I tried editing the DYLD_LIBRARY_PATH and finally got it to work by removing the last part of it: /Applications/MATLAB/MATLAB_Compiler_Runtime/v82/sys/java/jre/maci64/jre/lib
Now the demo application from the tutorial works.
Next comes trying to make my code work.
OS X Paths for Run-Time Deployment
Use these setenv commands to set your MATLAB Runtime paths.
setenv DYLD_LIBRARY_PATH \
mcr_root/version/runtime/maci64 \
mcr_root/version/bin/maci64 \
mcr_root/version/sys/os/maci64
Source: http://www.mathworks.com/help/compiler_sdk/java/mcr-path-settings-for-run-time-deployment.html

Cannot run "Hello World" program in Eclipse

I have an error in my first step with Java, so when i try to run the code hello world:
class apples{
public static void main(String args[]){
System.out.println("Hello World!");
}
}
I go to: - Run as .. -> Then i choose Java aplicacion - > And i press Ok
But when i press Ok does not appear the window down to show me the correct message Hello World
Your code works fine for me:
class apples
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
I downloaded it to c:\temp\apples.java.
Here's how I compiled and ran it:
C:\temp>javac -cp . apples.java
C:\temp>dir apples
Volume in drive C is HP_PAVILION
Volume Serial Number is 0200-EE0C
Directory of C:\temp
C:\temp>dir ap*
Volume in drive C is HP_PAVILION
Volume Serial Number is 0200-EE0C
Directory of C:\temp
08/15/2010 09:15 PM 418 apples.class
08/15/2010 09:15 PM 123 apples.java
2 File(s) 541 bytes
0 Dir(s) 107,868,696,576 bytes free
C:\temp>java -cp . apples
Hello World!
C:\temp>
Your lack of understanding and the IDE appear to be impeding your progress. Do simple things without the IDE for a while until you get the hang of it. A command shell and a text editor will be sufficient.
Sorry about missing javac; cut & paste error.
If you look at the screenshot, your class name is there, last in the list. Select it and press OK. To not see this message again, right-click on the class name on the left side and select there Run...->Java Application.
The only problem that causes your error here is that the classname and the filename do not match - and they have to.
Solution
Rename either the file thesame.java to apple.java or the class to thesame. Then if you select "Run as..." again, eclipse will present a menu item to start your Java application.
(other mentioned, that there's no requirement that a top-level class and the filename do match - unless the top level class is public. Of course this is true. But the problem was about "running" a class under eclipse as a Java application)
Try public class apples and make sure the file is apples.java. Also it should be public static void main(String[] args)
You have 2 classes by name of "thesame.java" under the source folder. Since one is directly under the src folder, and other under (default package), they use the same namespace, hence Interpreter is confused which java file to execute and is asking you to select the class you want to execute.
Class names must be capitalized... so change apples to Apples. Also, if you are a beginner (which it seems like), I would recommend the Netbeans IDE -- it's a bit more friendlier for new users than Eclipse.
You class must be named "thesame" if you store it in a file called "thesame.java", as you have. Either rename your class to "thesame" or change the file to be "apples.java".
You should move the "[]" to be before "args". So, String[] args.
Either select "apples" at the bottom of the menu you posted and run it, or right-click on the Java file and make it the default thing to run for this project. Or launch it by right-clicking on the file and selecting "run".

Categories