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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:15:51+00:00 2026-06-17T07:15:51+00:00

Hi im new to android programming and this code produces an error when the

  • 0

Hi im new to android programming and this code produces an error when the button is clicked… It shows unfortunately the application has stopped can anybody check? 🙁

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.compute);
    aButton = (Button) this.findViewById(R.id.Button06);

    //get intent
    Intent i = getIntent();
    Bundle extras = i.getExtras(); // get the parameters

    density = getBaseContext().getResources().getDisplayMetrics().density;
    int textViewSizeDp = (int)(200 * density);
    int textFieldSizeDp = (int)(50 * density);

    FieldsLayout = (LinearLayout) findViewById(R.id.FieldsLayout);
    if(extras!=null){
        items = (extras.getString("items")).split(",");
        rows = new LinearLayout[items.length];
        labels = new TextView[items.length];
        fields = new EditText[items.length];

        for (int ctr=0;ctr<items.length;ctr++){
            rows[ctr] = new LinearLayout(Compute.this);
            rows[ctr].setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
            rows[ctr].setOrientation(LinearLayout.HORIZONTAL);
            rows[ctr].setLayoutParams(new LayoutParams (LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            FieldsLayout.addView(rows[ctr]);

            labels[ctr] = new TextView(Compute.this);
            labels[ctr].setText(items[ctr]);
            labels[ctr].setMinimumWidth(textViewSizeDp);
            rows[ctr].addView(labels[ctr]);

            fields[ctr] = new EditText(Compute.this);
            fields[ctr].setMinimumWidth(textFieldSizeDp);
            rows[ctr].addView(fields[ctr]);

        }
    }
    else{
        finish();
    }



    aButton.setOnClickListener(new OnClickListener() {  


        public void onClick(View v) {   

              Intent i = new Intent(Compute.this, Total.class);
              //I believe this causes the error
                for(int ctr=0;ctr<fields.length;ctr++){
                    itemName[ctr] = labels[ctr].getText().toString();
                    }

                for(int ctr=0;ctr<fields.length;ctr++){
                    itemHour[ctr] = Integer.parseInt(fields[ctr].getText().toString());
                    }
                //until here
              i.putExtra("hours",itemHour);
              i.putExtra("items",itemName);
              startActivity(i);
              }});     

}

here’s the error log: (or is this it?)

01-14 09:37:16.047: W/Trace(768): Unexpected value from nativeGetEnabledTags: 0
01-14 09:37:16.187: E/AndroidRuntime(768): FATAL EXCEPTION: main
01-14 09:37:16.187: E/AndroidRuntime(768): java.lang.NullPointerException
01-14 09:37:16.187: E/AndroidRuntime(768):  at com.example.mpc.Compute$1.onClick(Compute.java:82)
01-14 09:37:16.187: E/AndroidRuntime(768):  at android.view.View.performClick(View.java:4202)
01-14 09:37:16.187: E/AndroidRuntime(768):  at android.view.View$PerformClick.run(View.java:17340)
01-14 09:37:16.187: E/AndroidRuntime(768):  at android.os.Handler.handleCallback(Handler.java:725)
01-14 09:37:16.187: E/AndroidRuntime(768):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-14 09:37:16.187: E/AndroidRuntime(768):  at android.os.Looper.loop(Looper.java:137)
01-14 09:37:16.187: E/AndroidRuntime(768):  at android.app.ActivityThread.main(ActivityThread.java:5039)
01-14 09:37:16.187: E/AndroidRuntime(768):  at java.lang.reflect.Method.invokeNative(Native Method)
01-14 09:37:16.187: E/AndroidRuntime(768):  at java.lang.reflect.Method.invoke(Method.java:511)
01-14 09:37:16.187: E/AndroidRuntime(768):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-14 09:37:16.187: E/AndroidRuntime(768):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-14 09:37:16.187: E/AndroidRuntime(768):  at dalvik.system.NativeStart.main(Native Method)
  • 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-17T07:15:52+00:00Added an answer on June 17, 2026 at 7:15 am

    Check out following things:

    1. Make sure your field array is initialized properly.
    2. Make sure that the length of itemName is same as that of fields.length and it should be properly initialized.
    3. Make sure that the length of labels is same as that of fields.length and it should be properly initialized.
    4. Make sure that the length of itemHour is same as that of fields.length and it should be properly initialized.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the code I am using in android programming EditText pass1,pass2; Button register=(Button)
I am new to android programming. Just wrote this code to convert kg's to
In O'Reilly - Programming Android they recommend avoiding this code: ArrayList<String> a = new
I am new to android programming and i am trying to develop this app
I'm fairly new to Android programming, so this may be a simple question, but
New to android programming. Getting Following error. 04-07 14:49:05.452: ERROR/AndroidRuntime(1566): FATAL EXCEPTION: main java.lang.OutOfMemoryError
I'm new on android programming and i'm working on android application and i'm stuck
I am a bit new to android programming and cant seem to shake this
I am new to android programming but there is something small that i can't
I am new to Android programming and so kingly pardon me if this question

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.