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 6565839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:08:41+00:00 2026-05-25T14:08:41+00:00

I have a little problem understanding how to create a child class’s contructor, which

  • 0

I have a little problem understanding how to create a child class’s contructor, which extends Parent class.Here is the code that I’m using :

Parent class constructor :

public RPCPacket(   int apacketId,
                        RPCPacketType apacketType,
                        RPCOperationType aoperationType,
                        String tmpPacket_objectOid,
                        int aobjectId,
                        int adataSize,
                        String tmpPacket_dataHash,
                        RPCPacketDataType adataType,
                        byte[] apacketData){


        RPCPacket packet=null;

        switch(apacketType){
            case ST_OBJECT_TYPE_INFO_START:
            {
                packet = new InfoStartRPCPacket();
                break;
            }
            case ST_OBJECT_TYPE_INFO_END:
            {
                packet = new InfoEndRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_INFO_ERROR:
            {
                packet = new InfoErrorRPCPacket();

                break;
            }

                // Basic packets
            case ST_OBJECT_TYPE_COLLECTION:
            {
                packet = new CollectionRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_CATEGORY:
            {
                packet = new CategoryRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_CARD:
            {
                packet = new CardRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_MESSAGE:
            {
                packet = new MessageRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_GENRE:
            {
                packet = new GenreRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_TAG:
            {
                packet = new TagRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_USER:
            {
                packet = new UserRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_CARDSTATS_CATEGORY:
            {
                packet = new CardStatsCategoryRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_CONTENT:
            {
                packet = new ContentRPCPacket();

                break;
            }

                // Media packets
            case ST_OBJECT_TYPE_MEDIA_COLLECTION:
            {
                packet = new MediaCollectionRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_MEDIA_CATEGORY:
            {
                packet = new MediaCategoryRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_MEDIA_CARD:
            {
                packet = new MediaCardRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_MEDIA_TAG:
            {
                packet = new MediaTagRPCPacket();

                break;
            }
            case ST_OBJECT_TYPE_MEDIA_COLLECTION_BUTTON:
            {
                packet = new MediaCollectionButtonRPCPacket();

                break;
            }

                // unknown packet
            default: 
            {
                packet=null;

                break;
            }
        }

    }

Child class constructor :

static int apacketId;
static RPCPacketType apacketType;
static RPCOperationType aoperationType;
static String tmpPacket_objectOid;
static int aobjectId;
static int adataSize;
static String tmpPacket_dataHash;
static RPCPacketDataType adataType;
static byte[] apacketData;

public InfoStartRPCPacket() {
        super(apacketId, apacketType, aoperationType, tmpPacket_objectOid, aobjectId,
                adataSize, tmpPacket_dataHash, adataType, apacketData);//line 46 from LogCat error
    }

And the LogCat Exception :

09-08 11:18:05.614: WARN/System.err(3376): java.lang.NullPointerException
09-08 11:18:05.614: WARN/System.err(3376):     at com.stampii.stampii.comm.rpc.RPCPacket.<init>(RPCPacket.java:68)
09-08 11:18:05.614: WARN/System.err(3376):     at com.stampii.stampii.comm.rpc.InfoStartRPCPacket.<init>(InfoStartRPCPacket.java:46)
09-08 11:18:05.614: WARN/System.err(3376):     at com.stampii.stampii.comm.rpc.RPCPacket.<init>(RPCPacket.java:71)
09-08 11:18:05.614: WARN/System.err(3376):     at com.stampii.stampii.user.UserLogin$2.onClick(UserLogin.java:122)
09-08 11:18:05.614: WARN/System.err(3376):     at android.view.View.performClick(View.java:2408)
09-08 11:18:05.614: WARN/System.err(3376):     at android.view.View$PerformClick.run(View.java:8817)
09-08 11:18:05.614: WARN/System.err(3376):     at android.os.Handler.handleCallback(Handler.java:587)
09-08 11:18:05.614: WARN/System.err(3376):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-08 11:18:05.614: WARN/System.err(3376):     at android.os.Looper.loop(Looper.java:144)
09-08 11:18:05.614: WARN/System.err(3376):     at android.app.ActivityThread.main(ActivityThread.java:4937)
09-08 11:18:05.614: WARN/System.err(3376):     at java.lang.reflect.Method.invokeNative(Native Method)
09-08 11:18:05.614: WARN/System.err(3376):     at java.lang.reflect.Method.invoke(Method.java:521)
09-08 11:18:05.614: WARN/System.err(3376):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-08 11:18:05.614: WARN/System.err(3376):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-08 11:18:05.624: WARN/System.err(3376):     at dalvik.system.NativeStart.main(Native Method)

Any suggestions how to fix my issue?

  • 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-05-25T14:08:42+00:00Added an answer on May 25, 2026 at 2:08 pm

    You’re getting NullPointerException because (I assume) you didn’t instantiate any of the static variables you’re using in your constructor. You need to pass in values for those parameters before calling InfoStartRPCPacket().

    However, this looks like a case of bad OO to me and unless you have a very specific need to use static variables in your child class, I would suggest that your child constructor should take the arguments of the parent so you can gracefully use the super(...) constructor in your child. Like so:

    InfoStartRPCPacket(
        int apacketId,
        RPCPacketType apacketType,
        RPCOperationType aoperationType,
        String tmpPacket_objectOid,
        int aobjectId,
        int adataSize,
        String tmpPacket_dataHash,
        RPCPacketDataType adataType,
        byte[] apacketData) {
        super(apacketId, apacketType, aoperationType, tmpPacket_objectOid, aobjectId,
                adataSize, tmpPacket_dataHash, adataType, apacketData);
        //your custom constructor code here
    }
    

    This way, no one has to know to instantiate all the static type variables before calling the constructor (an anti-pattern known as Sequential Coupling).

    Better yet, if you have no additional work to be done in the InfoStartRPCPacket, leave out the child constructor method altogether. It will simply inherit the parent’s constructor.

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

Sidebar

Related Questions

I have a little problem understanding the Java language public class PhonebookEntryList extends List<PhonebookEntry>
I have this little problem, that I cannot figure out which arguments to pass
I have little problem with my script. Here is the code. http://pastie.org/2361140 When I
I am facing a situation that I have problem understanding... I am writing a
I'm having a little bit of trouble understanding what the problem is here. I
This might be a stupid question, but I have a little problem with understanding
have a little problem here: int IntegerTransformer::transformFrom(std::string string){ stream->clear(); std::cout<<string<<std::endl;; (*stream)<<string; int i; (*stream)>>i;
I have a little problem understanding how to to the following in Haskell: Lets
i have little problem with boost::asio library. My app receive and process data asynchronously,
I have a little problem with a Listview. I can load it with listview

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.