I am trying to typecast and object to get at methods specific to its class, but am running into a strange error at runtime.
The line that causes the problem is simply:
whoops2 temp=(whoops2 ) teammate;
where teammate is declared as class which whoops2 extends, and is actually a whoops2 object. The error I'm receiving is:
java.lang.ClassCastException: whoops2 cannot be cast to whoops2
java.lang.ClassCastException: whoops2 cannot be cast to whoops2
at whoops2.takeTurn(whoops2.java:92)
I've never run into a problem like this typecasting before. I feel like there must be something stupid I'm missing, but for the life of me I can't figure what. Any help would be greatly appreciated.
Thank you
7 1489
Can we see a bit of the actual code and the actual exception message?
kind regards,
Jos
well you asked for it :-P code, leaving out irrelevant functions is
the bolded underlined line is where the error occurs.
The full exception message is:
java.lang.ClassCastException: whoops2 cannot be cast to whoops2
java.lang.ClassCastException: whoops2 cannot be cast to whoops2
at whoops2.takeTurn(whoops2.java:92)
at Clobber.getBotActions(Clobber.java:548)
at Clobber.play(Clobber.java:719)
at Clobber.main(Clobber.java:1077)
Thanks agian
What is the type of 'teammates'?
kind regards,
Jos
ps. I suspect an out of date class file here; or some esoteric classloading issue
because every X (loaded by the same classloader) can be cast to itself.
I suggest to recompile your classes and see what happens then.
kind regards,
Jos
thats why I'm so confused, is that I know I should be able to cast to itself, and that error says pretty clearly I've got the right object of the right type. I tried recompiling everything I have source for (basically whoops2 and ClobberBot) with no success. Unfortunately everything else I only have the class files and documentation for. I think I may need to break down and use reflection (I was able to get that to work, but I hate too since it shouldn't be necessary).
Oh and in awnser to your question, teammates is of type ClobberBot (which should be fine since whoops2 extends it) and is and inherited private field from the ClobberBot class)
If you have any great brainstorms I'd appreciate it if you passed them along but I think I'll move forward with reflection for now.
Thanks for the help.
Well sure enough you were right, at least you gave me the clue I needed. I was able to the code for the main part of the game, and each bot in the game is loaded by the same class of ClassLoader, but a different instantiation.
Thank you again for the help!
If you really want the best help from this forum I suggest the following. Recreate your error in a short (<1 page) example program that forum members can copy and run, and post that example program to the forum.
That's how I solve sticky problems. I write the shortest possible program that expresses them, and often the solution is staring me in the face. In any case, when I solve it, I add it to my directory of brain teasers, and if it ever comes up again in another program, I can go back and see exactly how I solved it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Grzegorz Kaczor |
last post by:
Hello all,
I've got a VERY strange network problem with Win2k Server and .NET.
I've got one central server (hub) getting raw binary data (files) from
many locations. Both server and clients...
|
by: M O J O |
last post by:
Hi,
I'm developing a asp.net application and ran into a strange css problem.
I want all my links to have a dashed underline and when they are
hovered, it must change to a solid line. Sounds...
|
by: Grzegorz Kaczor |
last post by:
Hello,
I've got a VERY strange network problem with Win2k Server and .NET.
I've got one central server (hub) getting raw binary data (files)
from many locations. Both server and clients are...
|
by: James Wong |
last post by:
Hi! everybody,
I'm facing a quite strange download problem. I use the following code to
download an XML file to client side:
With Response
' clear buffer
Call .Clear()
' specify the...
|
by: big DWK |
last post by:
Hi-
We're having a strange caching problem with an ASP.Net app written
in VB.Net on Windows 2003 with all the updates. We have two websevers
that use a common sql backend and a session server to...
|
by: arcimboldo |
last post by:
Hello,
I got a strange link problem; here are the simplest files showing the
error:
a.h::
#include <utility>
class a{
public:
|
by: Me |
last post by:
Hi,
I ran into a malloc problem but I can't find the solution.
I try to read a file into a variable with malloc like this:
BYTE *lcdata;
lcdata = malloc(fsize*sizeof(BYTE));
|
by: Manikandan |
last post by:
Hi,
I am using the following snippet to compare an object with integer in
my script.
if ( $forecast < 4 ) {
I got the "segmentation fault" error message when i executed this
script in CLI....
|
by: shaneal |
last post by:
Hello all,
I've been trying to learn some javascript and I ran into a strange
scoping problem I was hoping someone here could help with. I have a
fair amount of experience with functional...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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,...
|
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...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |