473,394 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to solve java.lang.NullPointerException

hi,
when I execute following code, I get the java.lang.NullPointerException

try
{

int cnt=0;
for(int i=0;i<d;i++)
{
String s = dpos[i];
String s1 = dpos1[i];
String s2 = dpos2[i];
String s3 = dpos3[i];

if(s.equals("C") || s1.equals("C") || s2.equals("C") || s3.equals("C"))
{
cnt++;
cfn[i] = dfn[i];
cln[i] = dln[i];
cpos[i] = dpos[i];
chr[i] = dhr[i];
crbi[i] = drbi[i];
csb[i] = dsb[i];
cavg[i] = davg[i];
cvalue[i] = dvalue[i];
}

}

for(int c=0;c<cnt;c++)
{
System.out.println("Selected Players for C Position are:"+cfn[c]+" "+cln[c]);
}


}
catch(Exception e)
{
System.out.println("Exception is....."+e);
}

but when I execute above code by making change in only if condition like

if(s.equals("C") )

it works well.But I want to check for all four string.

What mistake is here due to which I get the above exception.

Thanks,
Vikas Sawant.
Mar 14 '09 #1
4 7672
JosAH
11,448 Expert 8TB
In your catch clause change your print statement to "e.printStackTrace()" and you'll see exactly on what line you tried to dereference a null reference.

kind regards,

Jos
Mar 14 '09 #2
thanks Jos,

I change exception according to you...
I get the error at same line which I told above... i.e.

if(s.equals("C") || s1.equals("C") || s2.equals("C") || s3.equals("C"))

but when I change this loop like

if(s.equals("C"))

It works.

Please tell me what can I do.

Thanks,
Vikas Sawant.
Mar 14 '09 #3
JosAH
11,448 Expert 8TB
@vikassawant
At least one of s1, s2 or s3 are equal to null then. You have to reason 'backwards' in your code and see what caused it. A few System.out.println( ... ) method calls sprinkled in may be of help.

kind regards,

Jos
Mar 14 '09 #4
r035198x
13,262 8TB
There is also a whole article devoted to that exception alone.
Mar 16 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
2
by: Tim Murray | last post by:
First of all, I don't know much about Java, even its naming and version numbering nomenclature, and second, if there is a better group to ask this in, please let me know. System is Mac with...
3
sammyboy78
by: sammyboy78 | last post by:
Hello again, This time I'm creating a program that creates an array of CD objects and then displays the information. I've created a CD class, a CDInventory class and then a CDInventoryDisplay to...
0
by: gezkk | last post by:
hi, i m using http proxy service to get proxy and host to applet, its working fine with jdk1.5 but getting java.lang.NullPointerException in jdk1.6 And the following is mseeage contains java...
0
by: ycinar | last post by:
hey all, i am working on a Java project using JBuilder.. when i build my code its fine, but when comes to run, it doesnt run and displays the following logs.. i think there is JDK conflict.. ...
1
by: ketand1 | last post by:
import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import java.sql.*; import java.lang.*; class DbAwt extends Frame implements ActionListener { private...
1
by: ksrashmi | last post by:
HI I am getting following exception when i use mxml tags in jsp <%@ taglib uri="FlexTagLib" prefix="mm" %> can any one tell why i am getting this exception type Exception report message...
3
by: ohadr | last post by:
hi, i get Exception in thread "main" java.lang.NullPointerException when i run my application. the exact error is: "Exception in thread "main" java.lang.NullPointerException at...
1
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.