vishalbhardwaj0411
Lurker
I just started learning android development and was trying to build a basic currency conversion android app with the code.
-----------------------------------------------------------CODE----------------------------------------------------------------------------
package com.example.currencyconversion;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
/*-----------Creating objects of buttons and text field-----------*/
private TextView input;
private TextView output;
private int result;
private int value = 0;
private Button toInr;
private Button toUsd;
/*-----------Creating objects of buttons and text field-----------*/
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*---------------Refrence for XML---------------------------*/
input = findViewById(R.id.currency_input);
output = findViewById(R.id.currency_output);
toInr = findViewById(R.id.to_inr);
toUsd = findViewById(R.id.to_usd);
/*----xxx-----------Refrence for XML----------------------xxx-----*/
value = Integer.parseInt(input.getText().toString());
/*---------------On click listener---------------------------*/
toInr.setOnClickListener(this);
toUsd.setOnClickListener(this);
/*---xxx-----------On click listener-----------------------xxx----*/
}
/*---------------On click listener switch case---------------------------*/
public void onClick(View view) {
switch (view.getId())
{
case R.id.to_inr:
Toast.makeText(MainActivity.this , "to inr" , Toast.LENGTH_SHORT).show();
result = value * 74;
output.setText(Integer.toString(result));
break;
case R.id.to_usd:
Toast.makeText(MainActivity.this , "to usd" , Toast.LENGTH_SHORT).show();
}
}
/*-----xxx----------On click listener switch case-----------------xxx----------*/
}
----------------------------------------------------------END OF-CODE-----------------------------------------------------------------
Every time I run the following code it crashes the app AND problem is in following line
value = Integer.parseInt(input.getText().toString());
-----------------------------------------------------------CODE----------------------------------------------------------------------------
package com.example.currencyconversion;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
/*-----------Creating objects of buttons and text field-----------*/
private TextView input;
private TextView output;
private int result;
private int value = 0;
private Button toInr;
private Button toUsd;
/*-----------Creating objects of buttons and text field-----------*/
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*---------------Refrence for XML---------------------------*/
input = findViewById(R.id.currency_input);
output = findViewById(R.id.currency_output);
toInr = findViewById(R.id.to_inr);
toUsd = findViewById(R.id.to_usd);
/*----xxx-----------Refrence for XML----------------------xxx-----*/
value = Integer.parseInt(input.getText().toString());
/*---------------On click listener---------------------------*/
toInr.setOnClickListener(this);
toUsd.setOnClickListener(this);
/*---xxx-----------On click listener-----------------------xxx----*/
}
/*---------------On click listener switch case---------------------------*/
public void onClick(View view) {
switch (view.getId())
{
case R.id.to_inr:
Toast.makeText(MainActivity.this , "to inr" , Toast.LENGTH_SHORT).show();
result = value * 74;
output.setText(Integer.toString(result));
break;
case R.id.to_usd:
Toast.makeText(MainActivity.this , "to usd" , Toast.LENGTH_SHORT).show();
}
}
/*-----xxx----------On click listener switch case-----------------xxx----------*/
}
----------------------------------------------------------END OF-CODE-----------------------------------------------------------------
Every time I run the following code it crashes the app AND problem is in following line
value = Integer.parseInt(input.getText().toString());