We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I started with a demo that uses a menu that allows to choose which sketch to run on android. I modified it to add my sketch to the menu. I took my sketch that works standalone on android and added it to the demo. My sketch reads a csv file and uses the data as input. Heres the link to the processing android demo: https://github.com/omerjerk/ProcessingAndroidDemo
When I add my sketch and the csv file to a /data directory, it crashes and I get a blue processing error message that says make sure the file URL is accessible or readable. The Java error is Nullpointerexception trying to determine the length of a null array. I tried putting the csv file in different project directories but it doesn't matter. I'm using Android studio if it matters.
Heres my code that I put in draw():
String[] starLines = loadStrings("stardata.csv");
println("Loaded " + starLines.length + " stars:");
Lat = (float)Latitude_1 + (float)Lat_minutes/60 + (float)Lat_seconds/3600; //Estimated Latitude
Lon = (float)Longitude_1 - (float)Lon_minutes/60 - (float)Lon_seconds/3600; //Estimated Longitude
if (Longitude_1 > 0) {
Lon = (float)Longitude_1 + (float)Lon_minutes/60 + (float)Lon_seconds/3600; //East of Greenwich
}
for ( i = 0 ; i < starLines.length; i++) {
String[] stars = splitTokens(starLines[i], ", ");
String proper = (stars[0]);
String con = (stars[1]);
double dec = PApplet.parseFloat(stars[2]);
double ra = PApplet.parseFloat(stars[3]);
double pmra = PApplet.parseFloat(stars[4]);
double pmdec = PApplet.parseFloat(stars[5]);
double rv = PApplet.parseFloat(stars[6]);
ra = ra * 15;
Star1 = Name1.getCaptionLabel().getText();
if (Star1 == "Procyon") {
z = 47;
....
Any ideas where stardata.csv should go in the project, so it is "accessible" ?
Answers
https://forum.processing.org/two/search?Search=Assets
Kf
@HarryCodes===
Put your file in the assets folder (create it); then get it using AssetManager
Strange, I added the csv file to the assets folder and it didn't read it. I added an assets folder inside the src folder and it read it without any additional code.
The problem now is that I'm using a library to work on the data from the csv and it says NullPointerException lock == null. Whole different problem now.
@HarryCodes===
AssetManager can be used for fragment. Can you put the code you are using?
I'm using the JPARSEC library, for astronomy. this link goes to the general page: conga.oan.es/~alonso/doku.php?id=jparsec#jparsec_for_android_platform
I am using the jparsec directory from the android clearsky source.
Here's the code for my sketch that I added to the processing android demo. The problem starts with the ObserverElement. It seems to be trying to read another file using Reader.java
I think I see why its not working with the demo. The difference is that the demo uses gradle and my sketch that worked was jammed into a project(the clearsky android example) imported from eclipse. Theres some kind of dependency issue maybe.
@HarryCodes===
You are perhaps right about dependencies; yet, looking to the code you have put and to the android demo code i think that .csv not found is the main problem: there are a lot of fiedls which ask for "star" and if this is undefined nothing can work; the other fiedls from android demo do not seem to make problems; as for the Observer you are right, this class has a lot of methods which return values from embedded data as . txt (list of cities, observatories, lat, lon....) but in the code of your applet you only call (for the observer) the clone() method which do not calculate any value, so i don't think that it is the problem you get now. Have you tried to import the android demo in AS??? - Does it work as-it-is???
Yup, processing android demo works fine with Android Studio -as-is. I just cant figure out how to effectively add jparsec to it.
If you drag the jar into your code in the PDE, then you should be able to access that library (Untested). This is how it works in Processing java and I would assume it is similar for Android mode. If you export the pde into AS, you should be able to see where the jar is located... I believe it will be in the libs folder.
One thing: Do you need to open your csv file in
draw()
? If not, move it tosetup()
.Regarding the assets, accessing files, dataPath(), etc. check this: https://forum.processing.org/two/discussion/comment/118947/#Comment_118947
Kf
@HarryCodes, @kfrajer===
-i think as kfrajer that it is not a good idea to get your csv in draw()
I got the @#$%^*&) to compile, install, run using Android Studio. The JPARSEC link I gave includes the Android example I mentioned above. I can get that to run all by itself. I snipped the libs and src directories from that and put them into this already imported processing for android project. The processing code I posted runs on Android now.
All the advice you guys gave wasn't necessarily the solution but it still helped, thanks.
What still does not work is adding the sketch to the android processing demo. The sketch will start but it cant read from various files so the textarea where the calculations are printed is blank. Android Studio shows the errors in logcat. It doesn't crash but doesn't read what it needs either.