Can't read a value in a LinkedHashMap

A

Andrej Litowka

Hi All!
I have a LinkedHashMap, that I fill with this function:

public HashMap setCallPropertyValue(int Index, String Parameter, String
Type, String Value) {
LinkedHashMap tMap = new LinkedHashMap();
int index = 0;
int posBegin = 0,
posEnd = 0;

tMap.put("index", new Integer(Index) );
tMap.put("parameter", Parameter.toUpperCase() );
tMap.put("type", Type.toUpperCase() );
tMap.put("value", Value);

return tMap;
}

Then I put this Map in another map:

public void setCallProperties(Object key, Object val) {
propMap.put(key, val);
}

Where private Map propMap = Collections.synchronizedMap(new
LinkedHashMap());

And a call in main looks like this:

setCallProperties("res", setCallPropertyValue(1,"OUT","NVARCHAR2", null) );

When I then try to read a value from the map:

Iterator it = propMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
LinkedHashMap tMap = new LinkedHashMap();

tMap = (LinkedHashMap)entry.getValue();
String str = (String)tMap.get("type");

I get an error:

java.lang.NullPointerException
at
de.impulsus.util.ISU.CDBConnection.callDBStoredProcedureOrFunction(CDBConnec
tion.java:494)
at de.impulsus.app.TestISU.main(TestISU.java:28)
Exception in thread "main"

And in debuger str has a value:

"String" <error(s)_during_the_evaluation>
String cannot be resolved

I don't undertsand why. Has anybody any idea?
Any help will be appreciate.
Regards,
Andrej.
 
J

John C. Bollinger

Andrej said:
Hi All!
I have a LinkedHashMap, that I fill with this function:

Why do you need a LinkedHashMap instead of an ordinary one for this?
The linked variety is only better if the order of insertion into the map
is important.
public HashMap setCallPropertyValue(int Index, String Parameter, String
Type, String Value) {
LinkedHashMap tMap = new LinkedHashMap();
int index = 0;
int posBegin = 0,
posEnd = 0;

tMap.put("index", new Integer(Index) );
tMap.put("parameter", Parameter.toUpperCase() );
tMap.put("type", Type.toUpperCase() );
tMap.put("value", Value);

return tMap;
}

Then I put this Map in another map:

public void setCallProperties(Object key, Object val) {
propMap.put(key, val);
}
Okaaayyyy....

Where private Map propMap = Collections.synchronizedMap(new
LinkedHashMap());

And a call in main looks like this:

setCallProperties("res", setCallPropertyValue(1,"OUT","NVARCHAR2", null) );

I see an explicit null there, could that be related to your problem?
When I then try to read a value from the map:

Iterator it = propMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
LinkedHashMap tMap = new LinkedHashMap();

tMap = (LinkedHashMap)entry.getValue();

Why do you create a new LinkedHashMap there if you're going to
immediately discard it?
String str = (String)tMap.get("type");

I get an error:

java.lang.NullPointerException
at
de.impulsus.util.ISU.CDBConnection.callDBStoredProcedureOrFunction(CDBConnec
tion.java:494)
at de.impulsus.app.TestISU.main(TestISU.java:28)
Exception in thread "main"

So which lines in the source above correspond to the line numbers in the
stack trace?
And in debuger str has a value:

"String" <error(s)_during_the_evaluation>
String cannot be resolved

I don't undertsand why. Has anybody any idea?

You will be very lucky if anyone can figure out the problem from what
you have provided. I don't see any actual errors there, but it's
nowhere near a complete example. Chances are good that the problem is
at least partially somewhere in the code that you didn't show. Pare it
down to a small example that you can post in its entirety, and if you
don't find the problem yourself in the process then post the whole
example and we'll take a crack at it. Alternatively, we might be able
to guess something from examining the specific lines reported in the
stack trace.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top