Issue
I am trying to create a new PDF file in the public Documents folder. iTex7 is launched directly from a Dialog created by an external library com.afollestad.materialdialogs.MaterialDialog.
lateinit var writer : PdfWriter
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).absolutePath
val file = File(path + "/" + filename + ".pdf")
if (!file.parentFile.exists()) file.parentFile.mkdirs()
writer = PdfWriter(file)
pdf = PdfDocument(writer)
Sometiems this leads to an error:
Fatal Exception: java.lang.UnsupportedOperationException: AbstractITextEvent is only for internal usage.
at com.itextpdf.commons.actions.AbstractITextEvent.<init>(AbstractITextEvent.java:52)
at com.itextpdf.commons.actions.AbstractProductITextEvent.<init>(AbstractProductITextEvent.java:41)
at com.itextpdf.commons.actions.AbstractContextBasedITextEvent.<init>(AbstractContextBasedITextEvent.java:43)
at com.itextpdf.commons.actions.AbstractProductProcessITextEvent.<init>(AbstractProductProcessITextEvent.java:50)
at com.itextpdf.kernel.actions.events.ITextCoreProductEvent.<init>(ITextCoreProductEvent.java:53)
at com.itextpdf.kernel.actions.events.ITextCoreProductEvent.createProcessPdfEvent(ITextCoreProductEvent.java:69)
at com.itextpdf.kernel.pdf.PdfDocument.open(PdfDocument.java:1947)
at com.itextpdf.kernel.pdf.PdfDocument.<init>(PdfDocument.java:273)
at com.itextpdf.kernel.pdf.PdfDocument.<init>(PdfDocument.java:254)
at com.afollestad.materialdialogs.callbacks.DialogCallbackExtKt.invokeAll(DialogCallbackExtKt.java:68)
at com.afollestad.materialdialogs.MaterialDialog.onActionButtonClicked$core(MaterialDialog.java:406)
at com.afollestad.materialdialogs.internal.button.DialogActionButtonLayout$onFinishInflate$1.onClick(DialogActionButtonLayout.kt:84)
at android.view.View.performClick(View.java:6659)
at android.view.View.performClickInternal(View.java:6631)
at android.view.View.access$3100(View.java:790)
at android.view.View$PerformClick.run(View.java:26187)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
Any help? Sorry I am a beginner in programming.
Solution
If you are using Proguard then add a line to "proguard-rules.pro" (app module):
-keep public class com.itextpdf.**
Answered By - Tolikol
Answer Checked By - Katrina (JavaFixing Volunteer)