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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:21:35+00:00 2026-05-13T12:21:35+00:00

import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button;

  • 0
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class calctest extends Activity {
/** Called when the activity is first created. */
private EditText input; 
private EditText input2; 
private EditText input3; 
private EditText input4;
private TextView output;
private TextView output2;
private Spinner aperture;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

 // Extract the text fields from the XML layout 
    input = (EditText) findViewById(R.id.input1); 
    input2 = (EditText) findViewById(R.id.input2);
    input3 = (EditText) findViewById(R.id.input3); 
    input4 = (EditText) findViewById(R.id.input4);
    output = (TextView) findViewById(R.id.result); 
    output2 = (TextView) findViewById(R.id.result2);

    //aperture dropdown
    final Spinner aperture = (Spinner) findViewById(R.id.apt);
    ArrayAdapter adapter = ArrayAdapter.createFromResource(
    this, R.array.apertures, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    aperture.setAdapter(adapter);

    Spinner mode = (Spinner) findViewById(R.id.mode);
    ArrayAdapter adapter2 = ArrayAdapter.createFromResource(
    this, R.array.formats, android.R.layout.simple_spinner_item);
    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mode.setAdapter(adapter2);

    // Perform calculation when button is pushed

    final Button button = (Button) findViewById(R.id.calculate);
    button.setOnClickListener(new View.OnClickListener() {             
        public void onClick(View v) {                 
            doCalculation(aperture.getSelectedItem());
                }         
            });
        }


private void doCalculation(Object selectedItem) { 
    // Get entered input value 
    String cinput1 = input.getText().toString(); 
    String cinput2 = input2.getText().toString();
    String cinput3 = input3.getText().toString(); 
    String cinput4 = input4.getText().toString();
    Object cinput5 = aperture.getSelectedItem();
}

}

I know that the doCalculation method isnt actually calculating anything yet, because the app crashes just from trying to get the input’s value. If I disable the cinput5 line, it works just fine. What am I doing wrong here? And on that note, how do I convert the spinner’s value to a string to use in the calculation?

Also, as a double check… the spinner displays a list of numbers (1.4, 2, 2.8, 4, 5.6, etc) and whichever number is selected is the number I need to use in the calculation. I’m calling the correct value from the spinner, right?

I apologize for the probably extremely obvious errors. I just started Java and after I finish this app is promise I will be getting a book!

  • 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-13T12:21:36+00:00Added an answer on May 13, 2026 at 12:21 pm

    You are declaring aperture twice, once at the beginning of your code and again within the onCreate method.

    In this line:

    final Spinner aperture = (Spinner) findViewById(R.id.apt);
    

    try removing the final Spinner.

    When the app reaches the last line of the doCalculation method it is most likely throwing a null object reference because it is referencing the private aperture instance that has yet to be instantiated.

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

Sidebar

Ask A Question

Stats

  • Questions 265k
  • Answers 265k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's provider model, so you can change the data source.… May 13, 2026 at 12:21 pm
  • Editorial Team
    Editorial Team added an answer That's the usual way to do it with SAX. Just… May 13, 2026 at 12:21 pm
  • Editorial Team
    Editorial Team added an answer menuStrip1.Items.OfType<ToolStripMenuItem>().Where(it => it.GetType() == typeof(ToolStripMenuItem)); It seems kind of redundant,… May 13, 2026 at 12:21 pm

Related Questions

I just downloaded and installed the new Android SDK. I wanted to create a
I am using the following code to display a video file in the android
I've just started developing Android applications. I'm having a little problem with networking. If
What is the best way to learn Android? I'm reading Rogers's at al.'s book
I want to make a tile based game for android. At the moment I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.