I am having an issue with Mono for Android and adding drawables as background images or image resources in an ImageView
. I have a file in my drawable folder called LogoLarge.png
, which I want to display. Its Build Action
is set to AndroidResource
. So I try this:
<ImageView
android:id="@+id/Logo"
android:src="@drawable/LogoLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
The LogoLarge
resource is referenced in Resource.Designer.cs
. Building the project works fine. When I try to deploy to the emulator, I get the following in the build output:
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.CreateAp开发者_开发知识库k () [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.
If I remove the android:src
property from the XML file, and put this in my Activity1.cs
file, it works:
ImageView i = FindViewById<ImageView>(Resource.Id.Logo);
i.SetImageResource(Resource.Drawable.LogoLarge);
The same issue also occurs when trying to set a background image for any view using android:background="@drawable/SomeBackground"
in XML, but works fine when doing it programmatically.
What is happening here. Is this a bug in MonoDroid?
I think that your LogoLarge must be logolarge , because you only can use lower case letters in the drawables.
精彩评论