aspose file tools*
The moose likes Java in General and the fly likes Cast object[][] into strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cast object[][] into strings" Watch "Cast object[][] into strings" New topic
Author

Cast object[][] into strings

marko markovic
Greenhorn

Joined: Mar 16, 2001
Posts: 28
Hi,
i have an Object[][] with Key and Value.
My question:
How can i get these informations as a string?
Put Key in a variable k and Value in a variable v.
I tried something like this:
Object[][] theCmbxList;
...
for (int j = 0; j < theCmbxList.length; j++) {
String theCmbxId = (String)theCmbxList[0][j];
String theCmbxName = (String)theCmbxList[1][j];
...
but didnt' work!
Use the code in Js pages.
Help me through, please!
$Regards
Mark Savory
Ranch Hand

Joined: Feb 08, 2001
Posts: 122
What is the error you get? It look likes it should work assuming the Key and Value are actually String objects.
marko markovic
Greenhorn

Joined: Mar 16, 2001
Posts: 28
Please, my error:
Error: 500
Location: /EntityFinder/jsp/Recherche.jsp
Internal Servlet Error:
javax.servlet.ServletException: java.lang.Integer
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
at jsp._0002fjsp_0002fRecherche_0002ejspRecherche_jsp_75._jspService(_0002fjsp_0002fRecherche_0002ejspRecherche_jsp_75.java:264)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
Root cause:
java.lang.ClassCastException: java.lang.Integer
at jsp._0002fjsp_0002fRecherche_0002ejspRecherche_jsp_75._jspService(_0002fjsp_0002fRecherche_0002ejspRecherche_jsp_75.java:195)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
So at leat one of your elements is actually an Integer.
try
String xx = theCmbxList[0][j].toString();


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Mark Savory
Ranch Hand

Joined: Feb 08, 2001
Posts: 122
Looks like you should be casting the ID(Key) to an Integer object:
Integer theCmbxId = (Integer)theCmbxList[0][j];
marko markovic
Greenhorn

Joined: Mar 16, 2001
Posts: 28
the comment of Mark Savory
i get this error:
Error: 500
Location: /EntityFinder/jsp/Recherche.jsp
Internal Servlet Error:
javax.servlet.ServletException: java.lang.Integer
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
at jsp._0002fjsp_0002fRecherche_0002ejspRecherche_jsp_1._jspService(_0002fjsp_0002fRecherche_0002ejspRecherche_jsp_1.java:264)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
Root cause:
java.lang.ClassCastException: java.lang.Integer
at jsp._0002fjsp_0002fRecherche_0002ejspRecherche_jsp_1._jspService(_0002fjsp_0002fRecherche_0002ejspRecherche_jsp_1.java:196)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
marko markovic
Greenhorn

Joined: Mar 16, 2001
Posts: 28
For the comment of Frank Carver i get the following error:

Error: 500
Location: /EntityFinder/jsp/Recherche.jsp
Internal Servlet Error:
javax.servlet.ServletException: java.lang.Integer
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
at jsp._0002fjsp_0002fRecherche_0002ejspRecherche_jsp_2._jspService(_0002fjsp_0002fRecherche_0002ejspRecherche_jsp_2.java:264)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
Root cause:
java.lang.ClassCastException: java.lang.Integer
at jsp._0002fjsp_0002fRecherche_0002ejspRecherche_jsp_2._jspService(_0002fjsp_0002fRecherche_0002ejspRecherche_jsp_2.java:196)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
Mark Savory
Ranch Hand

Joined: Feb 08, 2001
Posts: 122
Try:
...
for (int j = 0; j < theCmbxList.length; j++) {
String theCmbxId = theCmbxList[0][j].toString();
String theCmbxName = theCmbxList[1][j].toString();
...
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I don't really believe that.
It looks like exactly the same error as you had before, but my suggestion does not have any class casts in it. have you made sure the servlet container has picked up the new files (restart Tomcat)? Have you changed all the (String)xx to xx.toString() ?
[This message has been edited by Frank Carver (edited March 21, 2001).]
marko markovic
Greenhorn

Joined: Mar 16, 2001
Posts: 28
i resolved the problem!

i had invert the array indices and when i tried to do this:
String theCmbxName = theCmbxList[1][j].toString(); i get the cast error.
My array structure was
8 9
Dp1 Dp2
and know is it
8 Dp1
9 Dp2
and the cast work now like this:
for (int j = 0; j < theCmbxList[0].length; j++) {
String theCmbxId = theCmbxList[j][0].toString();
String theCmbxName = theCmbxList[j][1].toString();
}
Thanks all for your replies.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cast object[][] into strings