We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So, here is how this nightmare of mine goes. I am using Android Studio, using Processing, I get to create sketches without a problem, everything great. The problem is when in one of my sketches I try to load a file, an SVG file in order to create a PShape, the app doesn't know where the "data" folder is, and the problem is, I don't know where should I locate such folder or how to targer the file within my code. Thanks a lot.
import processing.core.PApplet;
import processing.core.PShape;
import processing.core.PVector;
public class Menu extends PApplet {
/**************************************************/
//icon:
PShape icon;
/**************************************************/
public void settings()
{
size(displayHeight, displayHeight);
}
/**************************************************/
public void setup()
{
icon = loadShape("menu.svg"); //here is where an error occurs;
}
/**************************************************/
public void draw()
{
background(0);
}
/**************************************************/
Answers
Some tags about it:
I've looked at most of them. Thanks.
I found this
It gave me hope but is not working for me.
Sorry I dunno much about Android nor IntelliJ. :(
Thanks though :) ( :'v )
This works in eclipse:
icon = loadShape("android_asset/menu.svg");
or this next link might help: https://forum.processing.org/two/discussion/comment/69746/#Comment_69746
Kf
Hi, thanks for the cooperation, I tried to do as it was done in that link, I just don't know. To be honest, am not sure of what to do:
Thanks every one for the support, I feel confused and desperate.
@SAFR===
as you are using AS i suppose you can add the android svg lib that you can find there::
https://code.google.com/archive/p/svg-android/
(or other one:: https://github.com/TrevorPage/TPSVG_Android_SVG_Library
Put your SVG in an assets folder. (you can also get it from an url or from res folder, drawable);
get the svg using assetsManager && parse it (code for the first lib)
AssetManager assets = getActivity().getContext().getAssets(); SVG mySvg = SVGParser.getSVGFromAsset(assets, "my.svg"); Then create an imageView and add your svg to it as a drawable.
Alright, I installed the library, am in the middle of the
getActivity( )
issue, is not the first time it happens. Let me just get rid of this issue and I continue your answer (am not sure of how to). It says "Cannot resolve method 'getActivity()' "... What I understand is that, if it is and Activity that method won't work:Thanks for your support. I will solve this issue...
@SAFR===
first error is an unhandled one:: add a try catch or a throws
second error is because you have probably not imported the Activity android class
I added the
try and catch
, that problem is gone. I really don't understand why is thegetActivity( )
method not found. I did import the Activity class and yet, same problem... Thanks.@SAFR=== Sometimes P5 is saying "cannot resolve..." and it is not true... try to launch your code on a device && tell me if it crashes (&& with what error) try also to add this.getActivity()....
Sorry to tell you this but, it doesn't work (either with
this.getActivity( )
). Another question, do I still have to useloadShape( )
?, if so, how do I linkmySvg
?...Again, the
getActivity( )
is not found :( I want to get rid of this error. Thanks a gain.I just tried something, first of all, I am so sorry for making you work on this. I tried the original method,
loadShape( )
with a different SVG file, and it worked... Thanks to all. Sorry.