Search code examples
javaswingswingworker

I am stuck with a compilation error in Swing Worker?


I wrote a class that extends SwingWorker. I wrote overriden functions: doInBackground, done, and process, but for some reason I am getting compilation error:

The method process(List) of type BillImportAnalyzerGUI.Task must override or implement a supertype method

Here is my class:

  private class Task extends SwingWorker<Void, Void>
  {
    @Override
    public Void doInBackground()
    {
      try
      {
        generateReport(BillImportId.getText());
      }
      catch (InterruptedException e)
      {
      }
      catch (Exception e)
      {
      }

      publish();

      return null;
    }

    @Override
    protected void done()
    {
      try
      {
        jLabel6.setText("Generated Report");
      }
      catch (Exception ignore)
      {
      }
    }

    @Override
    protected void process(List<String> chunks)
    {
      jLabel6.setText("Generating Report");
      jProgressBar1.setVisible(true);
    }
  }

Solution

  • The problem is that you're extending SwingWorker<Void,Void> but you're declaring the method as process(List<String> chunks).

    You should extend SwingWorker<Void,String> in this case.