• Post Reply Bookmark Topic Watch Topic
  • New Topic

sysntex error in 2 dim array value assignment...  RSS feed

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Map hashmap = new HashMap();
hashmap = req.getParameterMap();
int i=0;
int j=0;
String message[][];
for(Iterator it=hashmap.entrySet().iterator();it.hasNext() {
String value;
Map.Entry entry = (Map.Entry)it.next();
Object key = entry.getKey();
//Object value = entry.getValue();
value = req.getParameter((String)key);
// String pair = key + " : " + value;
message[i][j] = [key][value]; //Syntex Error
i++;
j++;
System.out.println(key + " : " + value);
}
[b] Its giving me syntex error while assigning value to 2 dim array...
 
Anu Pillai
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What syntax error are you getting?

If the error says that message is not initialized, then use the line String message[][] = new String[10][10];

But your way of assigning value to the message array is wrong.
message[i][j] can hold only one string, not a key value pair.
So your statement should be message[i][j] = "Some Sring";

In case you want to store a key value pair, use a Map instead.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes the key and value are comming from hashmap itself but i want to pass this string array as a parameter to my e-mail message body...

in my email message it's not accepting hash map i don't even know wather it will accept string array or not...

do you have any idea of passing hash map as an arguement to mail message body



ANY IDEA ???
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


First, the message array has never been instantiated... but that is not the problem here. You are getting a Syntax error, because this isn't a valid Java statement.

If you can describe what you think should happen (with this line), we can help you get it into valid Java statements.

Henry
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you have any idea of passing hash map as an arguement to mail message body


Remember that you are building an e-mail message. If someone were to send you an email with a hashmap in it, how would it look? You, as with most people, would like to read text, and have no idea how to read a hashmap.

Personally, I would try hashmap.toString(), and see if it returns something that is readable. If it doesn't, then you have no choice but to build the message text as a string first.

Henry
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya we can pass only strings to a message body and so as i take the each key value pair of hash map in to string and passed it to mail message...

my problem is solved but i feel it's not a good solution...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!