Hello,

I've run across a problem trying to retrieve an image from the web and
decode the stream or byte array into a bitmap/drawable resource.  Each
one of the tests below fail when I try to invoke the static
BitmapFactory or BitmapDrawable class.  I'm running my tests in
MonoDevelop on Mac OSX Lion targeting API Level 8 with Mono for
Android 1.2.

The exception I receive for test 1:
System.NullReferenceException: Object reference not set to an instance
of an object
  at Android.Runtime.JNIEnv.get_Handle () [0x00014] in
/Volumes/Macintosh
HD/Users/jon/Development/xamarin/monodroid/Mono.Android/src/Runtime/JNIEnv.cs:33
  at Android.Runtime.JNIEnv.get_Env () [0x00000] in /Volumes/Macintosh
HD/Users/jon/Development/xamarin/monodroid/Mono.Android/src/Runtime/JNIEnv.cs:24
  at Android.Runtime.JNIEnv.FindClass (System.String classname)
[0x00000] in /Volumes/Macintosh
HD/Users/jon/Development/xamarin/monodroid/Mono.Android/src/Runtime/JNIEnv.cs:145
  at Android.Graphics.BitmapFactory..cctor () [0x00000] in <filename unknown>:0


The exception I receive for test 2:
System.NullReferenceException: Object reference not set to an instance
of an object
  at Android.Runtime.JNIEnv.get_Handle () [0x00014] in
/Volumes/Macintosh
HD/Users/jon/Development/xamarin/monodroid/Mono.Android/src/Runtime/JNIEnv.cs:33
  at Android.Runtime.JNIEnv.get_Env () [0x00000] in /Volumes/Macintosh
HD/Users/jon/Development/xamarin/monodroid/Mono.Android/src/Runtime/JNIEnv.cs:24
  at Android.Runtime.JNIEnv.FindClass (System.String classname)
[0x00000] in /Volumes/Macintosh
HD/Users/jon/Development/xamarin/monodroid/Mono.Android/src/Runtime/JNIEnv.cs:145
  at Android.Graphics.BitmapFactory..cctor () [0x00000] in <filename unknown>:0

The exception I receive for test 3:
System.NullReferenceException: Object reference not set to an instance
of an object
  at Android.Runtime.JNIEnv.get_Handle () [0x00014] in
/Volumes/Macintosh
HD/Users/jon/Development/xamarin/monodroid/Mono.Android/src/Runtime/JNIEnv.cs:33
  at Android.Runtime.JNIEnv.get_Env () [0x00000] in /Volumes/Macintosh
HD/Users/jon/Development/xamarin/monodroid/Mono.Android/src/Runtime/JNIEnv.cs:24
  at Android.Runtime.JNIEnv.FindClass (System.String classname)
[0x00000] in /Volumes/Macintosh
HD/Users/jon/Development/xamarin/monodroid/Mono.Android/src/Runtime/JNIEnv.cs:145
  at Android.Graphics.Drawables.Drawable..cctor () [0x00000] in
<filename unknown>:0

Any help would be greatly appreciated.

Regards,
John

//////////////////////////////////////////////////////////

using System;
using System.Net;

using Android.Graphics;
using Android.Graphics.Drawables;

using NUnit.Framework;

namespace App.Shared.Test
{
        [TestFixture]
        public class ImageTest
        {
                private string url =
"http://www.google.com/intl/en_com/images/srpr/logo3w.png";;
                
                [Test]
                public void TestStreamWithBitmapFactory()
                {
                        try
                        {
                                System.IO.Stream stream = new 
WebClient().OpenRead(url);
                                var bitmap = BitmapFactory.DecodeStream(stream);
                                Assert.IsNotNull(bitmap);
                        }
                        catch (Exception ex)
                        {
                                Console.WriteLine(ex.InnerException);
                                Assert.Fail(ex.InnerException.ToString());
                        }
                        
                }
                
                [Test]
                public void TestBytesWithBitmapFactory()
                {
                        try
                        {
                                byte[] bytes = new 
WebClient().DownloadData(url);
                                var bitmap = 
BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);
                                Assert.IsNotNull(bitmap);
                        }
                        catch (Exception ex)
                        {
                                Console.WriteLine(ex.InnerException);
                                Assert.Fail(ex.InnerException.ToString());
                        }
                }
                
                [Test]
                public void TestStreamWithBitmapDrawable()
                {
                        try
                        {
                                System.IO.Stream stream = new 
WebClient().OpenRead(url);
                                var bitmap = 
BitmapDrawable.CreateFromStream(stream, "src");
                                Assert.IsNotNull(bitmap);
                        }
                        catch (Exception ex)
                        {
                                Console.WriteLine(ex.InnerException);
                                Assert.Fail(ex.InnerException.ToString());
                        }
                }
        }
}
_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to