I try to read/write a file data_quizz.xml situated in /data/data/com.my.package.app/files/data_quizz.xml. Using other topic I used adb to make /data and all subfolders in the data_quizz.xml path 777.
But when it comes to this line :
FileInputStream is = new FileInputStream("/data/data/com.my.package.app/files/data_quizz.xml");
I still get an error, this is the stacktrace :
java.io.FileNotFoundException: /data/data/com.my.package.app/files/data_quizz.xml (Permission denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:99)
at com.dautry.a16126734.quizzapp.XmlManager.<init>(XmlManager.java:43)
at com.dautry.a16126734.quizzapp.ChooseTopic.onCreate(ChooseTopic.java:27)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Edit : Correction of the initial path which were wrong
Thanks
Related
I am trying to copy SD card image file from my pc using InputStream, OutputStream, FileInputStream and FileOutputStream. But the error comes at FileOutputStream as the values we are passing to this is desktop folder. The code is
File file = new File(path); \\ where 'path' is the sd card image file path
File destFolder = new File("D:\\images\\"); \\ I know this path is not correct. IP address of PC is missing here
InputStream in = new FileInputStream(file);
OutputStream out = new FileOutputStream(destFolder);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
When we can copy files from one system to another system, which are on same network, why can't we do that from mobile to pc when they are also on the same network connected through wifi.
If with the above method is not possible then What is the method to do this.
error is:
05-25 20:06:20.836 2576-2576/com.example.user.storeimage E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.storeimage, PID: 2576
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.view.View$DeclaredOnClickListener.onClick(View.java:4452)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.io.FileNotFoundException: D:\images\: open failed: EROFS (Read-only file system)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
at com.example.user.storeimage.copyimagetopc.onClickSaveBtn(copyimagetopc.java:52)
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
at com.example.user.storeimage. copyimagetopc.onClickSaveBtn(copyimagetopc.java:52)
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
File works for filesystem paths, for the local filesystem. In the case of Android, the local filesystem is the Android device. There is no D:\\images\\ on an Android device. Android does not support mapping of SMB servers to filesystem paths.
If with the above method is not possible then What is the method to do this.
Either work with SMB directly (e.g., jCIFS) or find some app that exposes SMB servers through some sort of API (e.g., a ContentProvider).
As the following error and CommonsWare's answer, I think that you need to know that your mobile phone and your computer OS are in different hosts. So D:\\images\\ is pointting to the same host address. You need to point to your LAN address and use a protocol like samba or the same windows sharer to share a folder and giving permissions or you can use a Webserver like XAMPP and send the file as a encoded base 64 String and decode then in the xampp server with php and save it to a folder.
I'm programming a new app and I was trying with different versions. When I try in Nougat, my app doesn't open. It just says:
app has stopped. Open app again?
If I press open again, the app keeps stopping.
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 25
versionCode 1
versionName "2.0"
multiDexEnabled true
}
}
I tried with buildToolsVersion "25.0.1" and nope. Any help?
Here is my logcat trace when I try to open it in a Nougat device
05-10 09:49:35.119 4709-4709/app E/app: /storage/emulated/0/app/Registros/grupo-registros.csv (No such file or directory)
java.io.FileNotFoundException: /storage/emulated/0/app/Registros/grupo(demo)-registros.csv (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at java.io.FileOutputStream.<init>(FileOutputStream.java:140)
at app.MainActivity.onCreate(MainActivity.java:175)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
05-10 09:49:35.148 4709-4709/app D/AndroidRuntime: Shutting down VM
05-10 09:49:35.148 4709-4709/app E/AndroidRuntime: FATAL EXCEPTION: main
Process: app, PID: 4709
java.lang.RuntimeException: Unable to start activity ComponentInfo{es/app.MainActivity}: java.util.EmptyStackException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.util.EmptyStackException
at app.MainActivity.copyFileOrDir(MainActivity.java:434)
at app.MainActivity.addSubjectDemo(MainActivity.java:341)
at app.MainActivity.onCreate(MainActivity.java:231)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
EDIT: my manifest´s permission request
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
java.io.FileNotFoundException:/storage/emulated/0/app/Registros/grupo(demo)-registros.csv (No such file or directory)
That happens probably because in Nougat-Android 7.0 there are changes to permissions that may affect your app. It is not enforced, but it pops exception which you probably don't handle. You should read the documentation:
https://developer.android.com/about/versions/nougat/android-7.0-changes.html
And check this answers
Android 7.1 Write to text file
I am attempting to use a custom font in an Android app. I placed my font files under /app/src/main/assets/fonts, and I reference them with
Typeface.createFromAsset(getApplicationContext().getAssets(),
"fonts/magorian_font.ttf")
When I run my app, I get the error:
04-23 16:14:40.017 13342-13342/com.pottermore.mandrake.pottermoreapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pottermore.mandrake.pottermoreapp, PID: 13342
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pottermore.mandrake.pottermoreapp/com.pottermore.mandrake.pottermoreapp.ActivityHome}: java.lang.RuntimeException: Font asset not found magorian_font.ttf
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.RuntimeException: Font asset not found magorian_font.ttf
at android.graphics.Typeface.createFromAsset(Typeface.java:206)
at com.pottermore.mandrake.pottermoreapp.ActivityHome.onCreate(ActivityHome.java:34)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
What am I doing wrong?
add assets folder in this path : src/main/assets/font
and use this code :
Typeface typrface=Typeface.createFromAsset(getAssets(),"font/iranian_sans");
Text.setTypeface(typrface);
Update
ِDont Forget , you must copy ttf format of font in font folder
It should be look like this when you want to give a TextView a different font :)
private TextView yourtext;
yourtext= (TextView) findViewById(R.id.the_id_of_the_textview);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/magorian_font.ttf");
yourtext.setTypeface(tf);
I did these things:
1) Clean the code and remove everything in /build folder.
2) Analyse AndroidManifest.xml file all activities have proper package name as suffix
Multidex is already enabled
These are the Error Logs i got every time.:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.packagename, PID: 25752
java.lang.RuntimeException: Unable to instantiate application
com.android.packagename.BaseApplication:
java.lang.ClassNotFoundException: Didn't find class
"com.android.packagename.BaseApplication" on path: DexPathList[[zip
file
"/data/app/com.android.packagename-1/base.apk"],nativeLibraryDirectories=[/data/app/com.android.packagename-1/lib/arm64,
/system/lib64, /vendor/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:802)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:5377)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.android.packagename.BaseApplication" on path: DexPathList[[zip
file
"/data/app/com.android.packagename-1/base.apk"],nativeLibraryDirectories=[/data/app/com.android.packagename-1/lib/arm64,
/system/lib64, /vendor/lib64]]
at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at
android.app.Instrumentation.newApplication(Instrumentation.java:992)
at android.app.LoadedApk.makeApplication(LoadedApk.java:796)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:5377)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Ok try to install instant run for your target api
Or disable instant run from Android studio
More about instant run
Preferences->Build,Execution,Deployment->instant Run
then,
function
I'm trying to add a native dialog over a scene to play a video with exoplayer.
So far I've managed to show the dialog correctly but when I'm starting calling exoplayer stuff I get this exception in the logcat :
Caused by: java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/eppz/plugins/DemoPlayer; at
com.eppz.plugins.EPPZ_DialogFragment.preparePlayer(EPPZ_DialogFragment.java:96)
at
com.eppz.plugins.EPPZ_DialogFragment.onCreateView(EPPZ_DialogFragment.java:87)
at android.app.Fragment.performCreateView(Fragment.java:2352) at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
at android.app.BackStackRecord.run(BackStackRecord.java:815) at
android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:483) at
android.os.Handler.handleCallback(Handler.java:751) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:154) at
android.app.ActivityThread.main(ActivityThread.java:6077) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused
by: java.lang.ClassNotFoundException: com.eppz.plugins.DemoPlayer at
java.lang.VMClassLoader.findLoadedClass(Native Method) at
java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742) at
java.lang.ClassLoader.loadClass(ClassLoader.java:362) at
java.lang.ClassLoader.loadClass(ClassLoader.java:312) at
com.eppz.plugins.EPPZ_DialogFragment.preparePlayer(EPPZ_DialogFragment.java:96)
at
com.eppz.plugins.EPPZ_DialogFragment.onCreateView(EPPZ_DialogFragment.java:87)
at android.app.Fragment.performCreateView(Fragment.java:2352) at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
at android.app.BackStackRecord.run(BackStackRecord.java:815) at
android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:483) at
android.os.Handler.handleCallback(Handler.java:751) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:154) at
android.app.ActivityThread.main(ActivityThread.java:6077) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/android/exoplayer/ExoPlayer$Listener; at
com.eppz.plugins.EPPZ_DialogFragment.preparePlayer(EPPZ_DialogFragment.java:96)
at
com.eppz.plugins.EPPZ_DialogFragment.onCreateView(EPPZ_DialogFragment.java:87)
at android.app.Fragment.performCreateView(Fragment.java:2352) at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
at android.app.BackStackRecord.run(BackStackRecord.java:815) at
android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:483) at
android.os.Handler.handleCallback(Handler.java:751) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:154) at
android.app.ActivityThread.main(ActivityThread.java:6077) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.google.android.exoplayer.ExoPlayer$Listener" on path:
DexPathList[[zip file
"/data/app/com.eppz.plugins.alert-1/base.apk"],nativeLibraryDirectories=[/data/app/com.eppz.plugins.alert-1/lib/arm,
/data/app/com.eppz.plugins.alert-1/base.apk!/lib/armeabi-v7a,
/system/lib, /vendor/lib]] at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380) at
java.lang.ClassLoader.loadClass(ClassLoader.java:312) at
com.eppz.plugins.EPPZ_DialogFragment.preparePlayer(EPPZ_DialogFragment.java:96)
at
com.eppz.plugins.EPPZ_DialogFragment.onCreateView(EPPZ_DialogFragment.java:87)
at android.app.Fragment.performCreateView(Fragment.java:2352) at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
at android.app.BackStackRecord.run(BackStackRecord.java:815) at
android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:483) at
android.os.Handler.handleCallback(Handler.java:751) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:154) at
android.app.ActivityThread.main(ActivityThread.java:6077) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
I've just added a texture view and added exoplayer in my android part just like if it was a normal project.
I've no idea of what I can add so if you need more information feel free to ask :)
Any Idea ?
Regards,
You have to add a compiled version of ExoPlayer as an .aar or a .jar in your Unity project and it will work correctly.