Open benthemobileguy opened 5 years ago
folioReader.openBook(file.getPath()+ "/title");
Why "/title"?
I just edited my question. please review
Is the filename is with epub extension?
yeah. it has the .epub extension.As a matter of fact it opens up from the asset folder. I want to post more of my stack trace error. that I think might be useful.
05-27 08:58:05.514 16925-16925/com.ben.thevoicebooks E/Error: Could not generate container java.lang.Exception: Missing File at org.readium.r2.streamer.parser.EpubParser.generateContainerFrom(EpubParser.kt:52) at org.readium.r2.streamer.parser.EpubParser.parse(EpubParser.kt:71) at com.folioreader.ui.activity.FolioActivity.initBook(FolioActivity.kt:477) at com.folioreader.ui.activity.FolioActivity.setupBook(FolioActivity.kt:447) at com.folioreader.ui.activity.FolioActivity.onCreate(FolioActivity.kt:296) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) 05-27 08:58:05.514 16925-16925/com.ben.thevoicebooks E/FolioActivity: -> Failed to initialize book kotlin.KotlinNullPointerException at com.folioreader.ui.activity.FolioActivity.initBook(FolioActivity.kt:493) at com.folioreader.ui.activity.FolioActivity.setupBook(FolioActivity.kt:447) at com.folioreader.ui.activity.FolioActivity.onCreate(FolioActivity.kt:296) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) 05-27 08:58:05.544 16925-16925/com.ben.thevoicebooks E/EGL_emulation: tid 16925: eglSurfaceAttrib(1199): error 0x3009 (EGL_BAD_MATCH) 05-27 08:58:05.554 16925-16925/com.ben.thevoicebooks E/UncaughtException: java.lang.IllegalStateException: menu.findItem(R.id.itemSearch) must not be null at com.folioreader.ui.activity.FolioActivity.onCreateOptionsMenu(FolioActivity.kt:365) at android.app.Activity.onCreatePanelMenu(Activity.java:2538) at androidx.fragment.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:378) at androidx.appcompat.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:94) at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.onCreatePanelMenu(AppCompatDelegateImpl.java:2549) at androidx.appcompat.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:94) at androidx.appcompat.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:455) at androidx.appcompat.app.ToolbarActionBar$1.run(ToolbarActionBar.java:56) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) 05-27 08:58:05.764 16925-16925/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.ben.thevoicebooks, PID: 16925 java.lang.IllegalStateException: menu.findItem(R.id.itemSearch) must not be null at com.folioreader.ui.activity.FolioActivity.onCreateOptionsMenu(FolioActivity.kt:365) at android.app.Activity.onCreatePanelMenu(Activity.java:2538) at androidx.fragment.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:378) at androidx.appcompat.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:94) at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.onCreatePanelMenu(AppCompatDelegateImpl.java:2549) at androidx.appcompat.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:94) at androidx.appcompat.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:455) at androidx.appcompat.app.ToolbarActionBar$1.run(ToolbarActionBar.java:56) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)
This error is thrown when the epub file you are trying to open doesn't exist on that path.
So, how do I get the reference to this path?
--getFileStreamPath(fileName);
You are opening the book which is in Assets? or which is in your SD card?
I am opening the book from my internal storage
the documentation does not explain how to open epub files from android internal storage
it's as simple as calling folioReader.open(sdCardPath) Can you check the path of the file and that file exist in your android device on that path?
it exists. but I still keep getting the error
I finally resolved my issue. I discovered from my device file explorer that my files were saved as .txt instead of .epub extension. After converting them, it worked smoothly with this code:
var path: String = context.getFilesDir().getAbsolutePath()
Thanks for your effort!
I saved a file to my internal storage with this path: file = getFileStreamPath(fileName); I am attempting to access the file with this line of code but it keeps crashing my app each time:
FolioReader folioReader = FolioReader.get(); File file = getFileStreamPath(fileName); Log.e("file: ", "file: " + file.getAbsolutePath()); folioReader.openBook(file.getPath());
This is the error it gives: Unknown book file extension
fileName
. What do I do?