 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Fri Jun 30, 2006 12:11 am Post subject: Structs and null pointer exceptions |
|
|
I have an IDL looking something like this
module LMS
{
struct Alarm
{
string sensor;
string zone;
};
interface LMSIF
{
void raise_alarm(in Alarm aReading);
void send_alarm_to_rmc(in string alarm);
string test_case();
};
};
and a java file looking something like:
class LMSServant extends _LMSIFImplBase
{
Alarm al;
//functions here
public LMSServ()
{
//this line causes the problem.
al.sensor = "Sensor 1";
}
}
The problem i'm having is when i try to modify or write to the Alarm
struct i get a NullPointerException every time.
Am i doing something wrong?
Do i need to define anything extra to get an IDL struct to work as a
java class?
I tried redefining Alarm as a class with the same variables but this
caused all sorts of other errors..
Any help appreciated  |
|
| Back to top |
|
 |
Piet van Oostrum Guest
|
Posted: Sat Jul 01, 2006 5:07 pm Post subject: Re: Structs and null pointer exceptions |
|
|
| Quote: | jamesb457 (AT) gmail (DOT) com (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 classes
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 (AT) cs (DOT) uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet (AT) vanoostrum (DOT) org |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|