Win a copy of Penetration Testing Basics this week in the Security forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Process method not being executed eventhough publish is being called

April Easton
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working with a scanning application and there is a random problem where the pages don't get displayed in the GUI when scanned. The document does not need to contain multiple pages, the example is on a one page document. Once the problem occurrs, it will continue to happen on each document thereafter until the application is exited and restarted. I've added a bunch of log messages in the code to see what's happening and the publish() method is executed, but I never see the log messages for the process() method. I took over on this project a few months ago and have been learning swing on my own. I've been searching the web for clues, but to no avail. I've enjoyed reading some of the posts on this website and decided to create my post here. The code and log file are below.

//Code from GUI
JButton appendButton = new JButton("Append");
appendButton.setToolTipText("This will append inserted pages to the end of the file.");
appendButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (scanner == null || scanner.isDone()) {
insert = false;
replace = false;
pdfViewer.postMessage("Appending page...");
user.getLog().debug(":initializeLayout:Append action");
scanner = new Scanner();
user.getLog().debug(":initializeLayout:Append action after instaniate Scanner()");
user.getLog().debug(":initializeLayout:Append action after scanner.execute");
pdfViewer.postMessage("Appending complete...");

} else {
JOptionPane.showMessageDialog(null,"Currently Appending... Please wait");

//SwingWorker object
public class Scanner extends SwingWorker<Void,BufferedImage> {

public Scanner() {


public Void doInBackground() {
Source source = null;
try {
source = SourceManager.instance().getDefaultSource();
user.getLog().debug(":Scanner:doInBackground:source name:" + source.getSourceName());

if (source == null) return null;
//Set source options

do {
BufferedImage image = source.acquireImageAsBufferedImage();
user.getLog().debug(":Scanner:doInBackground:adf:retrieved image:" + image);
} while (source.hasMoreImages());
user.getLog().debug(":Scanner:doInBackground:adf:all images acquired.");

user.getLog().debug(":Scanner:doInBackground:saved image");

} catch(JTwainException jte) {

} catch(Exception e) {

} finally {
user.getLog().debug(":Scanner:doInBackground:source = null");
source = null;
return null;
} //doInBackground

protected void process(List<BufferedImage> images) {
try {
BufferedImage image = images.get(images.size() -1);
ScannedImage scannedImage = new ScannedImage(ImageUtility.bufferedImage2bytes(image), false, false);
user.getLog().debug(":Scanner:process:scannedImage done, check if");
user.getLog().debug(":Scanner:process:addImage done");
unSaved = true;

} catch (ImageUtilityException iue) {
user.getLog().debug(":Scanner:process done");
} //process
} //Scanner

//Log - there should be some Scanner:process log messages and there are not
01:53:52 DEBUG ocEditer$16:initializeLayout:Scan action unsaved = false
01:53:53 DEBUG ocEditer$Scanner:Scanner:doInBackground:source name:FUJITSU fi-4340Cd
01:53:54 DEBUG ocEditer$Scanner:Scanner:doInBackground:source state:4
01:53:54 DEBUG ocEditer$Scanner:Scanner:doInBackground:adf
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:adf:retrieved image
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:adf:publish
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:adf:all images acquired.
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:saveLastAcquiredImageIntoFile
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:saved image
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:finally
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:source = null
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:done
pete stein
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if you used a for-each loop in the process method to iterate through all the images. Perhaps something like so (warning: not compiled nor tested):

Also, please use code tags when posting code (see the FAQs).

Much luck!
April Easton
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That seemed to help most of my problem. The rest of the problem is that I'm getting a null value for the image I just scanned. I've contacted the vendor for that problem. Thank you a bunch for your help.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic