197,999 questions
Score of 209
12 answers
4361517 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 ...
Score of 723
23 answers
4849293 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 ...
Score of 7742
87 answers
2839558 views
Is Java "pass-by-reference" or "pass-by-value"?
I always thought Java uses pass-by-reference. However, I read a blog post which claims that Java uses pass-by-value. I don't think I understand the distinction the author is making.
What is the ...
Score of 364
25 answers
1074666 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[] names = { "tom", "bob", "harry" };
for (int i = 0; i <= ...
Score of 974
25 answers
913940 views
Scanner is skipping nextLine() after using next() or nextFoo()?
I am using the Scanner methods nextInt() and nextLine() for reading input.
It looks like this:
System.out.println("Enter numerical value");
int option;
option = input.nextInt(); // Read ...
Score of 888
23 answers
565759 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 stack ...
Score of 2747
65 answers
1548593 views
How can I fix 'android.os.NetworkOnMainThreadException'?
I got an error while running my Android project for RssReader.
Code:
URL url = new URL(urlToRssFeed);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory....
Score of 823
15 answers
379616 views
What is a raw type and why shouldn't we use it?
Questions:
What are raw types in Java, and why do I often hear that they shouldn't be used in new code?
What is the alternative if we can't use raw types, and how is it better?
Score of 549
9 answers
152497 views
The Use of Multiple JFrames: Good or Bad Practice? [closed]
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 ...
Score of 996
11 answers
150608 views
How do I write a correct micro-benchmark in Java?
How do you write (and run) a correct micro-benchmark in Java?
I'm looking for some code samples and comments illustrating various things to think about.
Example: Should the benchmark measure time/...
Score of 555
19 answers
1745123 views
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
Please explain the following about "Cannot find symbol", "Cannot resolve symbol" or "Symbol not found" errors (in Java):
What do they mean?
What things can cause them?
...
Score of 1357
38 answers
2603168 views
How to parse JSON in Java
I have the following JSON text. How can I parse it to get the values of pageName, pagePic, post_id, etc.?
{
"pageInfo": {
"pageName": "abc",
"pagePic":...
Score of 248
11 answers
51603 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.
Score of 1773
31 answers
329948 views
How can I avoid Java code in JSP files, using JSP 2?
I know that something like the following three lines
<%= x+1 %>
<%= request.getParameter("name") %>
<%! counter++; %>
is an old school way of coding and in JSP version 2 ...
Score of 509
9 answers
71112 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 alternatives to ...