# ClassCastException

**URL:** https://discourse.processing.org/t/classcastexception/36290
**Category:** Processing.py
**Created:** [April 12, 2022, 2:31am UTC](https://discourse.processing.org/t/classcastexception/36290 "2022-04-12T02:31:03Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![XSun](https://avatars.discourse-cdn.com/v4/letter/x/ecd19e/32.png) [@XSun](https://discourse.processing.org/u/XSun)
#### Post date: [April 12, 2022, 2:31am UTC](https://discourse.processing.org/t/classcastexception/36290/1 "2022-04-12T02:31:03Z")

</div>

Hi everyone,

I’m trying to import a class from a separate file. I got ClassCast Exception message. Can anyone help me out? Thank you!

```auto
add_library('pdf')
from Sq import Sq
colorList=["#F5AD27","#D86D6D","#9CFCA1","#C3CBA0","#9CFCA1"]
squares = []
def setup():
    size(500,500)
    background(255)
    
    noStroke()
    beginRecord(PDF,"Output/test.pdf")
    squares.append(Sq(0,0,width))
    noLoop()
def draw():

    drawSquare(3)
    for squ in squares:
        squ.display()
    endRecord()
    
def drawSquare(res):
    tempSquares=[]
    
    
    if res > 1:
        for squ in squares:
            tempSquares.append(squ.x,squ.y,squ.s/2,res)
            tempSquares.append(squ.x+squ.s/2,squ.y,squ.s/2,res)
            tempSquares.append(squ.x,squ.y+squ.s/2,squ.s/2,res)
            tempSquares.append(squ.x+squ.s/2,squ.y+squ.s/2,squ.s/2,res)
        squares=tempSquares
        res-=1
        drawSquare(res)

```

separate file with class:

```auto
class Sq:
    def __init__ (self,x,y,s):
        self.x=x
        self.y=y
        self.s=s
    def display(self):
        fill(colorList[int(random(len(colorList)))])
        square(self.x,self.y,self.s)

```

error message:  
ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader ‘bootstrap’)  
at jycessing.LibraryImporter.addJarToClassLoader(LibraryImporter.java:315)  
at jycessing.LibraryImporter.recursivelyAddJarsToClasspath(LibraryImporter.java:164)  
at jycessing.LibraryImporter.addLibrary(LibraryImporter.java:140)  
at jycessing.LibraryImporter$1. **call** (LibraryImporter.java:82)  
at org.python.core.PyObject. **call** (PyObject.java:480)  
at org.python.core.PyObject. **call** (PyObject.java:484)  
at org.python.pycode.\_pyx163.f$0(recursions\_square.pyde:1)  
at org.python.pycode.\_pyx163.call\_function(recursions\_square.pyde)  
at org.python.core.PyTableCode.call(PyTableCode.java:171)  
at org.python.core.PyCode.call(PyCode.java:18)  
at org.python.core.Py.runCode(Py.java:1614)  
at org.python.core.Py.exec(Py.java:1658)  
at org.python.pycode.\_pyx162.f$0(/var/folders/4c/vx4wkqss45zb24tf5y56vbxw0000gn/T/recursions\_square5125658006693551092/recursions\_square.pyde:96)  
at org.python.pycode.\_pyx162.call\_function(/var/folders/4c/vx4wkqss45zb24tf5y56vbxw0000gn/T/recursions\_square5125658006693551092/recursions\_square.pyde)  
at org.python.core.PyTableCode.call(PyTableCode.java:171)  
at org.python.core.PyCode.call(PyCode.java:18)  
at org.python.core.Py.runCode(Py.java:1614)  
at org.python.core.Py.exec(Py.java:1658)  
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)  
at jycessing.PAppletJythonDriver.processSketch(PAppletJythonDriver.java:233)  
at jycessing.PAppletJythonDriver.findSketchMethods(PAppletJythonDriver.java:613)  
at jycessing.Runner.runSketchBlocking(Runner.java:399)  
at jycessing.mode.run.SketchRunner.lambda$2(SketchRunner.java:112)  
at java.base/java.lang.Thread.run(Thread.java:833)
