Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see several problems</p> <pre><code>mTextView.setText(sq1.toString()); </code></pre> <p>The toString method in SquareArea is not overridden. So the toString will return the default information about the object (location in memory, name, etc.)</p> <pre><code>public SquareArea(double length , double width){ _length = length; _width = width; area(); } </code></pre> <p>In the code above, you are inside the constructor. Why are you calling area() from here? A constructor can't return anything and the result from area() is being lost because area() returns a double.</p> <p>And lastly:</p> <pre><code>private double area(){ return _length } </code></pre> <p>This method is private. It cannot be called from outside the class/object.</p> <p>To make your code work this is what I would change.</p> <pre><code>public class SquareArea{ private double _length; private double _width; public SquareArea(double length , double width){ _length = length; _width = width; } public double area(){ return _length * _width; } } ///Below is my MainActivity Class/// public class MainActivity extends Activity { EditText mEditText1; EditText mEditText2; EditText mEditText3; TextView mTextView; Button mButton; Double value1, value2; SquareArea sq1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mEditText1 = (EditText) findViewById(R.id.editText1); mEditText2 = (EditText) findViewById(R.id.editText2); mEditText3 = (EditText) findViewById(R.id.editText3); mTextView = (TextView) findViewById(R.id.textView1); mEditText1.setBackgroundColor(Color.GREEN); mEditText2.setBackgroundColor(Color.GREEN); mEditText3.setBackgroundColor(Color.RED); mButton = (Button) findViewById(R.id.button1); mButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //When the button is clicked, call the calucate method. // calculate(); try { value1 = Double.parseDouble(mEditText1.getText().toString()); value2 = Double.parseDouble(mEditText2.getText().toString()); sq1 = new SquareArea(value1, value2); mTextView.setText(String.ValueOf(sq1.area())); } catch (NumberFormatException e) { mTextView.setText("Please use numbers"); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload