473,395 Members | 1,474 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,395 software developers and data experts.

steps to solve java.nullpointerexception

how can isolve this problem in my balckberry
steps to solve java.nullpointerexception
Jan 5 '11 #1
2 1479
Dheeraj Joshi
1,123 Expert 1GB
You are trying to use some variable which is not having any value.

Debug and figure out which is that value.

Regards
Dheeraj Joshi
Jan 5 '11 #2
nathj
938 Expert 512MB
when you know the variable you can put a simple if check around it or use the try catch block catching a NullPointerException.

So, for example if the variable in question is a String called var1
Expand|Select|Wrap|Line Numbers
  1.  
  2. if(var1 != null && var1.length() > 0)
  3. {
  4. // use the variable
  5. }
  6. else
  7. {
  8. // handle the exception
  9. }
  10.  
Alternatively using the try catch method:
Expand|Select|Wrap|Line Numbers
  1. try{
  2.  // use the variable var1
  3. }catch(NullPointerException npe){
  4. System.out.println(npe.getMessage()); // not production ready
  5. }
  6.  
This is the way I would go, the finl suggestion is that if it is appropriate set up the variable with a default value.

Hope this helps
nathj
Jan 6 '11 #3

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

Similar topics

3
by: billbou | last post by:
Exw balei Forte4.0 sto PC kai java_sdk_1.4.2. To problima einai oti den brisko online documentation(oxi meso internet) kai mou exoun spasei ta neyra. Den mporeis na thimase toses klaseis apekso,...
47
by: Theatre Mgmt | last post by:
Sun project seeks to solve Java memory, execution issues http://story.news.yahoo.com/news?tmpl=story&u=/infoworld/20050325/tc_infoworld/58059&e=1&ncid= San Francisco (InfoWorld) - Sun...
30
by: Rhino | last post by:
I am giving some thought to applying for some jobs that want people with Java and C++ experience. I have been writing Java for several years and am fluent enough that I don't have to get help with...
3
by: Chris K. | last post by:
Hi, Setting my first steps into Java, managing my genealogy website. In the list of names, with the names in anchor tags, i want a popup window to appear on clicking the name. With the command...
1
by: ciligun | last post by:
hi everybody..please help me, i'm starting to study java..but i need some help.. i instaled j2se..but i have no ideea what to do next..how to set the executable file to start always in Bin ...
2
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
1
by: r035198x | last post by:
This exception occurs often enough in practice to warrant its own article. It is a very silly exception to get because it's one of the easiest exceptions to avoid in programming. Yet we've all got it...
4
by: vikassawant | last post by:
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;
2
by: vikassawant | last post by:
hi, I am trying to import excel file in JTable.For that I used following code, import com.zfqjava.swing.*; import org.apache.poi.hssf.usermodel.*; import...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.