473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

JDBM put() then get() needs type casting?

dlite922
1,584 Expert 1GB
Hey fellas, long time PHP programmer (yes you can roll your eyes) trying to do Java. Although I initially came from C++ and Java programming to PHP, I'm having trouble grasping a concept:

I'm creating a jdbm hash table and putting in a String[] as the value, but when I try to get() it, it returns type Object and does not like being casted back to String[]. What is going on and why not?

Expand|Select|Wrap|Line Numbers
  1.  
  2. hashtable = HTree.createInstance( recman );
  3. .
  4. .
  5. .
  6. String[] test= {"test hard, testhard2", "romeo must test", "live rich or test trying"};
  7. String[] romeo = {"romeo must die","romeo and juliet","romeo and juliet 2"};
  8. hashtable.put( "die", die );
  9. hashtable.put( "die", romeo );
  10. .
  11. .
  12. .
  13. // Error Line: 
  14. String[] titleArr = hashtable.get("die");
  15.  
  16. Error: Uncompilable source code - incompatible types
  17.  
  18.  
  19.  
I've tried putting (String[]) explicit cast in front of the get, but still errors as saying:

java.lang.String cannot be cast to [Ljava.lang.String

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


FIXED before I finished my post, for anyone else who has the same issue. Experts, comments/feedback are welcome.

Explanation of my bug:
I was using an existing jdbm file that already had these keys with String values, not an array. recreated it and then the explicit casting worked. But I didn't use String[] anymore I used java.util.HashSet because my lists could get pretty large.

Thanks,




Dan
May 18 '09 #1
1 1960
JosAH
11,448 Expert 8TB
You have to learn how to read those internal class names; the following list was bluntly stolen from the description of the Class.getName() method:

boolean Z
byte B
char C
class or interface Lclassname;
double D
float F
int I
long J
short S

If you read that error message again you'd see what had happened.

kind regards,

Jos
May 31 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

43
by: Spare Change | last post by:
This is a recommendation to Microsoft. VB.net and c# are almost exactly equivalent. I know why Microsoft invented VB.net -- to wean old style VB6 scripters into a true OO world: .Net. But...
4
by: Jacob Jensen | last post by:
This question has probably been asked a million time, but here it comes again. I want to learn the difference between the three type cast operators: static_cast, reinterpret_cast, dynamic_cast. A...
0
by: Chen Yang | last post by:
Hi all, Please help me out with this memory problem with JDBM's H-Tree, thanks in advance. I am using JDBM to develop my search system. While I load the data into JDBM, I put them into...
12
by: TTroy | last post by:
For function definitions (not declarations/prototypes), is it necessary to put void in the emptry braces if the function is to receive no parameters? Does this turn any error checking off or cause...
18
by: Marco | last post by:
I need to get a iterator from any generic collection. public class .... GetIterator(Object collection) { ..... }
10
by: Bob | last post by:
This has been bugging me for a while now. GetType isn't availble for variables decalred as interface types, I have to DirectCast(somevariable, Object). In example: Sub SomeSub(ByVal...
15
by: shuisheng | last post by:
Dear All, Assume I have a class named Obj. class Obj { }; And a class named Shape which is derived from Obj. class Shape: public Obj
31
by: Jo | last post by:
class A { public: char text_a; A() { *text_a=0; } ~A() {} }; //-----------------------------------------------------------------------------
1
dlite922
by: dlite922 | last post by:
I developed a Java application and want to peek inside my jdbm data store for testing purposes. Maybe i'm seeing jdbm too much like sqlite3, but isn't anyone interested in a client app that can see...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.