Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8348409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:40:51+00:00 2026-06-09T07:40:51+00:00

I am creating a library for image loading and caching. I want the user

  • 0

I am creating a library for image loading and caching. I want the user programmer to select the file extension between .png and .jpeg that is want to it to be selected from this 2 only and if programmer types another extension then it must show error. How can I do so?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:40:53+00:00Added an answer on June 9, 2026 at 7:40 am

    If i understood your question right, you want to create a library, where you handle images, and when the programmer, who uses your library wants to instantiate your image handling class/classes, you want him/her to choose between jpg and png?

    If so, your best option is to create an enum:

    public enum ImageType
    {
        TYPE_JPG, TYPE_PNG;
    } 
    

    And in your actual image-manipulating class:

    public class MyImageHandler
    {
        public MyImageHandler(ImageType type)
        {
            //You still need a nullcheck
            if(type == null) 
                throw new NullPointerException("null is not accepted!");
    
            if(type == ImageType.TYPE_JPG)
            {
                //JPG chosen
            }
            else if(type == ImageType.TYPE_PNG)
            {
                //PNG chosen
            }
        }
    }
    

    When the user-programmer uses it:

    MyImageHandler handler = new MyImageHandler(ImageType.PNG); //correct
    MyImageHandler handler = new MyImageHandler(ImageType.JPG); //correct
    MyImageHandler handler = new MyImageHandler(null); //runtime error
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an scrollable image picker, but there's some info that I want to
I'm creating an dynamic image, which creates headers on my page using PHPs GD-library.
I need a PDF library for manipulating a PDF documents, (creating PDF, image convertinng
I'm trying to build a static library (lib.a file) for use in creating an
I am attempting to allow a user to select an image from the photo
i'm working on creating one PNG image from two others. Image A and B
I am creating custom images that I later convert to an image pyramid for
by using flash cs5 with a huge internal image library (over 300+ small png-files)
I'm using Uploadify and Kohana and I'm creating file uploader. User can upload only
I'm new to Core Data. I'm creating an app that will allow a user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.