Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Corba > Re: Structs and...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 438 of 558
Post > Topic >>

Re: Structs and null pointer exceptions

by Piet van Oostrum <piet@[EMAIL PROTECTED] > Jul 1, 2006 at 02:07 PM

>>>>> jamesb457@[EMAIL PROTECTED]
 (J) wrote:

>J> I have an IDL looking something like this
>J> module LMS
>J> {

>J>   struct Alarm
>J>   {
>J>     string sensor;
>J>     string zone;
>J>   };

>J>   interface LMSIF
>J>   {
>J>     void raise_alarm(in Alarm aReading);
>J>     void send_alarm_to_rmc(in string alarm);
>J>     string test_case();
>J>   };
>J> };

>J> and a java file looking something like:

>J> class LMSServant extends _LMSIFImplBase
>J> {
>J>    Alarm al;
>J>    //functions here
>J>   public LMSServ()
>J>   {
>J>       //this line causes the problem.
>J>       al.sensor = "Sensor 1";
>J>   }

>J> }

>J> The problem i'm having is when i try to modify or write to the Alarm
>J> struct i get a NullPointerException every time.
>J> Am i doing something wrong?

yes. You only declare the Alarm variable al, but you don't reserve any
memory for it. It initializes with null. In Java Corba structs are cl*****
and you have to create an instance with new. In contrast to C and C++
where
structs get memory automatically.

So Alarm al = new Alarm(); should solve it I think.
-- 
Piet van Oostrum <piet@[EMAIL PROTECTED]
>
URL: http://www.cs.uu.nl/~piet
[PGP 8DAE142BE17999C4]
Private email: piet@[EMAIL PROTECTED]

 




 2 Posts in Topic:
Structs and null pointer exceptions
jamesb457@[EMAIL PROTECTE  2006-06-29 12:11:13 
Re: Structs and null pointer exceptions
Piet van Oostrum <piet  2006-07-01 14:07:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Dec 4 0:08:06 CST 2008.