MainActivity
package com.elitiv.myapplication2.app;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
private EditText Result;
private String Operation;
private EditText editYear;
private EditText editCapacity;
private Button calc;
private RadioButton radioD;
private RadioButton radioB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView Year = (TextView) findViewById(R.id.Year);
TextView Capacity = (TextView) findViewById(R.id.Capacity);
editYear = (EditText) findViewById(R.id.editYear);
editCapacity = (EditText) findViewById(R.id.editCapacity);
final EditText Result = (EditText) findViewById(R.id.Result);
Button calc = (Button) findViewById(R.id.calc);
final RadioButton radioD = (RadioButton) findViewById(R.id.radioD);
final RadioButton radioB = (RadioButton) findViewById(R.id.radioB);
calc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int edityear_value = Integer.parseInt(editYear.getText().toString());//Convert to intger
if (radioB.isChecked()) {
switch (edityear_value) {
case 2004:
Operation = ("2004");
break;
case 2005:
Operation = "2005";
break;
case 2006:
Operation = "2006";
break;
case 2007:
Operation = "2007";
break;
case 2008:
Operation = "2007";
break;
case 2009:
Operation = "2009";
break;
case 2010:
Operation = "2010";
break;
case 2011:
Operation = "2011";
break;
case 2012:
Operation = "2011";
break;
case 2013:
Operation = "2013";
break;
case 2014:
Operation = "2013";
break;
}
} else if (radioD.isChecked()) {
switch (edityear_value) {
case 2004:
Operation = "20041";
break;
case 2005:
Operation = "20051";
break;
case 2006:
Operation = "20061";
break;
case 2007:
Operation = "20071";
break;
case 2008:
Operation = "20071";
break;
case 2009:
Operation = "20091";
break;
case 2010:
Operation = "20101";
break;
case 2011:
Operation = "20111";
break;
case 2012:
Operation = "20111";
break;
case 2013:
Operation = "20131";
break;
case 2014:
Operation = "20131";
break;
}
}
Operation();
}
}
);
}
public void Operation() {
double result = 0 ;
int NumberCapacity = Integer.parseInt(editCapacity.getText().toString())
//Benzin
if (NumberCapacity > 0 && NumberCapacity < 1000) {
if (Operation.equals("2004")) {
result = NumberCapacity * 0.52;
}
if (Operation.equals("2005")) {
result = NumberCapacity * 0.50;
}
if (Operation.equals("2006")) {
result = NumberCapacity * 0.47;
}
if (Operation.equals("2007")) {
result = NumberCapacity * 0.44;
}
if (Operation.equals("2009")) {
result = NumberCapacity * 0.43;
}
if (Operation.equals("2011")) {
result = NumberCapacity * 0.42;
}
if (Operation.equals("2013")) {
result = NumberCapacity * 0.40;
}
}
if (NumberCapacity > 1001 && NumberCapacity < 1500) {
if (Operation.equals("2004")) {
result = NumberCapacity * 0.67;
}
if (Operation.equals("2005")) {
result = NumberCapacity * 0.63;
}
if (Operation.equals("2006")) {
result = NumberCapacity * 0.60;
}
if (Operation.equals("2007")) {
result = NumberCapacity * 0.56;
}
if (Operation.equals("2009")) {
result = NumberCapacity * 0.55;
}
if (Operation.equals("2011")) {
result = NumberCapacity * 0.54;
}
if (Operation.equals("2013")) {
result = NumberCapacity * 0.52;
}
}
if (NumberCapacity > 1501 && NumberCapacity < 2000) {
if (Operation.equals("2004")) {
result = NumberCapacity * 1.00;
}
if (Operation.equals("2005")) {
result = NumberCapacity * 0.95;
}
if (Operation.equals("2006")) {
result = NumberCapacity * 0.89;
}
if (Operation.equals("2007")) {
result = NumberCapacity * 0.84;
}
if (Operation.equals("2009")) {
result = NumberCapacity * 0.83;
}
if (Operation.equals("2011")) {
result = NumberCapacity * 0.82;
}
if (Operation.equals("2013")) {
result = NumberCapacity * 0.80;
}
}
if (NumberCapacity > 2001 && NumberCapacity < 3000) {
if (Operation.equals("2004")) {
result = NumberCapacity * 1.59;
}
if (Operation.equals("2005")) {
result = NumberCapacity * 1.52;
}
if (Operation.equals("2006")) {
result = NumberCapacity * 1.44;
}
if (Operation.equals("2007")) {
result = NumberCapacity * 1.36;
}
if (Operation.equals("2009")) {
result = NumberCapacity * 1.35;
}
if (Operation.equals("2011")) {
result = NumberCapacity * 1.34;
}
if (Operation.equals("2013")) {
result = NumberCapacity * 1.32;
}
}
if (NumberCapacity > 3000) {
if (Operation.equals("2004")) {
result = NumberCapacity * 3.57;
}
if (Operation.equals("2005")) {
result = NumberCapacity * 3.56;
}
if (Operation.equals("2006")) {
result = NumberCapacity * 3.55;
}
if (Operation.equals("2007")) {
result = NumberCapacity * 3.54;
}
if (Operation.equals("2009")) {
result = NumberCapacity * 3.53;
}
if (Operation.equals("2011")) {
result = NumberCapacity * 3.52;
}
if (Operation.equals("2013")) {
result = NumberCapacity * 3.50;
}
}
//Diesel
if (NumberCapacity < 1500) {
if (Operation.equals("20041")) {
result = NumberCapacity * 1.67;
}
if (Operation.equals("20051")) {
result = NumberCapacity * 1.63;
}
if (Operation.equals("20061")) {
result = NumberCapacity * 1.60;
}
if (Operation.equals("20071")) {
result = NumberCapacity * 1.56;
}
if (Operation.equals("20091")) {
result = NumberCapacity * 1.55;
}
if (Operation.equals("20111")) {
result = NumberCapacity * 1.54;
}
if (Operation.equals("20131")) {
result = NumberCapacity * 1.52;
}
}
if (NumberCapacity > 1501 && NumberCapacity < 2500) {
if (Operation.equals("20041")) {
result = NumberCapacity * 1.59;
}
if (Operation.equals("20051")) {
result = NumberCapacity * 1.52;
}
if (Operation.equals("20061")) {
result = NumberCapacity * 1.44;
}
if (Operation.equals("20071")) {
result = NumberCapacity * 1.36;
}
if (Operation.equals("20091")) {
result = NumberCapacity * 1.35;
}
if (Operation.equals("20111")) {
result = NumberCapacity * 1.34;
}
if (Operation.equals("20131")) {
result = NumberCapacity * 1.32;
}
}
if (NumberCapacity > 2501) {
if (Operation.equals("20041")) {
result = NumberCapacity * 3.57;
}
if (Operation.equals("20051")) {
result = NumberCapacity * 3.56;
}
if (Operation.equals("20061")) {
result = NumberCapacity * 3.55;
}
if (Operation.equals("20071")) {
result = NumberCapacity * 3.54;
}
if (Operation.equals("20091")) {
result = NumberCapacity * 3.53;
}
if (Operation.equals("20111")) {
result = NumberCapacity * 3.52;
}
if (Operation.equals("20131")) {
result = NumberCapacity * 3.50;
}
}
Result.setText(String.valueOf(result));
}
}
ActivityMainn_Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.elitiv.myapplication2.app.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Anul Autovehicolului"
android:id="@+id/Year"
android:layout_marginTop="25dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/editYear"
android:layout_alignTop="@+id/Year"
android:layout_toRightOf="@+id/Year"
android:layout_marginLeft="27dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="capacitatea"
android:id="@+id/Capacity"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/editYear"
android:layout_marginBottom="175dp" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/editCapacity"
android:layout_alignBottom="@+id/Capacity"
android:layout_alignLeft="@+id/editYear"
android:layout_alignStart="@+id/editYear" />
<RadioGroup
android:layout_width="300dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_alignTop="@id/Year">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"
android:id="@+id/radioB"
android:layout_marginTop="83dp"
android:checked="true"
android:layout_marginRight="77dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="D"
android:id="@+id/radioD"
android:checked="false"
/>
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calc"
android:id="@+id/calc"
android:layout_below="@+id/editCapacity"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/Result"
android:layout_below="@+id/calc"
android:layout_centerHorizontal="true"
android:layout_marginTop="31dp" />
</RelativeLayout>
LogCat
05-07 08:22:37.058 1986-1986/com.elitiv.myapplication2.app I/Process﹕ Sending signal. PID: 1986 SIG: 9
05-07 08:24:46.850 2105-2105/com.elitiv.myapplication2.app D/dalvikvm﹕ GC_FOR_ALLOC freed 83K, 9% free 2877K/3156K, paused 228ms, total 230ms
05-07 08:24:49.880 2105-2105/com.elitiv.myapplication2.app D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
05-07 08:26:16.212 2105-2105/com.elitiv.myapplication2.app D/AndroidRuntime﹕ Shutting down VM
05-07 08:26:16.212 2105-2105/com.elitiv.myapplication2.app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb0e82648)
05-07 08:26:16.282 2105-2105/com.elitiv.myapplication2.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.elitiv.myapplication2.app.MainActivity.Operation(MainActivity.java:327)
at com.elitiv.myapplication2.app.MainActivity$1.onClick(MainActivity.java:117)
at android.view.View.performClick(View.java:4240)
at android.view.View$PerformClick.run(View.java:17721)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
So basicly the problem is, that i cannot show the calculated result in the EditText field 3 with id of Result