Hello guys. I just wrote my first java program and i have a couple of
questions and a problem. I would be glad if someone can give me a
hand.
The questions :
1. How do i pack everything into i nice executable file for others
to run without the need to open a cmd prompt and typing java ... and
so on ?
2. How do you guys do when your looking for a command. Is there some
kind of registry online, or do you have books or do you just know it
all from the getgo :) ?
The problem is that, while the compailer doesn't complain, i still get
an error at runtime. The error staits
Exception in thread "main" java.lang.NullPointerException
at DiveLog.DiveLog.populateMettoMenu(DiveLog.java:76)
at DiveLog.DiveLog.<init>(DiveLog.java:38)
at DiveLog.DiveLog.main(DiveLog.java:15)
Press any key to continue . . .
and i cant get the program running.
The source looks like this
package DiveLog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Metto
{
private JFrame mettoFrame;
private JTabbedPane mettoPane;
public static void main(String[] args)
{
Metto go = new Metto();
}
public Metto()
{
JFrame mettoFrame = new JFrame("Metto ligger långt efter");
mettoFrame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
mettoPane = new JTabbedPane(SwingConstants.RIGHT);
mettoPane.setBackground(Color.blue);
mettoPane.setForeground(Color.white);
populateMettoPane();
populateMettoMenu();
mettoFrame.getContentPane().add(mettoPane);
mettoFrame.pack();
mettoFrame.setSize(750, 650);
mettoFrame.setBackground(Color.white);
mettoFrame.setVisible(true);
}
private void populateMettoPane()
{
mettoPane.addTab("Tryck här",
null,
new press1(),
"Det här va inte så svårt");
mettoPane.addTab("Eller här",
null,
new press2(),
"Inte det här häller");
}
private void populateMettoMenu()
{
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
item.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
menu.add(item);
mb.add(menu);
mettoFrame.setJMenuBar(mb);
}
public class press1 extends JPanel
{
}
public class press2 extends JPanel
{
}
}
Thx in advance for any help you guys can give me. Mohamed Haidar.
Donkey Hot - 27 Dec 2007 14:06 GMT
mohed.haidar@gmail.com wrote in news:05e9ea93-a409-4198-8b38-13b6d587cb61
@v4g2000hsf.googlegroups.com:
> Hello guys. I just wrote my first java program and i have a couple of
> questions and a problem. I would be glad if someone can give me a
[quoted text clipped - 107 lines]
>
> Thx in advance for any help you guys can give me. Mohamed Haidar.
You have declared variable "mettoFrame" twice, once as a property in
class, and then a local variable in the constructor Metto(). You do not
create the class member mettoFrame, but try to use it in
populateMettoMenu().
Netbeans IDE told this as soon as loaded the source in it.
Vince - 27 Dec 2007 14:13 GMT
> Hello guys. I just wrote my first java program and i have a couple of
> questions and a problem. I would be glad if someone can give me a
[quoted text clipped - 4 lines]
> to run without the need to open a cmd prompt and typing java ... and
> so on ?
Check out how t create a JAR file as example
> 2. How do you guys do when your looking for a command. Is there some
> kind of registry online, or do you have books or do you just know it
> all from the getgo :) ?
You'll find everything you need at java.sun.com.
> The problem is that, while the compailer doesn't complain, i still get
> an error at runtime. The error staits
[quoted text clipped - 6 lines]
>
> and i cant get the program running.
The compiler tells you that you've got a runtime error at line 76
(populateMettoMenu). The NullPointer means basically that at one stage
you try to use the content of an object that is NULL. Basically if there
is no value to use, the program will fail... Check that your object's
really a content and then it will work..
> The source looks like this
>
[quoted text clipped - 84 lines]
>
> Thx in advance for any help you guys can give me. Mohamed Haidar.

Signature
Posted via a free Usenet account from http://www.teranews.com
lord.zoltar@gmail.com - 27 Dec 2007 14:34 GMT
On Dec 27, 8:53 am, mohed.hai...@gmail.com wrote:
> Hello guys. I just wrote my first java program and i have a couple of
> questions and a problem. I would be glad if someone can give me a
[quoted text clipped - 4 lines]
> to run without the need to open a cmd prompt and typing java ... and
> so on ?
Package it in a JAR file. Learning at least the basics about JAR files
is pretty important for Java development.
A co-worker of mine would often use JSmooth to create an executable
wrapper, but I think you still need to create a JAR file as the input
for JSmooth.
Karl - 27 Dec 2007 20:56 GMT
> On Dec 27, 8:53 am, mohed.hai...@gmail.com wrote:
>> Hello guys. I just wrote my first java program and i have a couple of
[quoted text clipped - 11 lines]
> wrapper, but I think you still need to create a JAR file as the input
> for JSmooth.
Yes, and if you want it to start with a double click, consider creating a
Windows shortcut with the Java command line in it. If you want to hide the
DOS console, use javaw.exe instead of java.exe in your command line.
Andrew Thompson - 27 Dec 2007 16:44 GMT
>Hello guys. I just wrote my first java program and i have a couple of
>questions and a problem. I would be glad if someone can give me a
[quoted text clipped - 4 lines]
>to run without the need to open a cmd prompt and typing java ... and
>so on ?
As two other people have mentioned, the first step is
to put it in a Jar archive.
But that is not enough in itself, to make a 'double click -
launch' file. To provide that level of convenience, you will
need to either..
a) Provide a manifest file in the Jar that sepcifies the main class.
b) Launch the app. using Java Web Start, and suggest (via
the JNLP file) desktop shortcuts or menu items.
>Thx in advance for any help you guys can give me. Mohamed Haidar.
Thanks in future for taking care to spell words fully.
That word is 'Thanks', not 'Thx' (which I think is a
proprietary sound system/format.). Note also that
the word 'I' should *always* be upper case - no matter
where it occurs in a sentence.

Signature
Andrew Thompson
http://www.physci.org/
Vince - 27 Dec 2007 17:24 GMT
> Thanks in future for taking care to spell words fully.
> That word is 'Thanks', not 'Thx' (which I think is a
> proprietary sound system/format.). Note also that
> the word 'I' should *always* be upper case - no matter
> where it occurs in a sentence.
Thanks posting comments like that in alt.english.usage :-) Without any
animosity though!

Signature
Posted via a free Usenet account from http://www.teranews.com
Mark Space - 27 Dec 2007 19:19 GMT
> Thanks posting comments like that in alt.english.usage :-) Without any
> animosity though!
I disagree. While the point about animosity is usually well taken, this
was one of Andrews milder post. And grammar and spelling are relevant
to c.l.j.p. It's how we all communicate -- our "protocol" if you will.
I don't want to see this group devolve into a mess of miss-spellings,
leet-speak, chat shorthand and general bastardization of the English
language. The only people who get a break are non-English speakers.
The rest should know better.
Vince - 28 Dec 2007 01:33 GMT
>> Thanks posting comments like that in alt.english.usage :-) Without any
>> animosity though!
[quoted text clipped - 5 lines]
> leet-speak, chat shorthand and general bastardization of the English
> language.
I fully agree with you on this one...
> The only people who get a break are non-English speakers. The
> rest should know better.
That's the point, have you seen the name of the original poster. Mohed
Haidar, most probably a non native English speaker that - using your
words - should be allowed to get a break...

Signature
Posted via a free Usenet account from http://www.teranews.com
Andrew Thompson - 28 Dec 2007 02:25 GMT
>>> Thanks posting comments like that in alt.english.usage :-) Without any
>>> animosity though!
There was none intended.
>That's the point, have you seen the name of the original poster.
Yes, I did. ..
>..Mohed Haidar, ..
.. I also noted that the OP capitalised the instances
of the word 'I' that led sentences, but not other
occurrences. That in turn, led to to suspect that
while they were not entirely familiar with English, they
were doing their best to communicate their message.
As such, I felt they might like that tip.
>... most probably a non native English speaker that - using your
>words ..
'Thx' is not English. Other people that are (perhaps like the
OP) not native speakers, would have more trouble understanding
what leet speak words like 'thx' mean, than the properly spelt
'thanks'. If you pop over to Google* and do a search on thx,
what is the first thing that comes up? (hint: I alluded to it in
my initial post).
* <http://www.google.com/search?as_q=thx>
> ..- should be allowed to get a break...
And on that subject, how about *you* give posters a 'break'
in future, by (politely) giving them tips that will help them
to communicate more effectively on this (English based) forum?
It is all in your perspective. You seem to feel I was somehow
'rude' in my initial comments.
I suggest you deal with that, because I feel it is entirely
appropriate and helpful to discuss the best ways to
communicate, and I see no advantage to anybody, in
altering my response to these situations.

Signature
Andrew Thompson
http://www.physci.org/
Vince - 28 Dec 2007 02:43 GMT
>>>> Thanks posting comments like that in alt.english.usage :-) Without any
>>>> animosity though!
>
> There was none intended.
I meant my comment was without animosity, sorry for the misunderstanding...
> It is all in your perspective. You seem to feel I was somehow
> 'rude' in my initial comments.
No I didn't percept your comment as rude, I was just following your
postings - with great respect to your constructive contributions - and
realized that - by guess - you mention the capital 'I' every 3rd time...
Thus I thought you may be interested that there is an interesting group
focusing on things like that...
> and I see no advantage to anybody, in
> altering my response to these situations.
Me neither, except that it looks like Don Quichote fighting against mills...
Anyway, no big deal about that.. peace...

Signature
Posted via a free Usenet account from http://www.teranews.com
Andrew Thompson - 28 Dec 2007 03:01 GMT
>>>>> Thanks posting comments like that in alt.english.usage :-) Without any
>>>>> animosity though!
>>
>> There was none intended.
>
>I meant my comment was without animosity, sorry for the misunderstanding...
After all this discussion about 'clear and effective
communication' I have to concede that I read too
much into your initial (clear) words. My bad.
...
>> ...I see no advantage to anybody, in
>> altering my response to these situations.
>
>Me neither, except that it looks like Don Quichote fighting against mills...
;-) Perhaps. But 'different folks/different strokes/
different approaches'. In a vibrant community (with
lots of different opinions and approaches), almost
anything is good.
>Anyway, no big deal about that.. peace...
:-)

Signature
Andrew Thompson
http://www.physci.org/
tim@nocomment.com - 28 Dec 2007 03:10 GMT
> > Thanks posting comments like that in alt.english.usage :-) Without any
> > animosity though!
[quoted text clipped - 6 lines]
> language. The only people who get a break are non-English speakers.
> The rest should know better.
Who died and left you king?
Brandon McCombs - 30 Dec 2007 18:56 GMT
>> Hello guys. I just wrote my first java program and i have a couple of
>> questions and a problem. I would be glad if someone can give me a
[quoted text clipped - 20 lines]
> That word is 'Thanks', not 'Thx' (which I think is a
> proprietary sound system/format.). Note also that
Actually 'Thx' is an abbreviation for 'Thanks', whether officially or
not I don't know. 'THX' is the proprietary sound format from George
Lucas' Film Studio.
> the word 'I' should *always* be upper case - no matter
> where it occurs in a sentence.
Lew - 30 Dec 2007 20:14 GMT
> 'THX' is the proprietary sound format from George
> Lucas' Film Studio.
Named after his first film, /THX 1138/.

Signature
Lew
Mark Space - 27 Dec 2007 19:32 GMT
> Hello guys. I just wrote my first java program and i have a couple of
> questions and a problem. I would be glad if someone can give me a
> hand.
As someone else alluded to, the real answer here is to download and use
a decent IDE like NetBeans. While trying to do things by hand is a
commendable learning exercise, it's not really practical. A good IDE
will be your best friend.
http://download.netbeans.org/netbeans/6.0/final/
You want the download all the way on the right, under the column that
says "All."
> 2. How do you guys do when your looking for a command. Is there some
> kind of registry online, or do you have books or do you just know it
> all from the getgo :) ?
We have it surgically implanted at birth by the Hive Over-Mind.
Seriously, we read books and online tutorials. Online magazines and
trade magazines are also good -- it's important to have a conduit for
learning new things, not just learning something once and then assuming
we know it all. (Although, the jar command is hardly new.)
For new people, I recommend O'Reilly's book Learning Java. The latest
edition is 3rd, I think. Learning Java explains the command line
utilities and much more. It's a very complete introduction to the language.
I also recommend looking a Sun's tutorials online. Sun updates those
periodically so you are almost always looking at the best and latest
information.
http://java.sun.com/docs/books/tutorial/
Also, the Javapassion web site has a free online class to take on Java.
It's tough for a true beginner but if you are coding already I think
you could handle it easily. The class does introduce the command line
tools and makes heavy use of the jar command. However the class does
use Netbeans primarily, which I think is best since a good IDE is essential.
http://www.javapassion.com/javaintro/
Arne Vajhøj - 27 Dec 2007 23:25 GMT
> As someone else alluded to, the real answer here is to download and use
> a decent IDE like NetBeans. While trying to do things by hand is a
> commendable learning exercise, it's not really practical. A good IDE
> will be your best friend.
It is much easier using an IDE. But it is part of understanding
Java development to understand what the IDE does behind the scene.
And that is hard to learn without having to work with command line
tools, directories and classpath etc..
Arne
Andrew Thompson - 28 Dec 2007 00:38 GMT
>> As someone else alluded to, the real answer here is to download and use
>> a decent IDE like NetBeans. While trying to do things by hand is a
[quoted text clipped - 3 lines]
>It is much easier using an IDE. But it is part of understanding
>Java development to understand what the IDE does behind the scene.
This is where Ant comes into its own. The Ant tasks
related to Java development are very easy to map between
command line arguments and task options.
While Ant build files can be run from the command line,
sans IDE, most IDEs can also load and work with (invoke
etc.) Ant scripts.
>And that is hard to learn without having to work with command line
>tools, directories and classpath etc..
I think it is important for developers to understand this
type of stuff. Many questions that start with "How do I
make my IDE...?" would already be answered if the
questioner had better knowledge of the underlying
SDK tools.

Signature
Andrew Thompson
http://www.physci.org/
Tim Smith - 28 Dec 2007 11:13 GMT
> As someone else alluded to, the real answer here is to download and use
> a decent IDE like NetBeans. While trying to do things by hand is a
> commendable learning exercise, it's not really practical. A good IDE
> will be your best friend.
Typing "javac Foo.java" to compile, and "java Foo" to run a program is
not practical?

Signature
--Tim Smith
Mark Space - 28 Dec 2007 16:31 GMT
> Typing "javac Foo.java" to compile, and "java Foo" to run a program is
> not practical?
No. Not even slightly. Ant is a big step up from typing javac each
time you want to compile something, but a good IDE does far more than that.
Roedy Green - 28 Dec 2007 13:44 GMT
> 1. How do i pack everything into i nice executable file for others
>to run without the need to open a cmd prompt and typing java ... and
>so on ?
1. give them a jar. See http://mindprod.com/jgloss/jar.html
2. natively compile. see
http://mindprod.com/jgloss/nativecompiler.html
3. use an installer. see
http://mindprod.com/jgloss/installer.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Roedy Green - 28 Dec 2007 13:45 GMT
> 2. How do you guys do when your looking for a command. Is there some
>kind of registry online, or do you have books or do you just know it
>all from the getgo :) ?
I use Copernic to search my local hard disk source and JavaDoc.
see http://mindprod.com/jgloss/copernic.html
Also check out http://mindprod.com/jgloss/jgloss.html
You can look up words and follow links. The entries are often linked
to even more detailed info. My essays are aimed at the newbie.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Mohammad Abou-Basha - 30 Dec 2007 04:05 GMT
Check that page for the jar thing
http://www.wikicodia.com/wiki/Java_Create_executable_jar_file
On Dec 27, 3:53 pm, mohed.hai...@gmail.com wrote:
> Hello guys. I just wrote my first java program and i have a couple of
> questions and a problem. I would be glad if someone can give me a
[quoted text clipped - 107 lines]
>
> Thx in advance for any help you guys can give me. Mohamed Haidar.