8

I keep getting this message in BlueJ/Java.

http://cache.gyazo.com/19c325e77bbc120892d1035dcfda5377.png

I know there are several other questions like this already on StackOverflow, but none of the answers were specific enough for me, a Java noob. For example, one of them said to add something on the javac command line," and I have no idea what is that. So use that information to know how specific you must be with me. Sorry. Thanks!

viggom555
  • 101
  • 1
  • 1
  • 5
  • Try this in command line `javac -Xlint:unchecked MyProgram.java`. Also see `javac -X` for help. – RanRag May 30 '12 at 20:31
  • @RanRag Like I said, I don't know what is the command line. – viggom555 May 30 '12 at 20:33
  • I looked at the [BlueJ/Java documentation](http://www.bluej.org/doc/bluej-ref-manual.pdf) and I don't see any way to specify command line options from the BlueJ IDE. Frankly, I'd suggest learning command-line Java. And/or learning a different IDE (like NetBeans or Eclipse). Both IDEs give you much greater control than BlueJ... IMHO... – paulsm4 May 30 '12 at 20:37
  • *facepalm* - You might have to Google some things for the sake of conciseness. – user845279 May 30 '12 at 20:38
  • @user845279 I did but, like I said, I don't understand Java vernacular and don't know what the articles on that are talking about. – viggom555 May 30 '12 at 20:51
  • In ant, place it here: ... – russellhoff Apr 22 '15 at 15:00

3 Answers3

5

open up command prompt in the directory with your source files. then type javac -Xlint:unchecked *.java

Epicblood
  • 1,099
  • 2
  • 10
  • 29
  • How do I specify the location in the command prompt? You DO mean typing in after the default text the location of the class's source files and then typing what you said, right? – viggom555 May 30 '12 at 20:50
  • when you start command prompt type `cd "C:\path\to\your\source\folder\"` – Epicblood May 30 '12 at 21:09
  • http://cache.gyazo.com/aaac8d3b879a92f38610a0716187767a.png That's what happened. "CompSci 1" is the folder containing the source files (classes and everything else). – viggom555 May 30 '12 at 21:18
  • have you installed the java JDK? http://www.oracle.com/technetwork/java/javase/downloads/index.html – Epicblood May 30 '12 at 21:23
  • also, there should be a space before the *.java – Epicblood May 30 '12 at 21:24
  • Still this message. I assume I've installed the JDK but will try anyways http://cache.gyazo.com/75e8810cd9f285c4a5dbfb7043d29453.png – viggom555 May 30 '12 at 21:38
  • You need to add the java binaries folder to your environment path, see [this](http://docs.oracle.com/javase/tutorial/essential/environment/paths.html). – user845279 May 30 '12 at 21:40
  • You need to use [generics](http://en.wikipedia.org/wiki/Generics_in_Java) to avoid that error. For example, `ArrayList list = new ArrayList(); String a = list.get(0);` You are probably getting unsafe cast error because of converting a return of Object type to another class. – user845279 May 30 '12 at 22:05
  • Ah. That is probably it, since the compiler prompted me to cast the list.get(x) as an int or whatever I was using as, and I knew there was something with < and > when creating the list, but I didn't know how to do it. I'll try that and if it works, you'll get the correct answer. – viggom555 May 30 '12 at 22:09
  • Okay I added in those identifiers and removed the castings, but I still get the same message. Here's a test class. http://cache.gyazo.com/eb88614b140a88b16579f01fb5e099d6.png In that, I don't receive the message, but it won't compile. Also, why can't I cast as an int an arraylist? – viggom555 May 30 '12 at 22:17
  • Then the problem is probably not with ArrayList. Your last question didn't make sense. If you'd like to do the same for `int` values, you have to do `ArrayList list = new ArrayList();list.add(5);int a = list.get(0);` You should probably post another question by showing more code. This is no longer a Bluej issue. – user845279 May 31 '12 at 00:08
3

Please refer to the BlueJ FAQ which has the exact answer.

Edit: Sorry for the runaround. This is what the FAQ says for Windows. Go to your Bluej installation directory and open lib\bluej.defs file. Then go to the section that says bluej.windows.vm.args and add the value the other user said.

So you have:

bluej.windows.vm.args=-Xlint:unchecked

I would listen to paulsm4's advice and start learning from command-line if you really want to understand java. This is the best I can do.

user845279
  • 2,755
  • 1
  • 15
  • 36
  • That looks complicated and, since I don't know much about Java, I can't really understand the vernacular with which that entry was written. – viggom555 May 30 '12 at 20:49
  • Unfortunately, it is the right answer. The command-line answer you've gotten isn't get any easier if have packages. – user845279 May 30 '12 at 20:54
  • Could you clarify the end of that comment? I don't get what you mean. Also, I'll give you the correct answer'n'shit if you just tell me how to do it. – viggom555 May 30 '12 at 20:56
  • 1
    @viggom555 I believe Joris Bolsens has the correct answer but I feel bad for you. – user845279 May 30 '12 at 21:17
  • Yeah I think he has the correct one too, and that's why I'm resorting more to his assistance. – viggom555 May 30 '12 at 21:22
  • Thanks, but I made the addition and am still getting the message. Recall that it said to add in that "for details." What does that mean? Where can I find said details? – viggom555 May 30 '12 at 21:36
  • You should not have the '#' in the beginning of the line. Also, are you using Windows machine? – user845279 May 30 '12 at 21:41
  • What picture are you talking about? I haven't linked anything in this subanswer discussion. And yes, Windows 7. – viggom555 May 30 '12 at 21:55
  • I was saying the line `bluej.windows.vm.args=-Xlint:unchecked` should not have a '#' in the beginning but nvm. – user845279 May 30 '12 at 22:00
  • Oh. Well when I removed the hashtag, BlueJ wouldn't open. I had to add it back in. – viggom555 May 30 '12 at 22:08
2

@viggom555:

Here is a complete command line example:

1) Create the file "ATest.java" (EXAMPLE: notepad ATest.java):

import java.util.*;

public class ATest {

  public static void main (String[] args) {
    ArrayList<String> test = new ArrayList<String>();
    System.out.println ("My array has " + test.size() + " items");
    test.add ("abc");
    System.out.println ("My array has " + test.size() + " items");
  }

}

2) Compile (EXAMPLE: "javac -Xlint:unchecked ATest.java"; you don't really need the "XLint" in this example; I'm just showing you where it would go if you wanted):

C:\temp>javac -Xlint:unchecked ATest.java

3) Run the test program:

C:\temp>java ATest
My array has 0 items
My array has 1 items

I hope that helps .. PSM

paulsm4
  • 99,714
  • 15
  • 125
  • 160