473,748 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

null pointer exception - mixing java and javascript

12 New Member
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 currentObservat ion.getComment( ) (java) is not null then all is well. But if it is null, instead of just setting document.commen tForm.commentBo x.value to a blank string I get a java.lang.NullP ointerException .

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 2212
JosAH
11,448 Recognized Expert MVP
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 currentObservat ion.getComment( ) (java) is not null then all is well. But if it is null, instead of just setting document.commen tForm.commentBo x.value to a blank string I get a java.lang.NullP ointerException .

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 'currentObserva tion' 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
6041
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" ( i am talking of unix machine ) while trying to read that location. Then how can i distinguish between a NULL pointer and an invalid location ? Is this essential that NULL pointer should not point to any of the location in the virtual address...
99
5170
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
41
10047
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 integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.55) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed...
1
3495
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. It is working fine for Java5. Here i am giving the piece of code where it is throwing me exception protected void autoDetectProxy(URL url) { // Trying Java system variables.
2
1485
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 outside init and made it global plz bear im relatively new to java import java.awt.*; import java.awt.event.*; import java.applet.*; public class calander extends Applet implements ActionListener,MouseMotionListener { Label l1,l2,l3,l4;...
9
4134
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 FrontPage 3.0"> 11: <html:javascript src="bscript.js" method="everything(this)" staticJavascript="false"/> 12: <!-- <SCRIPT LANGUAGE="JavaScript" SRC="bscript.js"></SCRIPT> --> 13: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
17
6367
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 lead to a couple pointers sometimes being NULL at the wrong time. As it stands the program just bombs out when it tries to dereference the NULL, which obviously isn't good (especially when it happens with the customer looking on!!).
2
3101
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 transactionStatement; import javax.xml.transform.TransformerFactory; import javax.servlet.*; import org.jdom.*; import java.io.ByteArrayOutputStream; import java.io.File;
5
2347
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 MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.radesan.struts.action; import java.sql.*; import javax.servlet.http.HttpServletRequest;
0
8983
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8822
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8235
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.