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

  • Home
  • SEARCH
  • 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 8067173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:12:28+00:00 2026-06-05T12:12:28+00:00

I have some classes A, B, C in package com.abc I have a Class

  • 0

I have some classes A, B, C in package com.abc

I have a Class Main in package com.pqr

Now I want to create a package object of the previous pacakge (abc).

For this I tried,

Package pkg = Package.getPackage("com.abc");   // This gives me null object in pkg

But when I do,

Package pkg = A.class.getPackage();    // It works fine

Can anyone notify, Why Package.getPackage(“package-name”) is not working ?

  • 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-05T12:12:32+00:00Added an answer on June 5, 2026 at 12:12 pm

    Package.getPackage will only return a non-null value if the current ClassLoader is already aware of the package. Try this:

    Package pkg = Package.getPackage("com.abc");
    System.out.println(pkg);
    Class<A> a = A.class;
    pkg = Package.getPackage("com.abc");
    System.out.println(pkg);
    

    The first System.out will print ‘null’, the second will print the package name as the ClassLoader has then loaded a class from it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some classes which extends a superclass, and in the JSP I want
I have some classes as below, i have implemented the Equals(Object) method for almost
I have some classes(call it Class A) which I would like to unit test
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have implemented some utility classes in Flex that I want to use in
I have some classes that implement an interface, but also extend the Sprite class:
I have some packages com.company.testing.module1 com.company.testing.module2 com.company.testing.module3 I also have some classes that have
I have a package which contains an interface and several classes,some classes in this
I have the following classes: package models; public class Test extends activejdbc.Model { }
I have one java project in netBeans. There are some packages, and classes in

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.