Android load & read properties file in library project - java

I have android & rest webservice api binary project
OnlineCourse
src
res
lib
manifest.xml
CourseAPI
src
config.properties
build.xml
Android project right click -> property -> java build path -> project ->Add select CourseAPI project. That all i did.
My problem is courseAPI project contain property file & java file read values.When I run only courseAPi project working file , read property file.
But when I run the android project, that binary java file couldn't read file. It say FileNotFoundException
Please guide me what is an issue

To read the properties file, you have to put the properties file in main project.

Related

How to read a file in android studio project folder?

I am new to android and it seems I cannot get a filepath of a file within the project structure.
I have a text file "db-info.txt", that I am trying to read from a class. Every method I tried has said no file found. This file I am trying to read from a java class within the same folder.
Any help is appreciated. Here is where my file is within the project -

Uploading app to Web App Engine in IntelliJ

I'm trying to deploy my app to Web App Engine. I have WAE module in web part of my project; there is a path specified in Modules/web/Google App Engine:
/Users/Kamil/IdeaProjects/appengine-java-sdk-1.9.12/
Although when I click on we in general (Modules/web/"Paths" tab), I see following settings:
Output path:
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/classes
The problem is:
When I click "Upload Web App Engine Application" following error appears:
Bad configuration: Could not locate
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/appengine-web.xml
I don't get it why it tries to search in wrong directory, not the one specified in Modules. Please advise.
Edit
I noticed that in Modules/web/"Sources" tab whole folder named "target" is excluded. Maybe that's the problem?
According to the error message
Bad configuration: Could not locate
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/appengine-web.xml
, the deployment code is looking for appengine-web.xml, a crucial config file for your App Engine app. It's looking for that file here:
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/appengine-web.xml
Is it possible that the file
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/appengine-web.xml
could not be located ("Bad configuration: Could not locate ") because the file
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/appengine-web.xml
does not exist?
The path /Users/Kamil/IdeaProjects/appengine-java-sdk-1.9.12/ is the path to your SDK, not the target folder, and is not related to this issue.
The target file is excluded from "sources" because "sources" is the location of files that are included as source code into the build. The target folder is the opposite of source files - it's the flattened-out WAR archive that is used to deploy your app. The deployment tool you use will pack it up into a .war file and send that to the App Engine data centers.
Finally, the output path folder .../classes is where the compiled .java files that turn into .class files for your app are put.
I think you should look into some tutorials on IntelliJ and App Engine to make sure that your project was created and configured properly.
Good luck!
One you can do that locate build folder in explorer and delete it. After that reopen android studio build it again and run it. Now every thing is fine.

Issue file assets Libgdx

I have a problem to load a file from assets.
In pratcise I have to load TiledMap file and I do it in this way:
arrayTiledMap.add(new TmxMapLoader().load(Gdx.files.internal("scenario.tmx").path())));
(I add it in array for other reason)
In the project the tmx file(scenario.tmx) is located in the android assets folder.
When I execute the program in Eclipse there aren't problems , but when I create the JAR file for Desktop project and I execute it I get this error on console(I launch it by terminal):
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: Documents/University/Programming/Street.png (Internal)
The file Street.png is a file that I used in tiledMap editor for create the map.
At this point I check the JAR file contents and In the root directory of JAR there is the Documents folder and in it there is University folder and so on.
Because if the path is in the JAR file I get this error?
What is that wrong?
Thank you very much for your time, this error is driving me crazy
If you need other code, in particular, tell me.
(although I do not think since the problem only occurs when loading the file)
Because if the path is in the JAR file I get this error?
No. Its most likely you aren't exporting the JAR correctly.
File -> Export -> Java -> Runnable JAR File
And be sure to check this:
package required libraries into generated JAR.

How to upload images and xml file into a maven project in eclipse

I'm working on a videogame with a my friend. We are working with Eclipse and we are using maven. We use BitBucket to synchronize the project but now we have a problem. I'm doing the GUI but I don't know how to upload the images and an xml file in the project and synchronize this with bitbucket. Now I'm using the path of the file that is on my desktop. There is a way to load all the files and import these into the project? I'm searching a solution that is correct also when we must export the project in a jar file.
Place the files in the source folder resources, and access them not as File, but as
URL url = getClass().getResource("/a/b/c.png");
// URL "..... myproject.jar!/a/b/c,png"
or direct as:
InputStream in = getClass().getResourceAsStream("/d.xml");
Case-sensitive.
This zips the files together with the .class code in the jar file.

Access external files (Outside of AVD device) using Android JUnit

I am using Robotium to automate Android application. Created a android test project for the same. Inside project folder I want to keep some files like .properties/.xls etc. and want to read from /write to those files. For example, I have one config.properties file under my Android test project directory (src/main/java/config) and I want to access that file through coding:
For normal Java project I used following code snippet to load config.properties file:
CONFIG = new Properties();
FileInputStream fs = new FileInputStream(System.getProperty("user.dir")+"/src/main/java/config/config.properties");
CONFIG.load(fs);
This same code - when executed as Android JUnit project throwing error saying java.io.FileNotFoundException: //src/main/java/config/config.properties: open failed: ENOENT (No such file or directory) and unable to locate the file.
If anyone faced this anytime before please help me to get through.
Thanks
Sitam Jana
Software QA Enginner
Mindfire Solutions
You cannot access the internal structure of your java project that way. When you install your apk on the device, your java code gets converted to dex code for the Dalvik Virtual Machine, and you won't have the file structure from your project.
You can try the following:
If you only want to read the config.properties you should use the http://developer.android.com/reference/android/content/res/AssetManager.html class, and put your config.properties in /assets/ in your project.
If you also want to write your .properties file, consider creating a temporary file like this: Creating temporary files in Android.
Best Regards.

Categories