473,395 Members | 1,762 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.

null pointer exception - mixing java and javascript

12
Hello,

Firstly, apologies if this should be in the javascript forum - I wasnt sure which was most appropriate to post this question in...

I am not sure if my problem is caused by the way I am mixing java and javascript in my jsp and if it can be fixed.

If currentObservation.getComment() (java) is not null then all is well. But if it is null, instead of just setting document.commentForm.commentBox.value to a blank string I get a java.lang.NullPointerException.

Am I testing for null incorrectly, or is it impossible to mix java and javascript quite like this?!

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. var commentValue = "";
  3. <%if(currentObservation.getComment()!=null){%>
  4.        document.commentForm.commentBox.value="<%=currentObservation.getComment()%>";
  5. <%}else{%>
  6.         document.commentForm.commentBox.value = "";
  7. <%}%>
  8. document.commentForm.commentBox.value = "";
  9. document.commentForm.remLen.value = (1000 - commentValue.length);
  10.                                     //-->
  11.                                 </script>
any help gratefully received
Nov 27 '07 #1
1 2197
JosAH
11,448 Expert 8TB
Hello,

Firstly, apologies if this should be in the javascript forum - I wasnt sure which was most appropriate to post this question in...

I am not sure if my problem is caused by the way I am mixing java and javascript in my jsp and if it can be fixed.

If currentObservation.getComment() (java) is not null then all is well. But if it is null, instead of just setting document.commentForm.commentBox.value to a blank string I get a java.lang.NullPointerException.

Am I testing for null incorrectly, or is it impossible to mix java and javascript quite like this?!

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. var commentValue = "";
  3. <%if(currentObservation.getComment()!=null){%>
  4.        document.commentForm.commentBox.value="<%=currentObservation.getComment()%>";
  5. <%}else{%>
  6.         document.commentForm.commentBox.value = "";
  7. <%}%>
  8. document.commentForm.commentBox.value = "";
  9. document.commentForm.remLen.value = (1000 - commentValue.length);
  10.                                     //-->
  11.                                 </script>
any help gratefully received
I guess your 'currentObservation' itself is null. The rest of your code looks fine
as far as I can tell.

kind regards,

Jos
Nov 27 '07 #2

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

Similar topics

102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
41
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An...
1
by: MRamaLakshmi | last post by:
hi, I am developing an application using Java Applet which will be uploading files. Its throwing Null Pointer exception while detecting the proxy when we are trying to load the applet using Java6....
2
by: true blue | last post by:
hey ppl plz can any one help me with this code im gettin a null pointer exception when i use graphics class object (g.drawString)in action performed functio eventhough i hava declared the object...
9
by: ajos | last post by:
hi all, im getting some problems in my javascript validations..... my jsp code--> 8: <head> 9: <title>Budget Master Administration</title> 10: <meta name="GENERATOR" content="Microsoft...
17
by: Tony Jackson | last post by:
Hi I'm quite new to C programming - I have more of a Java background: maybe someone here can advise me. I'm nearly finishing a little program but it has some hard-to-find bugs that basically...
2
by: crabsdf | last post by:
My project is a single method class which takes a xml object and, using Apache FOP, transforms it into a PDF which is returned as an output stream. Here is full code package...
5
by: iamdennisthomas | last post by:
Hi Guys i was developing a action servlet which is actulally getting the data from a form and putting it in the db but while executing i am getting a null pointer exception /* * Generated by...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.