我遇到了Mono for Android的问题,并在ImageView
中添加了drawable作为背景图片或图片资源。我的可绘制文件夹中有一个名为LogoLarge.png
的文件,我想显示它。其Build Action
设置为AndroidResource
。所以我试试这个:
<ImageView
android:id="@+id/Logo"
android:src="@drawable/LogoLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
LogoLarge
中引用了Resource.Designer.cs
资源。构建项目工作正常。当我尝试部署到模拟器时,我在构建输出中得到以下内容:
C:\Program Files (x86)\MSBuild\Novell\mandroid.exe -v --nosign --sdk-dir="C:\Android" --builddir="C:\Users\Vegard\Documents\Visual Studio 2010\Projects\HelloAndroid\HelloWorld2\obj\Debug\android" --framework-dir="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v2.2" --framework-dir="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0" -S="C:\Users\Vegard\Documents\Visual Studio 2010\Projects\HelloAndroid\HelloWorld2\obj\Debug\res" --package="HelloWorld2.HelloWorld2" --nolink --abi="armeabi" --java-sdk-dir="C:\Program Files\Java\jdk1.6.0_26" --debug --manifest-template="C:\Users\Vegard\Documents\Visual Studio 2010\Projects\HelloAndroid\HelloWorld2\Properties\AndroidManifest.xml" --sdk-platform="8" "C:\Users\Vegard\Documents\Visual Studio 2010\Projects\HelloAndroid\HelloWorld2\bin\Debug\HelloWorld2.dll" "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v2.2\Mono.Android.dll" "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\mscorlib.dll" "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Core.dll" "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.dll" "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Xml.dll" "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Xml.Linq.dll"
monodroid : error 1: System.NullReferenceException: Object reference not set to an instance of an object [C:\Users\Vegard\Documents\Visual Studio 2010\Projects\HelloAndroid\HelloWorld2\HelloWorld2.csproj]
at MonoDroid.Utils.ProcessRocks+<ReadStandardOutput>c__Iterator5.MoveNext () [0x00000] in <filename unknown>:0
at Monodroid.Toolbox.InvokeCommand (IEnumerable`1 commandLine) [0x00000] in <filename unknown>:0
at Monodroid.Toolbox.InvokeAapt (System.String packageName) [0x00000] in <filename unknown>:0
at Monodroid.Droidinator.CreatePackagedResources (System.Collections.Generic.List`1 javaTypes) [0x00000] in <filename unknown>:0
at Monodroid.Droidinator.CreateApk () [0x00000] in <filename unknown>:0
at Monodroid.MainClass.Main (System.String[] argv) [0x00000] in <filename unknown>:0
Done Building Project "C:\Users\Vegard\Documents\Visual Studio 2010\Projects\HelloAndroid\HelloWorld2\HelloWorld2.csproj" (SignAndroidPackage target(s)) -- FAILED.
如果我从XML文件中删除android:src
属性,并将其放在我的Activity1.cs
文件中,则可以正常运行:
ImageView i = FindViewById<ImageView>(Resource.Id.Logo);
i.SetImageResource(Resource.Drawable.LogoLarge);
尝试使用XML中的android:background="@drawable/SomeBackground"
为任何视图设置背景图像时也会出现同样的问题,但在以编程方式执行时效果正常。
这里发生了什么。这是MonoDroid中的错误吗?
答案 0 :(得分:2)
我认为您的LogoLarge必须是logolarge,因为您只能在drawable中使用小写字母。