locked
Unhandeld Exeption error when using Uri

    Question

  • Hi. im a beginner in wp app development and was following a tutorial for building

    a simple app that loaded up images on the screen when pushing a button.

    but when i clicked the button the app freezed and some kind of debugger says "user-code Unhandled Exeption"!

    what is going on?

    this is the code.

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Media.Imaging;
    using Windows.UI.Xaml.Navigation;
    
    // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
    
    namespace PhotoLock
    {
        
        public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
    
                this.NavigationCacheMode = NavigationCacheMode.Required;
            }
    
           
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
               
            }
    
            private void myButton_Click(object sender, RoutedEventArgs e)
            {
                myImage.Source = new BitmapImage(new Uri("/Images/MEEEEE.jpg", UriKind.Relative));
            }
        }
    }

    Saturday, August 30, 2014 12:46 PM

Answers

  • Only absolute URI are accepted as documented here: http://msdn.microsoft.com/en-us/library/hh763341.aspx

    Provided that you have added the image MEEEEE.jpg to a folder called Image in your project, the following code should work:

    private void myButton_Click(object sender, RoutedEventArgs e)
            {
                myImage.Source = new BitmapImage(new Uri("ms-appx:/Images/MEEEEE.jpg", UriKind.Absolute));
            }
    

    Saturday, August 30, 2014 2:01 PM

All replies

  • Only absolute URI are accepted as documented here: http://msdn.microsoft.com/en-us/library/hh763341.aspx

    Provided that you have added the image MEEEEE.jpg to a folder called Image in your project, the following code should work:

    private void myButton_Click(object sender, RoutedEventArgs e)
            {
                myImage.Source = new BitmapImage(new Uri("ms-appx:/Images/MEEEEE.jpg", UriKind.Absolute));
            }
    

    Saturday, August 30, 2014 2:01 PM
  • Thank You!. This problem has bugged me for Weeks!

    Wonder why they use the UriKind.Relative in the msdn documentation 

    Saturday, August 30, 2014 3:40 PM