All Questions

211
votes
12answers
1624441 views

What is a NullPointerException, and how do I fix it?

What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them? What methods/tools can be used to determine the cause so that you stop the exception from causing the program t...
727
votes
23answers
2787356 views

How do I compare strings in Java?

I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug. Is == bad? When should it ...
4872
votes
75answers
1449205 views

Is Java "pass-by-reference" or "pass-by-value"?

I always thought Java was pass-by-reference; however I've seen a couple of blog posts (For example, this blog) that claim it's not. I don't think I understand the distinction they're making. What is...
451
votes
9answers
94280 views

The Use of Multiple JFrames: Good or Bad Practice?

I'm developing an application which displays images, and plays sounds from a database. I'm trying to decide whether or not to use a separate JFrame to add images to the database from the GUI. I'm ju...
536
votes
15answers
256699 views

Unfortunately MyApp has stopped. How can I solve this?

I am developing an application, and everytime I run it, I get the message: Unfortunately, MyApp has stopped. What can I do to solve this? About this question - obviously inspired by What is a...
411
votes
14answers
269228 views

Scanner is skipping nextLine() after using next(), nextInt() or other nextFoo()?

I am using Scanner methods nextInt() and nextLine() for reading input. Basically, it looks like this: System.out.println("enter numerical value"); int option; option = input.nextInt();//read nume...
155
votes
14answers
391287 views

What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?

What does ArrayIndexOutOfBoundsException mean and how do I get rid of it? Here is a code sample that triggers the exception: String[] name = {"tom", "dick", "harry"}; for(int i = 0; i<=name.leng...
192
votes
11answers
34208 views

How to add JTable in JPanel with null layout?

I want to add JTable into JPanel whose layout is null. JPanel contains other components. I have to add JTable at proper position.
1447
votes
28answers
232726 views

How to avoid Java code in JSP files?

I'm new to Java EE and I know that something like the following three lines <%= x+1 %> <%= request.getParameter("name") %> <%! counter++; %> is an old school way of coding and in ...
408
votes
8answers
41325 views

Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?

Several times I've been criticized for having suggested the use of the following methods: setPreferredSize setMinimumSize setMaximumSize on Swing components. I don't see any alternative to their u...

Previous Next