473,495 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

dlite922
1,584 Recognized Expert Top Contributor
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 1964
JosAH
11,448 Recognized Expert MVP
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
2228
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
3438
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
2892
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
1835
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
2147
by: Marco | last post by:
I need to get a iterator from any generic collection. public class .... GetIterator(Object collection) { ..... }
10
11754
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
7549
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
1880
by: Jo | last post by:
class A { public: char text_a; A() { *text_a=0; } ~A() {} }; //-----------------------------------------------------------------------------
1
1858
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
6991
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
7160
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,...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.