Java Question (SOLVED) error: constructor File in class File cannot be applied to given types

Johan Schoeman

Expert
Licensed User
Longtime User
I am a bit lost here. I have opened the JAR of the below Library with JD-GUI and copied the code into notepad++. I want to modify the Java code and then recompile the code into a JAR. But when I use SLC (java 8) to compile it before making any changes to the code I get the following error:

Error:
error: constructor File in class File cannot be applied to given types

The original library works perfectly but after copying the code into a new Java project and compiling it with SLC it errors on this line:

Line that causes the compiling error.:
 File file = new File(paramString1, paramString2);

File file = new File (String, String) is a valid constructor.



Extracted from JAR using JD-GUI:
package com.palmosoft.palmohtmltopdf;

import android.os.Build;
import android.print.PdfPrint;
import android.print.PrintAttributes;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.streams.File;
import java.io.*;

@Author("Palmosoft")
@Version(1.0F)
@ShortName("PalmoHtmlToPdf")
@ActivityObject
public class HtmlToPdf {
  private WebView _webview;
 
  private BA mBa;
 
  private String mEventName;
 
  public void Initialize(BA paramBA, String paramString) {
    this.mEventName = paramString.toLowerCase(BA.cul);
    this.mBa = paramBA;
    this._webview = new WebView(this.mBa.context);
  }
 
  /*public void ConvertFromFile(String paramString1, String paramString2, final String DirectoryOutput, final String FilenameOutput) throws Exception {
    try {
      if (!fileExists(paramString1, paramString2)) {
        this.mBa.raiseEvent(this, this.mEventName + "_finished", new Object[] { Boolean.valueOf(false) });
      } else if (Build.VERSION.SDK_INT < 21) {
        this.mBa.raiseEvent(this, this.mEventName + "_finished", new Object[] { Boolean.valueOf(false) });
      } else {
        String str = Load(paramString1, paramString2);
        this._webview.setWebViewClient(new WebViewClient() {
              public void onPageFinished(WebView param1WebView, String param1String) {
                HtmlToPdf.this.createWebPrintJob(HtmlToPdf.this._webview, DirectoryOutput, FilenameOutput);
              }
            });
        if (str.startsWith("/"))
          str = "file:" + str;
        this._webview.loadUrl(str);
      }
    } catch (Exception exception) {
      this.mBa.raiseEvent(this, this.mEventName + "_finished", new Object[] { Boolean.valueOf(false) });
    }
  } */
 
  private boolean fileExists(String paramString1, String paramString2) {
    File file = new File(paramString1, paramString2);
    if (file == null || !file.exists())
      return false;
    return true;
  }
 
  public void ConvertFromString(String paramString1, final String DirectoryOutput, final String FilenameOutput) throws Exception {
    try {
      if (Build.VERSION.SDK_INT < 21) {
        this.mBa.raiseEvent(this, this.mEventName + "_finished", new Object[] { Boolean.valueOf(false) });
      } else {
        this._webview.setWebViewClient(new WebViewClient() {
              public void onPageFinished(WebView param1WebView, String param1String) {
                createWebPrintJob(_webview, DirectoryOutput, FilenameOutput);
              }
            });
        this._webview.getSettings().setJavaScriptEnabled(true);
        this._webview.loadDataWithBaseURL("", paramString1, "text/html", "UTF-8", "");
      }
    } catch (Exception exception) {
      this.mBa.raiseEvent(this, this.mEventName + "_finished", new Object[] { Boolean.valueOf(false) });
    }
  }
 
  @Hide
  private String Load(String paramString1, String paramString2) throws Exception {
    if (paramString1.equals(File.getDirAssets()))
      throw new Exception("HtmlToPdf: Cannot load file from assets");
    return File.Combine(paramString1, paramString2);
  }
 
  @Hide
  private void createWebPrintJob(WebView paramWebView, String paramString1, String paramString2) {
    String str1 = paramString2 + " Document";
    PrintAttributes printAttributes = (new PrintAttributes.Builder()).setMediaSize(PrintAttributes.MediaSize.ISO_A4).setResolution(new PrintAttributes.Resolution("pdf", "pdf", 600, 600)).setMinMargins(PrintAttributes.Margins.NO_MARGINS).build();
    File file = new File(paramString1);
    PdfPrint pdfPrint = new PdfPrint(printAttributes, this.mBa, this.mEventName);
    String str2 = paramString2.substring(paramString2.lastIndexOf("."));
    if (!str2.contentEquals(".pdf")) {
      paramString2 = paramString2.replace("." + str2, "");
      paramString2 = paramString2 + ".pdf";
    }
    pdfPrint.print(paramWebView.createPrintDocumentAdapter(str1), file, paramString2);
  }
}

Towards the end of the code it also errors on this line although it is also a valid constructor:
Also causes a compiling error:
File file = new File(paramString1);

Can anyone please point out what the reason for the error is when compiling it with SLC?
 
Top