java.lang.NoClassDefFoundError:未能解析:Landroid/webkit/PacProce



真的找不到单词,我的项目只是没有从一天编译到另一天。

这就是我所做的:

我下载并显示了一个PDF,后来我将其作为保存的PDF打印到设备上,然后崩溃了。

这是崩溃:

at java.lang.Class java.lang.Class.classForName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:-2)
at java.lang.Class java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:453)
at java.lang.Class android.webkit.WebViewFactory.getWebViewProviderClass(java.lang.ClassLoader) (WebViewFactory.java:176)
at java.lang.Class android.webkit.WebViewFactory.getProviderClass() (WebViewFactory.java:459)
at android.webkit.WebViewFactoryProvider android.webkit.WebViewFactory.getProvider() (WebViewFactory.java:251)
at android.webkit.WebViewFactoryProvider android.webkit.WebView.getFactory() (WebView.java:2681)
at void android.webkit.WebView.ensureProviderCreated() (WebView.java:2676)
at void android.webkit.WebView.setOverScrollMode(int) (WebView.java:2741)
at void android.view.View.<init>(android.content.Context) (View.java:4815)
at void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int) (View.java:4956)
at void android.view.ViewGroup.<init>(android.content.Context, android.util.AttributeSet, int, int) (ViewGroup.java:659)
at void android.widget.AbsoluteLayout.<init>(android.content.Context, android.util.AttributeSet, int, int) (AbsoluteLayout.java:55)
at void android.webkit.WebView.<init>(android.content.Context, android.util.AttributeSet, int, int, java.util.Map, boolean) (WebView.java:659)
at void android.webkit.WebView.<init>(android.content.Context, android.util.AttributeSet, int, int) (WebView.java:604)
at void android.webkit.WebView.<init>(android.content.Context, android.util.AttributeSet, int) (WebView.java:587)
at void android.webkit.WebView.<init>(android.content.Context, android.util.AttributeSet) (WebView.java:574)
at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:343)
at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:647)
at android.view.View com.android.internal.policy.PhoneLayoutInflater.onCreateView(java.lang.String, android.util.AttributeSet) (PhoneLayoutInflater.java:58)
at android.view.View android.view.LayoutInflater.onCreateView(android.view.View, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:720)
at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:788)

(实际错误太长,我无法将其发布在stackoverflow中,而且这些都不是我自己的代码,它与Android的网络视图有问题。(


以下是发生崩溃的活动代码:

public class ActivityPrintSurvey extends ActivityBase implements MVPView, View.OnClickListener, SendScannedSignedDocumentTask.SendScannedSignedDocumentCallback {

Document document;
Patient patient;
SurveyBundle surveyBundle;
View hider;
Button printBtn;
Button backBtn;
WebView webView;
ProgressBar progressBar;
Switch switcher;
boolean canPrint = false;
PrintManager printManager;
String jobName;
String fileName;
String pdfUrl;
String showPdfUrl;
private int SIGNING_DONE_1 = 105;
int runnableCounter = 0;
final int RUNNABLE_MAX = 3;
private void log(Object o) {
Log.i("PRINTING_ACT", o.toString());
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_print_survey);

log("activity started");
hider = findViewById(R.id.hider);
printBtn = findViewById(R.id.print_btn);
backBtn = findViewById(R.id.back_btn);
webView = findViewById(R.id.web_view);
progressBar = findViewById(R.id.progressbar);
switcher = findViewById(R.id.read_and_accepted_switch);

document = (Document) getIntent().getSerializableExtra("document");
patient = (Patient) getIntent().getSerializableExtra("patient");
surveyBundle = (SurveyBundle) getIntent().getSerializableExtra("survey_bundle");
jobName = this.getString(R.string.app_name) + " Document";
printManager = (PrintManager) this.getSystemService(Context.PRINT_SERVICE);
printBtn.setOnClickListener(this);
backBtn.setOnClickListener(this);

showPDF();
}

private void showPDF() {
log("starting to show pdf");
pdfUrl = document.getPdfUrl();
String embedUrl = "https://docs.google.com/gview?embedded=true&url=";
showPdfUrl = embedUrl + pdfUrl;
progressBar.setVisibility(View.VISIBLE);
hider.setVisibility(View.VISIBLE);
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
if (runnableCounter < RUNNABLE_MAX) {
runnableCounter++;
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(showPdfUrl);
handler.postDelayed(this, 1000);
//Szörnyűséges a helyzet, az android szemét használhatatlan webview nem mindig jeleníti meg a pdf-et, ezért rá kell frissíteni párszor, hogy biztos megjelenítse, ez van.
} else {
progressBar.setVisibility(View.GONE);
hider.setVisibility(View.GONE);
}
}
};
handler.post(runnable);
downloadPDF();
}

public void downloadPDF() {
log("starting to download pdf");
fileName = FileHelper.generateTempFileName();
ANRequest.DownloadBuilder downloadBuilder = AndroidNetworking.download(pdfUrl, FileHelper.getTempFileDirectory(this), fileName);
downloadBuilder.doNotCacheResponse();
ANRequest request = downloadBuilder.build();
request.setDownloadProgressListener(new DownloadProgressListener() {
@Override
public void onProgress(long bytesDownloaded, long totalBytes) {
// do anything with progress
Log.i("ON_PROGRESS", bytesDownloaded + " / " + totalBytes);
}
}).startDownload(new DownloadListener() {
@Override
public void onDownloadComplete() {
// do anything after completion
canPrint = true;
}
@Override
public void onError(ANError error) {
// handle error
Toast.makeText(ActivityPrintSurvey.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
public void print() {
log("starting to print");
printManager.print(jobName, new PrintDocumentAdapter() {

@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
InputStream input = null;
OutputStream output = null;
log("onWrite() called for printing");
try {
File file = FileHelper.readTempFile(ActivityPrintSurvey.this, fileName);
input = new FileInputStream(file);
output = new FileOutputStream(destination.getFileDescriptor());
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES});
log("onWriteFinished() called for printing");
} catch (Exception e) {
//Catch exception
e.printStackTrace();
log("Exception 1: " + e.getMessage());
} finally {
try {
input.close();
output.close();
} catch (IOException e) {
e.printStackTrace();
log("Exception 2: " + e.getMessage());
}
}
}
@Override
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
log("onLayout() done");
if (cancellationSignal.isCanceled()) {
callback.onLayoutCancelled();
log("onLayoutCancelled()");
return;
}
PrintDocumentInfo pdi = new PrintDocumentInfo.Builder(fileName/*Ez itt lehet bármi, kiskutya füle, nem kell megegyeznie az alap file nevvel*/).setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build();
callback.onLayoutFinished(pdi, true);
log("onLayoutFinished() called");
}
@Override
public void onFinish() {
FileHelper.deleteTempFiles(ActivityPrintSurvey.this);
log("onFinish() done");
// ha kész a nyomtatás, jöhet a valós aláírás tollal, majd visszafotózás, és feltöltés
new AlertDialog.Builder(ActivityPrintSurvey.this)
.setTitle(getString(R.string.next_step))
.setMessage(getString(R.string.please_scan_the_printed_and_signed_document))
.setPositiveButton(getString(R.string.scan), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
startScanningByCameraPhoto();
}
})
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.show();
log("showing alert dialog");
}
}, null);
}
public void startScanningByCameraPhoto() {
// start picker to get image for cropping and then use the image in cropping activity
CropImage.activity()
.setGuidelines(CropImageView.Guidelines.ON)
.start(this);
log("startScanningByCameraPhoto");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
log("onActivityResult called");
if (resultCode == Activity.RESULT_OK) {
if (requestCode == SIGNING_DONE_1) {
log("RESULT_OK from SIGNING_DONE_1 -> calling .finish()");
Intent intent = new Intent();
intent.putExtra("document", document);
setResult(Activity.RESULT_OK, intent);
finish();
}
} else {
log("1. Error: resultCode NOT RESULT OK");
}
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
log("RESULT_OK from CROP_IMAGE_ACTIVITY_REQUEST_CODE");
Uri resultUri = result.getUri();
File file = new File(resultUri.getPath());
showLoading();
SendScannedSignedDocumentTask task = new SendScannedSignedDocumentTask(this, this, DatabaseHelper.getInstance().readLoggedInUser().getUserToken(), document, patient, file);
task.execute();
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
log("2. Error: resultCode NOT RESULT OK: " + error.getMessage());
error.printStackTrace();
}
}
}

@Override
public void handleUploadScannedDocumentAPIDone(String error) {
hideLoading();
if (error != null) {
log("handleUploadScannedDocumentAPIDone, error:" + error);
DialogHelper.showInfo(this, error);
} else {
log("handleUploadScannedDocumentAPIDone -> finishing()");
setResult(Activity.RESULT_OK);
Toast.makeText(this, "✔ " + getString(R.string.uploaded), Toast.LENGTH_LONG).show();
finish();
}
}
@Override
public void onClick(View v) {
if (v.equals(printBtn)) {
if (switcher.isChecked()) {
if (canPrint) {
print();
} else {
Toast.makeText(this, "PDF not found in device. Retrying download...", Toast.LENGTH_LONG).show();
downloadPDF();
}
} else {
DialogHelper.showInfo(this, getString(R.string.please_check_the_checkbox));
}
} else if (v.equals(backBtn)) {
onBackPressed();
}
}
public void hideLoading() {
progressBar.setVisibility(View.GONE);
}
@Override
public void showLoading() {
progressBar.setVisibility(View.VISIBLE);
}
@Override
public void showError(String error, String code) {
hideLoading();
canPrint = false;
DialogHelper.showError(this, error);
log("showing error: " + error);
}

@Override
public void showSuccess(Object... object) {
hideLoading();
String api = object[0].toString();
if (api.equals("eject_patient")) {
log("showSuccess: " + "finishing activity.");
Intent intent = new Intent(this, ActivityWaitingForPatient.class);
startActivity(intent);
finish();
} else {
log("showSuccess: " + "ERROR: " + api + " not equals " + "eject_patient");
}
}

@Override
public void onResume() {
super.onResume();
LayoutTextSizeChanger.changeAllTextSizeInLayout((ViewGroup) findViewById(R.id.main_cont), FontUtil.loadFontSize(this));
log("onResume()"  );
}

}

运行时在应用程序中使用WebView时,我遇到了同样的异常和巨大的堆栈跟踪,具体取决于设备上安装的软件版本:

Chrome版本:

  • 96.0.4664.92/.104-正常,没有错误
  • 97.0.4692.98-错误,见下文

Android版本:

  • 安卓7->android.webkit.TracingController的NoClassDefFoundError
  • 安卓9->android.webkit.PacProcessor的NoClassDefFoundError
  • 安卓12->没有这样的错误

根据您的描述和堆栈跟踪,您在运行时看到这个错误,而不是在编译时,对吧?所以,我建议

  • 在Android 12目标上测试
  • 安装较旧的Chrome版本

嗯。。。引用类加载器问题的间歇性问题。+巨大的堆栈痕迹。

您提供的少量证据可能指向静默IO类型的错误。

例如,你使用的android在运行时动态加载类,出于某种原因,它试图使用的任何jar的主机文件夹也包含主动写入/读取的pdf文件。。。或者由于任何原因,整个fileSystem分区都被标记为锁定。

在这种情况下,您最终会遇到间歇性的类加载器错误,就像您引用的那个错误一样。

还有这个:

try {
input.close(); <--- if exception occurs at this point, output will never close.
output.close();
} catch (IOException e) {
e.printStackTrace();
log("Exception 2: " + e.getMessage());
}

我不知道。。。老实说,可供参考的信息很少。例如,您没有发布finish()例程的内容,并且堆栈跟踪不包含对代码的引用(至少我可以看到(。。。所以这是一种在黑暗中疯狂的刺。

最新更新