masijade 1,351 Industrious Poster Team Colleague Featured Poster

remove the "int" and/or "double" now, from the call to the method. You include types when defining and declaring the methods. You include only values when calling the methods.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You declare "throws Exception" in the declaration of the method, but when you use the method you are catching "STAFException". If "STAFException" is the exception that might be thrown by your method, then you need to declare "throws STAFException" and not "throws Exception". If you do use "throws Exception" then you need to use catch "Exception" when you use the method.

It's as simple as that. You need to "catch" what you "throw". Exactly what you throw (or more (not less) general). I.E. When you declare to throw IOException, you can catch Exception, but not FileNotFoundException (P.S. FileNotFoundException extends IOException which extends Exception).

Edit: a bit slow.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Regardless of the amount of input parameters use PreparedStatement. What if getParameter on USER return ';delete * from FMC_EMPLOYMENT;-- ? Or, more innocently, either one contains a simple "single quote" (')? PreparedStatement will prevent this sort of thing. It is not perfect in preventing SQL injection attacks, but it definately helps.

As far as the errors, then "req" is not defined in this scope.
And you forgot a quote (") at the end of the statement, before the closing paren. (And you forgot a plus (+) between the get parameter and that closing string.)

You need to look at your code more carefully.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Uhm, forget a quote (") before SELECT?

P.S. Use PreparedStatement.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Try using the GridBagLayout colWeights and rowWeights arrays, rather than assigning per item. I haven't lloked closely, but I already see a weighty of 1.0 on row 0 and 1 and a 0.1 on row 2, that means you are attemtping to use 210% of the space. Just because you are giving those values to a single component, they apply to the entire row, not just the component. That means it is easier, less error-prone, and more effective to simply set weightx and y to 0.0 and use the Layout's arrays. Try that first (as shown in the example).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Study this

package test;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class BogusGridTest {

	private static void doIt() {
		JFrame.setDefaultLookAndFeelDecorated(false);

		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JMenuBar mb = new JMenuBar();
		mb.add(new JMenu("File"));
		frame.setJMenuBar(mb);

		GridBagLayout gbl = new GridBagLayout();
		GridBagConstraints gbc = new GridBagConstraints();
		frame.getContentPane().setLayout(gbl);

		gbl.columnWeights = new double[] { 0.7, 0.3 };
		gbl.rowWeights = new double[] { 0.1, 0.7, 0.2 };

		gbc.anchor = GridBagConstraints.CENTER;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.gridheight = 1;
		gbc.gridwidth = 1;
		gbc.insets = new Insets(1, 1, 1, 1);
		gbc.ipadx = 0;
		gbc.ipady = 0;
		gbc.weightx = 0.0;
		gbc.weighty = 0.0;

		JPanel incScrollPane = new JPanel();
		incScrollPane.setBackground(Color.WHITE);
		gbc.gridx = 0;
		gbc.gridy = 0;
		gbc.gridheight = 2;
		gbl.setConstraints(incScrollPane, gbc);
		frame.getContentPane().add(incScrollPane);

		JPanel usrLabel = new JPanel();
		usrLabel.setBackground(Color.GREEN);
		gbc.gridx = 1;
		gbc.gridy = 0;
		gbc.gridheight = 1;
		gbc.gridwidth = GridBagConstraints.REMAINDER;
		gbl.setConstraints(usrLabel, gbc);
		frame.getContentPane().add(usrLabel);

		JPanel usrScrollPane = new JPanel();
		usrScrollPane.setBackground(Color.YELLOW);
		gbc.gridx = 1;
		gbc.gridy = 1;
		gbl.setConstraints(usrScrollPane, gbc);
		frame.getContentPane().add(usrScrollPane);

		JPanel senScrollPane = new JPanel();
		senScrollPane.setBackground(Color.CYAN);
		gbc.gridx = 0;
		gbc.gridy = 2;
		gbc.gridheight = GridBagConstraints.REMAINDER;
		gbl.setConstraints(senScrollPane, gbc);
		frame.getContentPane().add(senScrollPane);

		frame.setSize(400, 200);
		frame.setPreferredSize(new Dimension(400,200));
		frame.pack();
		frame.setVisible(true);
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(
				new Runnable() {
					public void run() {
						doIt();
					}
				}
			);
	}
}
masijade 1,351 Industrious Poster Team Colleague Featured Poster

You have used only weightx and not weighty and you have only used a horizontal fill, so your elements will not even attempt to fill the space vertically, and all "unused" space in the container will dispersed evenly around the components (i.e. the "free" vertical space will be half above and half below the components and the "free" horizontal space will be half to the left and half to the right of the components).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Maybe I'll come back to this later. I knew it was going to be this kind of question and I am just not in the mood right now.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Use an ArrayList rather than an array, and you don't have to worry about all that array manipulation. And as far as "storing" the data, how do you propose to do that with an empty actionPerformed method?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because, since you are simply painting to the graphics in an external method, rather than overriding the paintComponent method in JPanel will cause the standard "painting" of the panel to erase it. Either extend JPanel and override the paintComponent method, or have that method create an image (use BufferedImage and you can do that exactly as you are doing this now) and set that as the contents of the JPanel.

aym312 commented: insightful and truly helpful +0
masijade 1,351 Industrious Poster Team Colleague Featured Poster

That "class" however, is not doing any SQL. You need to provide the DataHolder class. Also, currently you are doing your work on the event thread which is more than just wrong. You need to learn about MVC and use it. At the very least, you need to completely separate your DB and GUI code and do the actual DB work in a separate thread that then triggers an update of the GUI.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
String queryLNLike = "SELECT * FROM employees WHERE firstName LIKE in(?)"+
"'" +ln+ "%" + "'";

Like In?

I don't think that could ever work.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What is "g1" (hint, you can find it two lines higher in the code)?

Edit: And then read reply #7 again.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well look at the code. What do think this " g1.drawString(output, 10, 20);//10, 20 keeps it neat in corner. " is doing?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

By calling repaint on the canvas after modifying the graphics object?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay? And if your first array is only 3 elements long (which is what you use to create the second array so it is also only 3 elements long, i.e. last index of 2) and one of the Strings is 6 characters long, what happens?

If you want to do it this way, then you need to find the longest String first, and make your second array that length (that length + 1 actually, since arrays are 0 based).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because you're trying index into an array using an index value representing the length of one the Strings stored in the array. What did you hope to achieve by doing that?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You include the parameter types (i.e. method(int a, int b)) when you declare a method, not when you call it. When you call it you simply provide values (or variables referencing values) i.e.

public int someMethod(int a, int b) {
  // do something
}
.....
int someInt = 2;
int anotherInt = 3;
int answerOne = someMethod(someInt, anotherInt);
int answerTwo = someMethod(1, 2);
// or any combination thereOf
...
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I should downrep you for that advice. The system classpath is very nearly useless and suggesting to "newbies" to play around with it (even more to the point of adding it if it doesn't exist) is counter-productive to their development. This "advice" is just so wrong on so many levels, but it is not, in its technical form, that far off-base so I can't, personally, justify downreping it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Post your modified add method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, shouldn't you be assigning newNode to neste, instead of the otherway around? (Hint, yes you should be).

Also, those "next" variables should be "neste", should they not?

You should also do Node temp = neste, rather than just Node temp and from that point on you should use temp.neste every where it currently uses next (as I assume you are traversing the list to find the end of it there), and that includes in the assignment at the end.

Edit: The thought behind the method is right, just skewed in the implementation. ;-)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, if the very first "fremst = fremst.neste" results in "fremst" being null, then, either, there is only one item in the list, or the items are not being added to the list properly, but I haven't seen that method, nor how it is being used, so I can't say.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

In your main method you want to define "moonwieght" so you need to do

moonweight = someMethodCall(earthweight)

and "someMethodCall" needs to return earthweight divided by 6. And someMethodCall, of course, needs to de declared to take an argument.

Give it a try and post your new code (complete).

jmguerriero commented: Thanks for your help. +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

And you now have the "fremst = fremst.neste" completely outside of the if statement, which is the reason you are getting the NPE. That, and the counter, of course, should still be inside the else portion if statement.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The output with the error:


The code I come to when I press the topmost line:

fremst = fremst.neste;

(There is nothing more around this code. Above is the method I posted in the starting post, belowe a counter; totalt++ , and that's it.)

Uhm, what do you mean "above is the method". This should be part of that method. I.E. you should be using this and "denne = fremst" instead of "denne = fremst.neste". Post that method again, as it is now.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Post the complete error statck trace for the NPE, as well as the code around the line number referenced in the NPE.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

But that part of the code has nothing to do with the removing part of the method? I thought I would get an error or warning or something if I just used:

fremst = fremst.neste;
denne = fremst;

since the first line then would try to set the next first in line to a customer who doesn't exist...?

Yes it does. Since, according to the code you posted, those "copy lines" take place in an "else block". So, if fremst is null it will never make it to those "copy lines", so it can never throw an NPE. Which is why I say that either the code is not the right code or the NPE is coming from somewhere else.

Also, there is no problem, whatsoever, in setting a reference null. You get an NPE when you then attempt to use that null reference (i.e. fremst.neste throws the NPE when fremst is null, but fremst = fremst.neste works just fun when fremst is not null, but fremst.neste is null).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I thought I needed more than those lines no matter what. I've been thinking and when the program reaches the last customer, don't I need a routine that says something like:
- If first.next is null
- first = last = null
Or someting like that...? (Do I need that last-part in a singly linked line?) That's why I tried that other one.

You already have

if (fremst == null)

which should catch that immediately in the next iteration. And since this assignment takes place in the block opposite that question, the NPE should never happen there (as long as the code originally posted is what is really being used).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Then it is because fremst.neste is null on the first run, which probably means that you are not "adding" items to the list correctly. It also, of course, means fremst is null in the second run and so those statements should never be executed, as they take place (as far as I can see) in the portion of the if block where fremst cannot be null, so either the code is not what you've posted here, or you are mistaken in where the NPE took place. And neither "denne" nor "sist" apply here as they are not being used here.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Where and when do you get the NPE, and "denne" is irrelevant in this instance if you are allways concerned with the first item in the list, and I have no idea what "sist" is. If it gives you an NPE immediately (i.e. on the second "run" even if there are multiple items in the list), then you are not setting neste correctly.

IOW, don't "try that instead", go back to what I suggested and post where you are getting the NPE and "when".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

deleting the first (and setting the "current") would be more like

fremst = fremst.neste;
denne = fremst;

because, otherwise, you are never changing the value of "fremst", and so, are never "deleting" anything.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That is VB style. It doesn't work that way in java (that would be pass-by-reference which java is not.

you do methods like this

...
double d = SomeObject.someMethod();
...
//SomeObject someMethod method
public double someMethod() {
  return 1.0;
}
...
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Sorry, but at this point you need a tutor, if not a real teacher. A forum is not going to help.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Sorry to break this to you, but it isn't OOP if you don't use objects.

It might help to see more code, then again, if you are creating new textfields every time you want to place a value in one, that is your problem, and judging by the name of the first method that appears to be what you are doing.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

"Components" don't have any kind of "positioning" features. You place components into layout that is part of a container, and that layout takes care of the positioning. Also, the border is "removable" on all swing elements, see the "sertBorder" method and the "EmptyBorder" class.

For full positioning control use GridBagLayout (you have x/y coordinates there, but probably not how you're thinking of them), but that is the hardest layout manager to use correctly.

If you feel you really must control all features of the layout then google for "Java Swing Null Layout". Be forewarned, however, that the slightest differences from machine to machine (I.E. resolution, OS, system font settings, etc, etc, etc) will probably "break" your GUI using Null Layout.

Olliepop commented: Thanks for the great reply, bookmarked :) +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, getDataBuffer is only contracted to return a "DataBuffer", whether that "DataBuffer" is a "DataBufferByte" or "DataBufferInt", I would assume varies from image type to image type, and, seemingly, your compress method winds up changing it the to different type than what "createScreenCapture" returns, thereby changing the type of "DataBuffer" that underlies the image.

If you need the int color values array behind an image (and you have a BufferedImage anyway) then use the getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What? What are you talking about? If you need these "bytes" as "chars" then do new String -> toCharArray There is no reason you cannot do that, unless those "bytes" do not represent characters (i.e. a String) and so "converting" them to chars would be pointless anyway.

I still have no idea what you mean by "Her teststr is Vector". Are you saying that this "byte buffer" is a serialised Vector object maybe? In which case this "conversion" is less than pointless anyway.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Uhm don't cast?

We might be able to give you some real help if you would post the exact and complete error message and full stack trace as well as some relevant code (using code tags).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If some of those "things" are Strings, use String's equals method rather than == to compare them. (I'm assuming efname is a String.)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Why use getBytes? Why don't you use toCharArray? In any case, the easiest way (although not necessarily the most effecient) is to do new String(byte[]).toCharArray() .

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay? I have no idea why anyone would want to "vote down" that post, but ......

To each his/her own, I guess. What about it was disagreed with would interest me though.

Salem commented: Sod the up/down thumb twiddlers, here's a vote that kicks ass! :) +19
BestJewSinceJC commented: .. up vote .. +4
masijade 1,351 Industrious Poster Team Colleague Featured Poster

An IDE is an Integrated Development Environment. It is, at it's most basic level, a jumped up editor with compiler capability.

Java Beans, at their most basic, are simple Java Classes where all members are private with getter and setter methods.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And, if he really wanted help, he would have provided the complete exception with stack trace, of course.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

registered iana media types (and a link to a registration form)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That should only happen if you have used the same id in both cases.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

In that form "cut.gif" needs to be located in the same directory as the class containing this call, inside the jarfile, of course.

No idea if that is what you meant by "program".

Seeing what execption is thrown, might help. The complete stacktrace, BTW. And don't forget to close the stream (preferrably in a finally block).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Yep, and that is using files, you need to use streams change

ImageIcon cut = new ImageIcon("images/cut.gif");

to

ImageIcon cut = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/images/cut.gif"));

assuming "images" is a "top-level directory" within the jarfile.

Edit: But that will leave the InputStream open so this is better

InputStream is = getClass().getResourceAsStream("/images/cut.gif");
ImageIcon cut = new ImageIcon(ImageIO.read(is));
is.close();
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Show me the code where you are defining and creating the Icons. That is probably where the problem is.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I don't believe that would work at all since you cannot have a "\" in a variable name, AFAIK.