#1st arg can't be coerced to java.awt.Frame

1 messages · Page 1 of 1 (latest)

wicked slate
#

Hello, I use Jython to write a script for ImageJ. Can somone help me?

I use:

saveOption = YesNoCancelDialog("YesNoCancel",DEFAULT_CURSOR,"a")```

to create a dialog, but since I cant find the type of attributes the method wants I get 
this error output:
`1st arg can't be coerced to java.awt.Frame`
https://imagej.net/ij/developer/api/ij/ij/gui/YesNoCancelDialog.html
vagrant plankBOT
#

<@&987246399047479336> please have a look, thanks.

wary oxide
#

Try putting new JPanel() before the first argument

#

If that doesn’t work, show us the constructor of YesNoCancelDialog

wicked slate
#

JPanel() is not defined in my case.
sry im pretty new, what is a constructor?

#
from ij.io import FileSaver
from ij.io import OpenDialog
from ij.gui import YesNoCancelDialog

import os

targetFile = OpenDialog("Choose the Target folder",None)

saveFile = OpenDialog("Choose the Save Folder",None)

saveOption = YesNoCancelDialog(I dont know what to put here)

for file in os.listdir(targetFolder):
    print(file)
    imp = IJ.openImage(file);

    IJ.run(imp, "Enhance Contrast", "saturated=0.35");
    IJ.run(imp, "Auto Threshold", "method=Default white");
    
    print(str(file[:-5]))
    IJ.saveAs(imp, "Tiff", targetFolder + str(file[:-5]) + "C");```
whole code
runic glacier
#

if you dont have a frame, you'd most likely use null, similar to a JOptionPane

#

something like YesNoCancelDialog(null, "Your Title", "Your Message")

wicked slate
#

null is not defined

runic glacier
#

if so, post the actual error

wicked slate
wicked slate
runic glacier
#

use None for python

#

it wouldnt be the 2nd argument

#

you'd specify None as the value for the parent (the frame)

#

did you look at the docs?

wicked slate
#

it works now thanks