I've created an app that contains only one activity. In this activity there are 3 EditTexts and 1 TextView .
I created 3 variables of type long ( l01, l02 e l03
) to receive the value of 3 EditTexts .
MainActivity:
package genesysgeneration.treerule;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
public class MainMenuActivity extends AppCompatActivity {
private EditText et01, et02, et03;
private TextView tv01;
private long l01, l02, l03;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
l01=0;
l02=0;
l03=0;
et01=(EditText)findViewById(R.id.et01);
et02=(EditText)findViewById(R.id.et02);
et03=(EditText)findViewById(R.id.et03);
l01=Long.parseLong(et01.getText().toString());
l02=Long.parseLong(et02.getText().toString());
l03=Long.parseLong(et03.getText().toString());
tv01=(TextView)findViewById(R.id.tv01);
tv01.setText(String.valueOf(l01*l02*l03));
}
}
As you can see in the code I used the parseLong method, but it did not make the app work and the application does not even open.
Ontheandroidmonitorgivesthis:
01-30 20:41:31.441 2448-2448/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{genesysgeneration.treerule/genesysgeneration.treerule.MainMenuActivity}: java.lang.NumberFormatException: Invalid long: ""
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid long: ""
at java.lang.Long.invalidLong(Long.java:125)
at java.lang.Long.parseLong(Long.java:346)
at java.lang.Long.parseLong(Long.java:319)
at genesysgeneration.treerule.MainMenuActivity.onCreate(MainMenuActivity.java:27)
at android.app.Activity.performCreate(Activity.java:4466)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)