well, i started generating my code through Textpad, and when i run it, it runs smoothly, but if i am to create the jar file through Netbeans, it becomes a disaster and returns a null error. i cant even figure out where the error is...

here is the part of the code

Container c = getContentPane();
	public PnTDesktop(final Connection con,final String userOnline)
	{
		final String[] args = new String[10];
		setTitle("The user Online is "+userOnline);
		
		Panel adminPanel = new Panel();

			JButton logoutButton = new JButton("Logout");


			adminPanel.setLayout(new BorderLayout());
			adminPanel.add(logoutButton,BorderLayout.CENTER);

			logoutButton.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent ae)
				{
					hide();
					PnTLogin goToLogin = new PnTLogin();
				}
			});

		Panel downloadPanel = new Panel();

			JButton mp3UploadButton = new JButton(mp3Icon);			

			downloadPanel.add(new JLabel("Download Selection"));
			downloadPanel.add(mp3UploadButton);			

			mp3UploadButton.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent ae)
				{						
					try
					{
						hide();
						BasicUploader startUploader = new BasicUploader(con,userOnline,"MP3");

					}catch(Exception myE)
					{
						ErrorFrame thisError = new ErrorFrame(myE,con,userOnline);
					}
			});

////////----------------------------------------------------///////////////

the class BasicUploader is as follows

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class BasicUploader extends JFrame
{
	Container c = getContentPane();

	public BasicUploader(final Connection con,final String userOnline,final String theUploadType)
	{
		final String[] args = new String[10];

		setTitle("Upload either USB or Infrared "+ theUploadType);
		Panel topPanel = new Panel();
			JLabel myTopDefiner = new JLabel();
			ImageIcon mybg = new ImageIcon(ClassLoader.getSystemResource(theUploadType+"Icon.jpg"));
			myTopDefiner.setIcon(mybg);

			topPanel.add(myTopDefiner);


		Panel mainPanel = new Panel();

			JButton usbUploadButton = new JButton("USB");
			JButton externalUploadButton = new JButton("External");

			mainPanel.add(new JLabel("Upload using either USB or External"));
			mainPanel.add(usbUploadButton);
			mainPanel.add(externalUploadButton);

		Panel bottomPanel = new Panel();

			JButton cancelButton = new JButton("Cancel");

			bottomPanel.add(cancelButton);

		c.setLayout(new BorderLayout());


		c.add(topPanel,BorderLayout.NORTH);
		c.add(mainPanel,BorderLayout.CENTER);
		c.add(bottomPanel,BorderLayout.SOUTH);


		usbUploadButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent ae)
			{
				String uploadMode ="usb";
				hide();
				
			}
		});

		externalUploadButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent ae)
			{
				String uploadMode ="external";
				hide();
				
			}
		});

		cancelButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent ae)
			{
				hide();
				
			}
		});

		setSize(600,600);
		setVisible(true);
	}
}

///////////////////--------------------------------------/////////////////////////////

so any one with any help please its urgent

  1. Please start using code tags, [code] YOUR CODE HERE [/code]
  2. Please provide exact error as received

One thing I see is

ImageIcon mybg = new ImageIcon(ClassLoader.getSystemResource(theUploadType+"Icon.jpg"));

Is this "Icon" contained inside the jarfile?

If so, you cannot use this form of the constructor.

You will want to use getResourceAsStream together with ImageIO.read(InputStream) to create a BufferedImage, then ImageIcon(Image) constructor.

not yet there. what do you mean? give me an example. because i think the buffering of an image is not the problem, but elsewhere, but it is something to look into. just help me out with the code for such a call

What I mean, is that if your "Icon" is inside of the jarfile, you can't access it using that form of the constructor. That form of the constructor can only be used if the "Icon" is a regular file, and inside of a jarfile, that is no longer the case.

i asked example. because i now only this method for calling all of my images, so if you could show me the way, then i think that will be beneficial

InputStream is = getClass().getResourceAsStream(theUploadType+"Icon.jpg"));
BufferedImage bi = ImageIO.read(is);
is.close();
ImageIcon mybg = new ImageIcon(bi);

Now, what was so hard to understand about

You will want to use getResourceAsStream together with ImageIO.read(InputStream) to create a BufferedImage, then ImageIcon(Image) constructor

Does not the code above, follow exactly the process detailed below it, and in my previous post?

Was it sooo hard to at least read the API for the specific methods and Classes referenced that you just, absolutely could not manage to at least attempt it yourself?

Edit: P.S. There is absolutely no error handling in that "example", so you will have to do at least something yourself.

okay, dearest if my problems seem to be a problem, then i do believe that it will be in my best interest not to do so again. Really i am sorry if my problem nagged you a little bit.

What "bothered" me, is that you didn't even attempt it. I have no problem what-so-ever with someone coming here and saying help me, this is what I tried, can you tell me what else to try.

That's what you did, at first. But, then I told you what to try, and you, essentially, said "I've never done that before (as if we didn't know that), and I don't what to bother myself to follow your instructions, just do it for me."

That, I have no patience for. And don't say you didn't say that, since there is no way to give an example on such a specific process without, essentially, doing it for you.

Well Mr or Mrs, that idea did not solve the problem, still the null error appears.

Anyway thanks for your contribution

No need to be ungrateful, besides masijade warned you that implementation of error handling required.

Well Mr or Mrs, that idea did not solve the problem, still the null error appears.

Anyway thanks for your contribution

Like I said, I didn't know if that was the problem that was causing a "null error", but that it was a problem that needed to be fix, if your "Icons" were inside the jarfile.

As far as your "null error" problem goes, it might help if you posted exactly which line the error occurs on, as well as the complete stacktrace of the error.

Edit: And if it is a null pointer error, the exception will tell you exactly where it occurred. Change that catch block to provide a stacktrace, as well.

guys, i have found the prob, the thing is my code was failing to pick up the cases of my images naming, e.g. i had mp3Icon.jpg, but i would call it up as MP3Icon.jpg.

In the runtime environment it will work well, since they will be read the same, but it is not the same in the jar runtime environment.

anyway guys thanks

No, on windows it works (at least when FAT32 is used, with NTFS, I don't know), it wouldn't work that way on nearly any other system.

sorry to inform you on this, but i am coding on a windows XP ntfs system, and it is running, what is the fuss all about, dude, its cool. i showed you the reason why that error comes up. its okay.

To tell you that you should be careful of that all the time. Java is case-sensitive, when the OSes File System is not, it can lead to some compatability problems with other systems, or simply other execution plans (jar vs. directory). You've gotten bit by it once already, maybe you'll learn for next time.

its cool, believe me i now understand about case sensitiveness, somehow, the IDE ran it without the case sensitivity, so i now understand.

Now you sound more than a human being than last time, did you get a girlfriend or something?? just kidding.

commented: Perhaps you should consider your own attitude when you are requesting help from others. -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.