Image source not found error

5 posts, 1 answers
  1. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 19 Oct Link to this post

    Hi,

     

    I am trying to show an image in  xaml page  from a local file, but it is throwing null object reference error. This happens only on project with telerik libraries.  I was able to reporduce this issue by adding a new xaml page in QSF project that comes with installer.   Is there any extra steps needed to make Xamarinforms  render image ?

    <Image AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0.5, 0, 100, 100" Rotation="30" Source="reorder_icon.png" />

    <Image  HorizontalOptions="End" >
                            <Image.Source >
                                 <OnPlatform x:TypeArguments="Image">
                                        <OnPlatform.iOS><FileImageSource File="reorder_icon.png"/></OnPlatform.iOS>
                                        <OnPlatform.Android><FileImageSource File="reorder_icon.png"/></OnPlatform.Android>
                                        <OnPlatform.WinPhone><FileImageSource File="Images/reorder_icon.png"/></OnPlatform.WinPhone>
                                  </OnPlatform>
                            </Image.Source>
                          </Image>

    Regards,

    Prava

  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    138 posts

    Posted 20 Oct Link to this post

    Hello Prava,

    This issue is unrelated to Telerik UI for Xamarin. You can go here to get assistance with general Xamarin Forms programming problems like this in the future.

    Although you state that it only happens in a project referencing Telerik libraries, the error should occur in any Xamarin Forms application. This is because you have the incorrect TypeArgument set, it should be ImageSource not Image:

    <OnPlatform x:TypeArguments="ImageSource">

    Additionally, to confirm that this is not a Telerik based conflict, I've attached a screenshot of your code running in a demo project that is referencing all of the UI for Xamarin DLLs.

    Another tip I can provide is for you to review this documentation and make sure you have your images in the right places and that they're using the proper Build action. (i.e. AndroidResource, BundledResource and Content). 

    I also wanted to briefly touch on the topic of your current license status. You appear to be a valid DevCraft Complete Licensed User however this does not include UI for Xamarin. Since your trial for UI for Xamarin has expired, you're limited to only submitting forum posts and will not be able to publish or distribute your application with the trial DLLs.

    I recommend that you reach out to the person who assigned you as a licensed user and have you upgraded to DevCraft Ultimate which includes a license for UI for Xamarin. This would let you submit full support Tickets instead of Forum Posts (Support Tickets have a guaranteed response time) and you'll be able to compile your application with the full developer licensed DLLs.

    Let me know if you have any further questions or if you would like assistance with the upgrade. Thank you for your understanding and for contacting Telerik Support!

    Regards,
    Lance | Tech Support Engineer, Sr.
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 25 Oct in reply to Lance | Tech Support Engineer, Sr. Link to this post

    Hi,

    I did look into Xamarin forum for similar issues but later found that it was not a Xamarin problem. I am still unable to open a project with image. I modified'Transitions.xaml"  page  in SDKBrowser project and it is throwing null object error.  Images I used are telerik images that are referenced din toolbars. Can you kindly attach a working Telerik project?

     

    Regards,

    Prava

     

     <Grid BackgroundColor="Gray">
              <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                  <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
              </Grid.RowDefinitions>
                  <Label Text="Transition Type:"/>
               <Image  HorizontalOptions="End" >
                          <Image.Source >
                                    <OnPlatform x:TypeArguments="ImageSource">
                                              <OnPlatform.iOS><FileImageSource File="image.png"/></OnPlatform.iOS>
                                              <OnPlatform.Android><FileImageSource File="image.png"/></OnPlatform.Android>
                                              <OnPlatform.WinPhone><FileImageSource File="image.png"/></OnPlatform.WinPhone>
                                    </OnPlatform>
                          </Image.Source>
                   </Image>
                
                  <Picker Grid.Row="1" x:Name="picker" SelectedIndexChanged="picker_SelectedIndexChanged">
                    <Picker.Items>
                      <x:String>Push</x:String>
                      <x:String>Reveal</x:String>
                      <x:String>ReverseSlideOut</x:String>
                      <x:String>ScaleUp</x:String>
                      <x:String>SlideAlong</x:String>
                      <x:String>SlideInOnTop</x:String>
                    </Picker.Items>
                  </Picker>
                  <Label Grid.Row="2" x:Name="descritpionLabel">
                  </Label>
                  <Button Text="Open SideDrawer" IsVisible="false" x:Name="button1"/>
            </Grid>

     

    Thanks,

    Prava

     

     

  5. Answer
    Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    138 posts

    Posted 26 Oct Link to this post

    Hello Prava,

    I built you a File > New > Telerik enabled Xamarin Forms app (Android, iOS and WP8 only) and used your exact code below. Note that because you didn't provide an image for image.png, I created one and add it to the project (it is critical that these directions are followed when using local image files).

    Here is how to get the project working:

    - Download, extract the zip and open the solution in Visual Studio
    - Right click on the solution and select "Manage Nuget Packages for solution..." and restore all packages
    - Right click on the PravaImageTestApp.Portable project and select Build
    - Right click on the PravaImageTestApp.Android project and select "Set as Startup Project"
    - Right click on the PravaImageTestApp.Android project and select "Rebuild"

    At this point, the project is ready to deploy to an Android Emulator or device. Once you deploy it you will see the application running as seen in my attached screenshot.


    Next Steps

    If you are still having trouble, please update my attached example app so that it replicates your problem and send it back to us. This will effectively isolate the issue and allow us to debug the problem directly. 


    "Telerik Related" Clarification

    To clarify what I meant about what is not related to Telerik was the general programming issue surrounding using <OnPlatform>, this you had incorrectly set and would cause an error. This is considered general Xamarin Forms programming.

    Additionally, the use of images in a Xamarin Forms application isn't directly related to the Telerik components.

    To help you diagnose what's wrong with your image files, there are some things you need to ensure in order for images not to throw an error. Here are some of the top items right from Xamarin's documentation:

    Image files can be added to each application project and referenced from Xamarin.Forms shared code. To use a single image across all apps, the same filename must be used on every platform, and it should be a valid Android resource name (ie. only lowercase letters, numerals, the underscore, and the period are allowed).

    • iOS - Place images in the Resources folder with Build Action: BundleResource . Retina versions of the image should also be supplied - two and three times the resolution with a @2x or @3x suffixes on the filename before the file extension (eg. myimage@2x.png).
    • Android - Place images in the Resources/drawable directory with Build Action: AndroidResource. High- and low-DPI versions of an image can also be supplied (in appropriately named Resources subdirectories such as drawable-ldpi ,drawable-hdpi , and drawable-xhdpi ).
    • Windows Phone - Place images in the application's root directory with Build Action: Content .
    • Windows/UWP - Place images in the application's root directory with Build Action: Content .

    The one exception to keeping the same filename is if you are using OnPlatform and explicitly set the filename and path. It is critical that you added the images to the correct location and set the BuildAction appropriately.

    Go here and follow the steps in this Xamarin Forms documentation to get your images working.


    Examples Apps

    I'd also like to clarify what the Telerik example application is for.  It is meant to be used as a reference, something you can review and apply the example implementations in your application.

    It is not meant to be edited directly and then used as your application, this falls under custom implementation and is outside the scope of normal Telerik Support. If this is what you want, we can connect you to one of our Professional Services partners for consultation on custom implementations.


    Follow up

    If you have any further questions, please let us know. As I stated above, if you still cannot get your app to work after following the instruction on using Local Images, please send us an isolated reproducible app that we can debug directly and work on a solution for you.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Prava kafle
    Prava kafle avatar
    212 posts
    Member since:
    Apr 2010

    Posted 26 Oct in reply to Lance | Tech Support Engineer, Sr. Link to this post

    Hi,

    I identified problem in my project, it got fixed by including "Resource.Designer.cs" in project, somehow it got excluded from project.

     

    Thanks,

    Prava

     

Back to Top
DevCraft banner