我采用了 F# 的 Xamarin OpenGL 示例应用程序,并尝试从 XML 加载(网格)数据。我已将 XML 文件添加到Resources/values
并将其构建操作设置为,AndroidResource
但是当我尝试读取它时出现异常。
我正在使用这个 F# 代码来尝试读取文件:
context.Resources.GetXml Resource_String.n
wherecontext
是MainActivity
传入的类型的对象GLView1
。
我得到的例外是:
08-03 12:18:23.931 V/GLCube (29315): ***** at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in <filename unknown>:0
08-03 12:18:23.931 V/GLCube (29315): at Android.Content.Res.Resources.GetXml (Int32 id) [0x00000] in <filename unknown>:0
08-03 12:18:23.931 V/GLCube (29315): at AndroidOpenGLFSharp.GLView1..ctor (AndroidOpenGLFSharp.MainActivity context) [0x00000] in <filename unknown>:0
08-03 12:18:23.931 V/GLCube (29315): --- End of managed exception stack trace ---
08-03 12:18:23.931 V/GLCube (29315): android.content.res.Resources$NotFoundException: File 8 from xml type xml resource ID #0x7f040000
08-03 12:18:23.931 V/GLCube (29315): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2351)
08-03 12:18:23.931 V/GLCube (29315): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2306)
08-03 12:18:23.931 V/GLCube (29315): at android.content.res.Resources.getXml(Resources.java:983)
08-03 12:18:23.931 V/GLCube (29315): at androidopenglfsharp.MainActivity.n_onCreate(Native Method)
08-03 12:18:23.931 V/GLCube (29315): at androidopenglfsharp.MainActivity.onCreate(MainActivity.java:30)
08-03 12:18:23.931 V/GLCube (29315): at android.app.Activity.performCreate(Activity.java:5133)
08-03 12:18:23.931 V/GLCube (29315): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-03 12:18:23.931 V/GLCube (29315): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-03 12:18:23.931 V/GLCube (29315): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-03 12:18:23.931 V/GLCube (29315): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-03 12:18:23.931 V/GLCube (29315): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-03 12:18:23.931 V/GLCube (29315): at android.os.Handler.dispatchMessage(Handler.java:99)
08-03 12:18:23.931 V/GLCube (29315): at android.os.Looper.loop(Looper.java:137)
08-03 12:18:23.931 V/GLCube (29315): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-03 12:18:23.931 V/GLCube (29315): at java.lang.reflect.Method.invokeNative(Native Method)
08-03 12:18:23.931 V/GLCube (29315): at java.lang.reflect.Method.invoke(Method.java:525)
08-03 12:18:23.931 V/GLCube (29315): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-03 12:18:23.931 V/GLCube (29315): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-03 12:18:23.931 V/GLCube (29315): at dalvik.system.NativeStart.main(Native Method)
08-03 12:18:23.931 V/GLCube (29315): Caused by: java.io.FileNotFoundException: 8
08-03 12:18:23.931 V/GLCube (29315): at android.content.res.AssetManager.openXmlAssetNative(Native Method)
08-03 12:18:23.931 V/GLCube (29315): at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:488)
08-03 12:18:23.931 V/GLCube (29315): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2333)
08-03 12:18:23.931 V/GLCube (29315): ... 18 more
08-03 12:18:24.001 V/PhoneStatusBar( 1201): setLightsOn(true)
08-03 12:18:24.021 V/GLCube (29315): Loading with default settings
我究竟做错了什么?