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

The Archive Base Latest Questions

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

I am getting a null pointer exception when I am calling a function. Here

  • 0

I am getting a null pointer exception when I am calling a function.

Here is my code:

    try{
            .....
            String [] forForm = new String[5];
            forForm[0] = new String(parentElement.getNodeName());
            forForm[1] = new String(childElement1.getNodeName());
            forForm[2] = new String(ce1);
            forForm[3] = new String(childElement2.getNodeName());
            forForm[4] = new String(ce2);
            Log.e(tag,forForm.toString());
            showForm(forForm);

    } catch (Exception e) {
        Log.e(tag, "error in try: "+e.toString());
    } 

Here is my output :

09-10 21:58:47.919: ERROR/ca(867): <?xml version='1.0' encoding='ISO-8859-1'?><LoginInfo><Username>un</Username><Password>pw</Password></LoginInfo>
09-10 21:58:47.999: ERROR/ca(867): Username: un
09-10 21:58:47.999: ERROR/ca(867): Password: pw
09-10 21:58:48.019: ERROR/ca(867): [Ljava.lang.String;@44ed5570
09-10 21:58:48.019: ERROR/ca(867): in show form1
09-10 21:58:48.040: ERROR/ca(867): error in try: java.lang.NullPointerException

Why am I getting a null pointer exception even though there is a memory location for forForm?

EDIT:

private void showForm(String[] forForm) {
        Log.e(tag, "in show form1");
        LinearLayout ol = (LinearLayout) findViewById(R.id.OuterLayout);
        LinearLayout [] il = new LinearLayout [2];
        EditText [] et = new EditText[2];
        TextView [] tv = new TextView[3];

        tv[0].setText(forForm[0]);
        tv[0].setTextSize(30);
        tv[0].setLayoutParams(
                new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        Log.e(tag, "in show form2");
        il[0].setOrientation(LinearLayout.HORIZONTAL);
            tv[1].setText(forForm[1]);
            tv[1].setTextSize(20);
            tv[1].setLayoutParams(
                    new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT,1f));
            il[0].addView(tv[1]);

            et[0].setText(forForm[2]);
            et[0].setId(1111);
            et[0].setTextSize(20);
            et[0].setLayoutParams(
                    new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT,1f));
            il[0].addView(et[0]);
            Log.e(tag, "in show form3");
        il[1].setOrientation(LinearLayout.HORIZONTAL);
            tv[2].setText(forForm[3]);
            tv[2].setTextSize(20);
            tv[2].setLayoutParams(
                    new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT,1f));
            il[1].addView(tv[1]);

            et[1].setText(forForm[2]);
            et[1].setId(2222);
            et[1].setTextSize(20);
            et[1].setLayoutParams(
                    new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT,1f));
            il[1].addView(et[1]);
            Log.e(tag, "in show form4");    
        ol.addView(tv[0]);
        ol.addView(il[0]);
        ol.addView(il[1]);

        Log.e(tag, "Set Content View.");
        this.setContentView(ol);
    }

In the output, I am getting till “in showform 1”

  • 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:14:51+00:00Added an answer on May 25, 2026 at 2:14 pm

    This might be happening with .getnodename(), if the node is not present, you are working on a null node, check for sure that the node is present before working on that node with .getnodename().

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

Sidebar

Related Questions

I try in following way but I am getting Null Pointer Exception at iv.setImageBitmap(bm).
How to resolve null pointer exception that occurred when I try to use Intent.putExtra()
How to resolve null pointer exception that occurred when I try to use Intent.putExtra()
I am getting null pointer exception when I am trying to get lat/long from
I am getting a null pointer exception when trying to set up datasource in
I am getting same null pointer exception while running integration test in eclipse .while
I am getting Null Pointer Exception for ImageView imag = (ImageView) findViewById(R.id.image). I have
I am getting null pointer exception, due to failed to recognize layout parameter in
I'm writing a Linux module and getting: Unable to handle kernel NULL pointer dereference
IN JAVA CODE IN JSP as below i m getting null value for fieldnoOfRecords.

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.