我正在尝试在我的android应用程序中运行Processing草图。在此草图中,我需要访问SVG
位于我的raw
目录中的文件。我不知道如何访问该文件,即使该文件位于目录“数据”中(就像它在“处理”中的工作方式一样)也根本不起作用。检查以下示例代码:
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);
}
/**************************************************/
更新
错误信息:
---------
beginning of crash
09-07 07:36:07.503 2939-2986/letalis.safr.com.letalis E/AndroidRuntime: FATAL EXCEPTION: Animation Thread
Process: letalis.safr.com.letalis, PID: 2939
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String processing.data.XML.getString(java.lang.String)' on a null object reference
at processing.core.PShapeSVG.<init>(Unknown Source)
at processing.core.PShapeSVG.<init>(Unknown Source)
at processing.core.PGraphicsAndroid2D.loadShape(Unknown Source)
at processing.core.PApplet.loadShape(Unknown Source)
at letalis.safr.com.letalis.Esquech_Menu.setup(Esquech_Menu.java:111)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PSurfaceNone.callDraw(Unknown Source)
at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source)
09-07 07:36:07.578 2939-2952/letalis.safr.com.letalis W/EGL_emulation: eglSurfaceAttrib not implemented
09-07 07:36:07.578 2939-2952/letalis.safr.com.letalis W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xacb7f860, error=EGL_SUCCESS
09-07 07:36:07.592 2939-2952/letalis.safr.com.letalis E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaebf1150
09-07 07:36:07.734 2939-2952/letalis.safr.com.letalis W/EGL_emulation: eglSurfaceAttrib not implemented
09-07 07:36:07.735 2939-2952/letalis.safr.com.letalis W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xab2c9da0, error=EGL_SUCCESS
09-07 07:36:07.942 2939-2952/letalis.safr.com.letalis V/RenderScript: 0xa21fe000 Launching thread(s), CPUs 2
09-07 07:36:08.053 2939-2952/letalis.safr.com.letalis E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaebf1230
加载形状可能不是问题。您没有在屏幕上绘制SVG形状。menu.svg应该位于Menu.pde所在项目的根目录。请参见下面的屏幕截图。我显示了svg文件所在的位置。
import processing.core.PApplet;
import processing.core.PShape;
import processing.core.PVector;
public class Menu extends PApplet {
/**************************************************/
//icon:
PShape icon;
/**************************************************/
public void settings()
{
size(400, 400);
}
/**************************************************/
public void setup()
{
icon = loadShape("Ghostscript_Tiger.svg");
}
/**************************************************/
public void draw()
{
shape(icon, 50, 50, 300, 300); // need to draw the shape you loaded
}
/**************************************************/
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句