🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.language
4 messages
4 total messages Started by Raul Lorenzo Thu, 25 May 2006 17:59
Array problem
#194
Author: Raul Lorenzo
Date: Thu, 25 May 2006 17:59
25 lines
1450 bytes
Hello,

I have this piece of code
/***************************************************/
int index=0;
AttributeREM RoleREM[]=null;
RoleREM=new AttributeREM[asociationREM.numero_roles];
RoleREM[index].oid="hello";
/***************************************************/

Java reports me a null Pointer exception at RoleREM[index].oid="hello";
Why?
asociationREM.numero_roles is always >0

AttributeREM is a class something like this

class AttributeREM
{
public String oid;
public String name;
...
...
};

Thanks in advance
Re: Array problem
#195
Author: Lori M Olson [TeamB]
Date: Thu, 25 May 2006 20:52
54 lines
2302 bytes
Raul Lorenzo wrote:
> Hello,
> 
> I have this piece of code
> /***************************************************/
> int index=0;
> AttributeREM RoleREM[]=null;
> RoleREM=new AttributeREM[asociationREM.numero_roles];
> RoleREM[index].oid="hello";
> /***************************************************/
> 
> Java reports me a null Pointer exception at RoleREM[index].oid="hello";
> Why?
> asociationREM.numero_roles is always >0
> 
> AttributeREM is a class something like this
> 
> class AttributeREM
> {
> public String oid;
> public String name;
> ...
> ...
> };
> 
> Thanks in advance
> 

This statement:

RoleREM=new AttributeREM[asociationREM.numero_roles];

Creates an array, but it does not populate the array with instances of 
AttributeREM.  The contents of the array will all be null, until you put 
something in it.

-- 

Regards,

Lori Olson [TeamB]

------------

Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.

Google Advanced Newsgroup Search
     http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
     http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
     http://www.visi.com/~gyles19/fom-serve/cache/1.html
Re: Array problem
#196
Author: Raul Lorenzo
Date: Fri, 26 May 2006 13:47
40 lines
2040 bytes
Ok, It�s like C++.....I think Java create all the structure autom�tically.
Thanks

Lori M Olson [TeamB] escribi�:
> Raul Lorenzo wrote:
>> Hello,
>>
>> I have this piece of code
>> /***************************************************/
>> int index=0;
>> AttributeREM RoleREM[]=null;
>> RoleREM=new AttributeREM[asociationREM.numero_roles];
>> RoleREM[index].oid="hello";
>> /***************************************************/
>>
>> Java reports me a null Pointer exception at RoleREM[index].oid="hello";
>> Why?
>> asociationREM.numero_roles is always >0
>>
>> AttributeREM is a class something like this
>>
>> class AttributeREM
>> {
>> public String oid;
>> public String name;
>> ...
>> ...
>> };
>>
>> Thanks in advance
>>
> 
> This statement:
> 
> RoleREM=new AttributeREM[asociationREM.numero_roles];
> 
> Creates an array, but it does not populate the array with instances of
> AttributeREM.  The contents of the array will all be null, until you put
> something in it.
> 
Re: Array problem
#197
Author: Alexey N. Solofnenko
Date: Sat, 27 May 2006 04:17
49 lines
2348 bytes
In Java all object variables are actually similar to C++ pointers. So, 
when you create AttributeREM* array you will also get an array of nulls.

- Alexey.

Raul Lorenzo wrote:
> Ok, It´s like C++.....I think Java create all the structure automátically.
> Thanks
> 
> Lori M Olson [TeamB] escribió:
>> Raul Lorenzo wrote:
>>> Hello,
>>>
>>> I have this piece of code
>>> /***************************************************/
>>> int index=0;
>>> AttributeREM RoleREM[]=null;
>>> RoleREM=new AttributeREM[asociationREM.numero_roles];
>>> RoleREM[index].oid="hello";
>>> /***************************************************/
>>>
>>> Java reports me a null Pointer exception at RoleREM[index].oid="hello";
>>> Why?
>>> asociationREM.numero_roles is always >0
>>>
>>> AttributeREM is a class something like this
>>>
>>> class AttributeREM
>>> {
>>> public String oid;
>>> public String name;
>>> ...
>>> ...
>>> };
>>>
>>> Thanks in advance
>>>
>> This statement:
>>
>> RoleREM=new AttributeREM[asociationREM.numero_roles];
>>
>> Creates an array, but it does not populate the array with instances of
>> AttributeREM.  The contents of the array will all be null, until you put
>> something in it.
>>

-- 
Alexey N. Solofnenko
home: http://trelony.cjb.net/
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads