Comments (5)
Your code is fine.
The exact code that performs the copy is this one:
public static boolean copyAsset(Context ctx, String assetName, String destinationPath) throws IOException{
InputStream in = ctx.getAssets().open(assetName);
File f = new File(destinationPath);
f.createNewFile();
OutputStream out = new FileOutputStream(new File(destinationPath));
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
in.close();
out.close();
return true;
}
You could call this function and copy the assets on SD card by yourself, without using a CopyAsset object. You can then log what getAssets() and open() are returning, and find the error.
It never happened to me. If you find a trace where the code is failing, post it so I can review what's going on.
from pdfviewpager.
Hi again,
have you finally managed to read the assets folder? was just curious about the root cause of this issue.
from pdfviewpager.
Code
public class PDFViewPagerActiivty extends Activity {
PDFViewPager pdfViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
pdfViewPager = (PDFViewPager) findViewById(R.id.pdfViewPagerZoom);
}
@Override
protected void onDestroy() {
super.onDestroy();
BasePDFPagerAdapter adapter = (BasePDFPagerAdapter) pdfViewPager.getAdapter();
if(adapter != null) {
adapter.close();
adapter = null;
}
}
}
Layout --------------------
<es.voghdev.pdfviewpager.library.PDFViewPager
android:id="@+id/pdfViewPagerZoom"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:assetFileName="adobe.pdf"
/>
ERROR
java.io.FileNotFoundException: No such file or directory
W/System.err: at android.os.Parcel.openFileDescriptor(Native Method)
W/System.err: at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:270)
W/System.err: at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:200)
W/System.err: at es.voghdev.pdfviewpager.library.adapter.BasePDFPagerAdapter.getSeekableFileDescriptor(BasePDFPagerAdapter.java:98)
W/System.err: at es.voghdev.pdfviewpager.library.adapter.BasePDFPagerAdapter.init(BasePDFPagerAdapter.java:62)
W/System.err: at es.voghdev.pdfviewpager.library.adapter.BasePDFPagerAdapter.(BasePDFPagerAdapter.java:56)
W/System.err: at es.voghdev.pdfviewpager.library.adapter.PDFPagerAdapter.(PDFPagerAdapter.java:37)
W/System.err: at es.voghdev.pdfviewpager.library.PDFViewPager.initAdapter(PDFViewPager.java:62)
W/System.err: at es.voghdev.pdfviewpager.library.PDFViewPager.init(PDFViewPager.java:57)
W/System.err: at es.voghdev.pdfviewpager.library.PDFViewPager.(PDFViewPager.java:37)
W/System.err: at java.lang.reflect.Constructor.newInstance(Native Method)
W/System.err: at android.view.LayoutInflater.createView(LayoutInflater.java:619)
W/System.err: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
W/System.err: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
W/System.err: at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
W/System.err: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
W/System.err: at android.transition.Scene.enter(Scene.java:175)
W/System.err: at com.android.internal.policy.PhoneWindow.transitionTo(PhoneWindow.java:451)
W/System.err: at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:391)
W/System.err: at android.app.Activity.setContentView(Activity.java:2166)
W/System.err: at com.app.android.cync.SplashActiivty.onCreate(SplashActiivty.java:24)
W/System.err: at android.app.Activity.performCreate(Activity.java:6237)
W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
W/System.err: at android.app.ActivityThread.-wrap11(ActivityThread.java)
W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:148)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[ 06-09 06:57:04.955 28201:28201 D/ ]
HostConnection::get() New Host Connection established 0xab0f2da0, tid 28201
loaded /system/lib/egl/libEGL_emulation.so
/system/lib/egl/libGLESv1_CM_emulation.so
loaded /system/lib/egl/libGLESv2_emulation.so
[ 06-09 06:57:05.079 28201:28240 D/ ]
HostConnection::get() New Host Connection established 0xab0f2e80, tid 28240
I/OpenGLRenderer: Initialized EGL, version 1.4
W/EGL_emulation: eglSurfaceAttrib not implemented
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xab0ebcc0, error=EGL_SUCCESS
E/System: Uncaught exception thrown by finalizer
E/System: java.lang.NullPointerException: Attempt to invoke virtual method 'void dalvik.system.CloseGuard.warnIfOpen()' on a null object reference
at android.graphics.pdf.PdfRenderer.finalize(PdfRenderer.java:210)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:202)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:185)
at java.lang.Thread.run(Thread.java:818)
from pdfviewpager.
@narendra9593: Maybe you are trying to open the file before the copy has completed? You can, for example, set the adapter to the PdfViewPager once the copy has been completed, or open the activity once the copy has been done.
from pdfviewpager.
Example code of my last comment:
CopyAsset copyAsset = new CopyAssetThreadImpl(getApplicationContext(), new Handler(), new CopyAsset.Listener() {
@Override
public void success(String assetName, String destinationPath) {
pdfViewPager = new PDFViewPager(context, getPdfPathOnSDCard(Environment.getExternalStorageDirectory()));
setContentView(pdfViewPager);
}
@Override
public void failure(Exception e) {
e.printStackTrace();
}
});
Full example available here
Let me know if it helps
from pdfviewpager.
Related Issues (20)
- PDF Not loaded properly HOT 1
- Renderer PDF with mosaic HOT 1
- JCenter is depreceated, please move this lib to other supported repo HOT 1
- Save the last page viewed
- Password protected pdf files crash the app HOT 1
- How to make PDF scroll vertically and total number of pages? HOT 1
- Get Item Info in the vertical scrolling
- Veracode Scan reported External Control of File Name or Path (CWE ID 73) issue
- OOM
- Could you add VerticalPDFViewPager in old version,I can't use androidx HOT 1
- Pdf not load every time
- Flip animation
- Repo is not available HOT 1
- 切换闪烁
- PDF selected text
- Rendering boxes included in PDF
- OnPageClickListener cannot be reached
- free doc viewer support view word excel ppt pdf txt image in sdcard & uri & assets & url download here https://github.com/Victor2018/DocViewer
- Fit view with zoom
- Remote PDF preview, unable to display official seal and electronic signature
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdfviewpager.