Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Error message explanation
 Post subject: Error message explanation Post rating: 0   New post Posted: Mon 02 May, 2016, 00:56 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi

Could somebody explain what this java error message means................

java.lang.ClassCastException:com.dukascopy.dds2.greed.agent.compiler.c cannot be cast to java.net.URLClassLoader

Thank you

Bob M


 
 Post subject: Re: Error message explanation Post rating: 0   New post Posted: Tue 03 May, 2016, 07:14 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
//all psuedo code i.e. will not compile
Class Shape
{
   abstract Integer area(); // must be implemented in a child class
   abstract void printSides(); // must be implemented in a child class
}

Class EqualateralTriangle extends Shape
{
   Integer area() // implements Shape.area() for regular triangles
   {
      return (sqrt(3) / 4) * sqr(side);
   }

   void printSides() // implements Shape.printSides() for regular triangles
   {
      print(side); // 3 equal sides
      print(side);
      print(side);
   }
}
.
.
Shape shp;
EqualateralTriangle t = new EqualateralTriangle(4);

system.print(t.area()); // valid output of 6.93
shp = t; // make use of the EqualateralTriangle t via shp which is a Super class (and so valid) referencing variable.
shp.area(); //valid because a EqualateralTriangle IS (extends) a Shape
.
.

CASTING:
Class ShapePrinter
{
   void printShape(Shape s)
   {
      //We don't know what shape (EqualateralTriangle, Square, Circle) we will get so interface incoming object using a 'Shape' reference
      s.printSides();
   }
}

String str = new String();
EqualateralTriangle t = new EqualateralTriangle(4);
Shape shp = t;
ShapePrinter sp = new ShapePrinter();

sp.printShape((Shape)t); //(Shape) converts EqualateralTriangle perspective of 't' into a Shape perspective i.e. it CASTS ET into S
sp.printShape(shp); // shp is a 'Shape' perspective on t since an ET IS an S
sp.printShape(t); // in this situation, compiler knows an ET IS an S so the casting is done implicitly
sp.printShape(str); // No such method accepting a String
sp.printShape((Shape)str); // <--- java.lang.String cannot be cast into Shape.
sp.printShape(sp); // No such method accepting a ShapePrinter
sp.printShape((Shape)sp); // <--- ShapePrinter cannot be cast into Shape.

So in your case you might have a method that accepts a URLClassLoader e.g.
Class Profiler
{
   static void LoadClassToProfile(URLClassLoader ucl) //static so don't create a Profiler just use 'Profiler.method()'
   {
      //blah... blah...
   }
}

somewhere in your code you might have a URLClassLoader:
URLClassLoader u = new StandardURLClassLoader("https://myserver.com/trading/bin/mystrategy.class"); //Think Shape/EqualateralTriangle, a StandardURLClassLoader IS a URLClassLoader

you might also have one of those greed compiler objects in your code:
com.dukascopy.dds2.greed.agent.compiler.c comp = new com.dukascopy.dds2.greed.agent.compiler.c(); //variable here is 'comp'

with this in place you might try:
Profiler.LoadClassToProfile(u); //valid use of your URLClassLoader

or
Profiler.LoadClassToProfile(comp); //compiler will complain that LoadClassToProfile expects a URLClassLoader and no method found that accepts anything else

which might lead to a CAST attempt to beat the error
Profiler.LoadClassToProfile((URLClassLoader)comp); //java.lang.ClassCastException:com.dukascopy.dds2.greed.agent.compiler.c cannot be cast to java.net.URLClassLoader


Some methods do not specify the type of objects they take explicitly, e.g:
Class Profiler
{
   static void LoadClassToProfile(Object someClassLoader) //<---- generic OBJECT type to hold reference to ALL incoming class types
   {
      //use Java Reflection to CAST 'someClassLoader' into the java.net.URLClassLoader object we ultimately expect
      //if 'someClassLoader' happens to be a String, Greed Compiler, anything other than an instance of URLClassLoader (or one of it's sub-class type)
      //then we get an error of the form: <Actual CLASS TYPE of 'someClassLoader'> cannot be cast to java.net.URLClassLoader
   }
}


Hope you understand the underlying idea a bit better.


 
 Post subject: Re: Error message explanation Post rating: 0   New post Posted: Tue 10 May, 2016, 20:19 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi C S

Nice to see you again..................

Thank's for painting the picture......I do understand the process a little better :)

The solution was a single line added to the onStart method (suggested by University of Waikato - weka people)

viz:-

System.setProperty("weka.test.maventest", "true")


Kind regards

Bob M


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com