• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Java experts... what's up?

Status
Not open for further replies.
Hey guys... been a while since I did anyhting significant in Java and I've been using Python lately, so I think that explains why I'm having trouble...

Can anyone tell me why this code throws a null pointer exception?

Code:
String[][] newgrid = new String[13][9]; 

for (int x=0;x<13;x++){
	for (int y=0;y<9;y++){
		grid[x][y]=".";
	}
}

If I manually set the coords, it works fine--but it fails on grid[0][0] if the variables are supplied by the for loop...


EDIT: I feel like an idiot... :)
 

Phoenix

Member
EDIT: That actually won't compile. newgrid != grid

Noticed the hard define in ="."

After fixing compiler bug, works fine for me.
 

Phoenix

Member
Code:
public class Foo
{
	public static void main( String[] args )
	{
		String[][] newgrid = new String[13][9]; 
		
		for (int x=0;x<13;x++){
				for (int y=0;y<9;y++){
						newgrid[x][y]=".";
				}
		}	

		for (int x=0;x<13;x++){
				for (int y=0;y<9;y++){
						System.out.print(newgrid[x][y]);
				}
				
				System.out.println(" |");
		}		
		
	}
}


Works for me. What you making? Minesweeper clone?
 

Ghost

Chili Con Carnage!
Do you guys have any fancy editors for jave your are you just using textpad and stuff?

Id try to help but ive reached my recognised java limit of 15 hours a day.

I did the usual:

-Think of a way to do what i had to do
-Program it, compiles.
-Doesnt work
-spend 4 hours trying other ways to do it, none of which do what i want
-try the original way one last time as a last ditch before hanging self
-works fine
-scream
 

Phoenix

Member
Ghost said:
Do you guys have any fancy editors for jave your are you just using textpad and stuff?

Id try to help but ive reached my recognised java limit of 15 hours a day.

I did the usual:

-Think of a way to do what i had to do
-Program it, compiles.
-Doesnt work
-spend 4 hours trying other ways to do it, none of which do what i want
-try the original way one last time as a last ditch before hanging self
-works fine
-scream


Writing Java code without a modern IDE is like sleeping nude in bed with Tyra Banks, Vivica Fox, and Gabrielle Union and not doing anything - yeah you could do it, but why in God's name would you?

Go grab a copy of Eclipse from eclipse.org or Netbeans from netbeans.org at the very least.

FOr small stuff like this I just open BBEdit and javac from the commandline.
 

Slo

Member
At work I use Eclipse 3.0. We had Borlands' editor for like $1000 a chair, but we ditched it in favor of Eclipse and I like it a lot.
 

Phoenix

Member
Slo said:
At work I use Eclipse 3.0. We had Borlands' editor for like $1000 a chair, but we ditched it in favor of Eclipse and I like it a lot.

I use IntelliJ professionally. It doesn't get any better than that... no matter how much you spend :)
 

Ghost

Chili Con Carnage!
I put a gypsy curse on netbeans last year because it KEPT CHANGING MY CODE, i'll try eclipse though.
 

Phoenix

Member
Ghost said:
I put a gypsy curse on netbeans last year because it KEPT CHANGING MY CODE, i'll try eclipse though.

Netbeans used so suck many flavors of ass, but its gotten better in its latest (pre release) revision.
 

Chrono

Banned
Ok... what does an IDE do?

I'm a n00b at this-- I only took one programming (intro to java) class last summer and I don't remember much now. All I used was TextPad and it was helpful in coloring methods, classes, and stuff like that. Its' probably because we didn't learn much that we did not use an IDE but I'm still curious how an IDE helps you program better... I mean 1000 dollars is just… o_O
 

Ecrofirt

Member
the IDE is your development package.

It's the editor and compiler and debugger.

alternatively, you could code in notepad, and compile and run in DOS.
 

Ecrofirt

Member
Since we're talknig Java, can you compile Java stuff down into executables? We never covered anything like this in my Java class.

Can you do it with Eclipse?
 
Phoenix said:
Works for me. What you making? Minesweeper clone?

I realized my problem right after I posted this... :D

I'm building a game for elementary kids using Eclipse and the visual editor plugin... It's a combination strategy/answer the question game...

mockup1.png


That's a mockup I did a few weeks ago for fun, and the actual project looks better than that, thanks to fancy Java PNG support...

The War on Terror won't be what the game is called when it's finished :lol

and BTW... I use JCreator LE for simple Java tasks
 

Phoenix

Member
Ecrofirt said:
Since we're talknig Java, can you compile Java stuff down into executables? We never covered anything like this in my Java class.

Can you do it with Eclipse?

Yep, you sure can. There are a wide variety of programs (many open source) out there that will compile the java code into an actual executable. There are some (lamer) ones that do this by embedding a JVM into the compiled application, and some that actually statically compile the application (like gcj). Most modern Java application don't benefit much from actually being compiled however.
 

alejob

Member
Ecrofirt said:
the IDE is your development package.

It's the editor and compiler and debugger.

alternatively, you could code in notepad, and compile and run in DOS.

If I've been tought correctly, the IDE is just the environment, which does NOT include the compiler and debugger.
 

Phoenix

Member
alejob said:
If I've been tought correctly, the IDE is just the environment, which does NOT include the compiler and debugger.

It should. The I in IDE stands for "integrated" and it would be pretty lame if the compiler and debugger weren't integrated into the thing you were developing with.
 
alejob said:
If I've been tought correctly, the IDE is just the environment, which does NOT include the compiler and debugger.

If that's true by definition, it usually isn't in practice. Every IDE I've ever used has had it all together... that's why it's an integrated dev environment...
 

Ecrofirt

Member
Phoenix said:
Yep, you sure can. There are a wide variety of programs (many open source) out there that will compile the java code into an actual executable. There are some (lamer) ones that do this by embedding a JVM into the compiled application, and some that actually statically compile the application (like gcj). Most modern Java application don't benefit much from actually being compiled however.


Anything in particular you'd recommend? Being able to distribute .exe's of my stuff would be great.
 

Phoenix

Member
Ecrofirt said:
Anything in particular you'd recommend? Being able to distribute .exe's of my stuff would be great.


I would personally use Excelsior JET, but it ain't free :(

Source


I have talked to plenty of people using JET including a few Java game developers who swear by it.



For free you won't get any better than GCJ (portability wise)

Source


But like I said, I have never head anyone use JET and then try to use ANYTHING else :)
 

alejob

Member
Well, I've also noticed that people have different definitions for a lot of stuff.

Anyway, Netbeans is an IDE but it uses the JDK, you have to set environment variables for it. I suspect other JAVA IDEs are the same.


Now that we are talking about .exes, I went through an entire Power Builder class and we never learned how to make the executable files. We just hit run on the compiler to see it running. The profesor even tested it like that.
 

Phoenix

Member
alejob said:
Well, I've also noticed that people have different definitions for a lot of stuff.

Anyway, Netbeans is an IDE but it uses the JDK, you have to set environment variables for it. I suspect other JAVA IDEs are the same.


Now that we are talking about .exes, I went through an entire Power Builder class and we never learned how to make the executable files. We just hit run on the compiler to see it running. The profesor even tested it like that.


Java programs are most often not actually compiled into native platform executables (kinda defeats the purpose of making the bytecode crossplatform). Generally you compress everything into a double clickable .jar file or use one of the bagillion Java installers that will create a native launcher app that will start the cross platform Java code. Most people who do compile to native code fall into 2 categories:

a) they mistakingly believe that compiling the code will magically make the application faster (which is false in 90% of cases)

b) they didn't realize that they could use an installer or webstart to make the regular .jar file launch just like a program on the native platform
 

alejob

Member
Phoenix said:
Java programs are most often not actually compiled into native platform executables (kinda defeats the purpose of making the bytecode crossplatform). Generally you compress everything into a double clickable .jar file or use one of the bagillion Java installers that will create a native launcher app that will start the cross platform Java code. Most people who do compile to native code fall into 2 categories:

a) they mistakingly believe that compiling the code will magically make the application faster (which is false in 90% of cases)

b) they didn't realize that they could use an installer or webstart to make the regular .jar file launch just like a program on the native platform

Good to know but I was talking about Power Builder not Java.
 

rastex

Banned
I've heard nothing but great things about IntelliJ. My friend used it for a job once and has been praising it for the past 3 years anytime dev environments come up. Conversely he insults Eclipse in the same breath. Eclipse 2 was CRAP, and Eclipse3 is a bit better, it's just very unfriendly to use. If you know how to use Eclipse then it can do a lot of really nice things for you, but all of it is hidden and just laid out very poorly and difficult to find, so for noobs it's very frustrating.
 

iapetus

Scary Euro Man
Phoenix said:
I use IntelliJ professionally. It doesn't get any better than that... no matter how much you spend :)

Amen. I used Eclipse at my last job, and IntelliJ at the new one, and it's night and day. Don't get me wrong, Eclipse is nice, and has a lot of cool features. But IntelliJ kicks its ass in just about every way you can imagine apart from the price tag. :)
 

Ecrofirt

Member
Pheonix, how do you go about creating the .jar file? I know you can make them *somehow*, but we've never discussed it in my Java class.
 

Phoenix

Member
Ecrofirt said:
Pheonix, how do you go about creating the .jar file? I know you can make them *somehow*, but we've never discussed it in my Java class.

You can go to the command line and type 'jar' and it will give you all the details. In general its 'jar -cvf foo.jar {list of jars or directories}'. To make one that is double clickable you need to add a manifest file that defines the Main-Class element.

You can get all the details of jar files here:

http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html
 

Phoenix

Member
Ecrofirt said:
odd, typing jar gives me an unrecognized error.

Find out what directory javac is in, there should be a command 'jar' in the same place. Perhaps its not in your path or your JavaSDK install is screwed up somehow.
 

Ecrofirt

Member
well, I've got the 1.4.1 SDK, and jar is in there.

ah, do I have to be in that folder to get jar to work, I wonder? I don't usually do the java stuff from the command line.

OK, i've got the jar working.

I'm not understanding the manifest file stuff at the sun site, however. If you have a simple working one, is there any way uou could paste it in here?
 

Azih

Member
putting the java sdk folder in your path is highly recommended, makes the console commands much easier to do.
 
Status
Not open for further replies.
Top Bottom