Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

获取外部缓存目录可能导致应用崩溃 #29

Open
ruankao-mengxin opened this issue Sep 29, 2018 · 0 comments
Open

获取外部缓存目录可能导致应用崩溃 #29

ruankao-mengxin opened this issue Sep 29, 2018 · 0 comments

Comments

@ruankao-mengxin
Copy link

ruankao-mengxin commented Sep 29, 2018

`
private File getOutputMediaFile(String ext) {
ext = ext != null ? ext : "jpg";
File mediaStorageDir = getCurrentActivity().getExternalCacheDir();
if (mediaStorageDir == null) {
mediaStorageDir = getCurrentActivity().getCacheDir();
}
if (mediaStorageDir == null || (!mediaStorageDir.exists() && !mediaStorageDir.mkdirs())) {
return null;
}
String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date());
File mediaFile;
String mImageName = "RN_" + timeStamp + "." + ext;
mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName);
Log.d("path is", mediaFile.getPath());
return mediaFile;
}

`

`
FATAL EXCEPTION: mqt_native_modules
(link to log)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
03-10 12:49:00.577 2919 3008 E AndroidRuntime: Process: com.doquestion, PID: 2919
03-10 12:49:00.577 2919 3008 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.exists()' on a null object reference
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at me.vanpan.rctqqsdk.QQSDK.getOutputMediaFile(QQSDK.java:702)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at me.vanpan.rctqqsdk.QQSDK.getOutputMediaFile(QQSDK.java:696)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at me.vanpan.rctqqsdk.QQSDK.saveBitmapToFile(QQSDK.java:643)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at me.vanpan.rctqqsdk.QQSDK.processImage(QQSDK.java:512)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at me.vanpan.rctqqsdk.QQSDK.shareImage(QQSDK.java:224)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
03-10 12:49:00.577 2919 3008 E AndroidRuntime: at java.lang.Thread.run(Thread.java:818)

`

这是我修改后的获取缓存的方法,老的方法在某些没有外存的手机上可能导致CARSH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant