I wrote this code in order to simplify part numbers in math e.g. 2a/2b = a/b. android studio shows no problems but when i run this code: (maz stands for lowest number, liels stands for highest number, skait is the 2a in the previous example and sauc is the 2b int the previous example, skaitout and saucout are the output text fields corresponding to the part number parts, skaitout is the top number and saucout is the bottom number)
package com.example.mikus.simplify;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View skait = findViewById(R.id.skait);
View sauc = findViewById(R.id.sauc);
TextView skaitout = (TextView) findViewById(R.id.skaitout);
TextView saucout = (TextView) findViewById(R.id.saucout);
int maz;
int liels;
int x;
int i = 0;
maz = Integer.parseInt(skait.toString());
liels = Integer.parseInt(sauc.toString());
if(maz > liels){
x = maz;
maz = liels;
liels = x;
i = 1;
}
if(maz == liels){
skaitout.setText('1');
saucout.setText('1');
}else{
x = maz;
while(true){
if(maz % x == 0 && liels % x == 0){
maz /= x;
liels /= x;
x = maz;
}else{
if(x == liels){
return;
}else{
x++;
}
}
}
}
if (i == 0) {
skaitout.setText(maz);
saucout.setText(liels);
}
if(i == 1){
skaitout.setText(liels);
saucout.setText(maz);
}
}
}
i get the error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mikus.simplify, PID: 24905
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mikus.simplify/com.example.mikus.simplify.MainActivity}: java.lang.NumberFormatException: Invalid int: "android.support.v7.widget.AppCompatEditText{11f3506 VFED..CL. ......ID 0,0-0,0 #7f0b0057 app:id/skait}"
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3256)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3352)
at android.app.ActivityThread.access$1100(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1797)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.NumberFormatException: Invalid int: "android.support.v7.widget.AppCompatEditText{11f3506 VFED..CL. ......ID 0,0-0,0 #7f0b0057 app:id/skait}"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:410)
at java.lang.Integer.parseInt(Integer.java:367)
at java.lang.Integer.parseInt(Integer.java:334)
at com.example.mikus.simplify.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:6877)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3352)
at android.app.ActivityThread.access$1100(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1797)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
in phone the program just crashes. can anyone help me.
You try to convert a view to string and parse this to integer:
liels = Integer.parseInt(sauc.toString());
maz = Integer.parseInt(skait.toString());
I guess you want to do something like this:
liels = Integer.parseInt(sauc.getText().toString());
maz = Integer.parseInt(skait.getText().toString());
Also, it´s possible that the user make some wrong input. You could catch the exception if the input is not a number like:
try{
liels = Integer.parseInt(sauc.getText().toString());
maz = Integer.parseInt(skait.getText().toString());
}catch(NumberFormatException ex){
//inform the user about wrong input
}
or you can restrict user input to only numbers by setting this attribute to editTexts:
android:inputType="number"
And be aware: Later you will get also exceptions by setting the text:
if (i == 0) {
skaitout.setText(maz);
saucout.setText(liels);
}
if(i == 1){
skaitout.setText(liels);
saucout.setText(maz);
}
This will throw an exception, you have to cast the integer to a string like:
if (i == 0) {
skaitout.setText(Integer.toString(maz));
saucout.setText(Integer.toString(liels));
}
if(i == 1){
skaitout.setText(Integer.toString(liels));
saucout.setText(Integer.toString(maz));
}
or just for example with some quitation marks:
saucout.setText(""+maz);
You're trying to parse View as int.
Related
I'm new to development so sorry if my question is very simple.
I'm developing an app for D&D. When the user inserts a number in the first edittext i use onTextChanged of edittext so I setText to the second edittex the result.
My problem only occurs if the checkbox is checked. If the checkbox is not checked, it works fine but if the checkbox is checked the app will make a sum (proficiencybonus + mod). It works but only for positive numbers. When the app sets a velue of f.e. -5 the app crashes. The data is all saved in the sharedpreferences.
checkBox_strength.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(checkBox_strength.isChecked()) {
float result_num;
int num1, num2;
int f= 0;
DecimalFormat df = new DecimalFormat("0.##########");
num1 = Integer.parseInt(proficiencybonus.getText().toString());
if (strength_mod.getText().toString().length() > 0) {
num2 = Integer.parseInt(strength_mod.getText().toString());
} else {
num2=f;
}
result_num = num1 + num2;
strength_save.setText(" = " + df.format(result_num));
editor.putBoolean("checkBox_strength", true);
editor.apply();
}else{
editor.putBoolean("checkBox_strength", false);
editor.apply();
}
}
});
Have tried something else but I can't go find a solution
float result_num;
int num1, num2;
int f= 0;
DecimalFormat df = new DecimalFormat("0.##########");
num1 = Integer.parseInt(proficiencybonus.getText().toString());
if (strength_mod.getText().toString().length() > 0) {
num2 = Integer.parseInt(strength_mod.getText().toString());
} else {
num2=f;
}
result_num = num1 + Math.abs(num2);
strength_save.setText(" = " + df.format(result_num));
This is my error of the crash, it crashes "num2 = Integer.parseInt(strength_mod.getText().toString());"
2020-05-03 17:09:24.440 10318-10318/jekanapplication.charactersheet5e E/AndroidRuntime: FATAL EXCEPTION: main
Process: jekanapplication.charactersheet5e, PID: 10318
java.lang.NumberFormatException: For input string: "−1"
at java.lang.Integer.parseInt(Integer.java:608)
at java.lang.Integer.parseInt(Integer.java:643)
at jekanapplication.charactersheet5e.MainActivity$51.onCheckedChanged(MainActivity.java:1394)
at android.widget.CompoundButton.setChecked(CompoundButton.java:172)
at android.widget.CompoundButton.toggle(CompoundButton.java:128)
at android.widget.CompoundButton.performClick(CompoundButton.java:133)
at android.view.View$PerformClick.run(View.java:24931)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
In the XML define this attribute: android:inputType="numberSigned"
The Problem is how set the text in the second edittext , is use onTextchange of the first edittext, I set the text edittext.settext"-2" I have changed in edittext.settext"R.String.two_" so when the i get the text I have no proble when I get the string.
I am new to android programming and am trying to the program to run but the problem is that the app builds and runs successfully but crashes whenever I press the GO button. My professor gave me this to accomplish as something to get started with android programming as he thought it would be challenging task that will be motivational and interesting. I looked everywhere for the solution but could not find it. My professor himself is unable to debug the code and hence.
The code is as given below:
**CODE 1**
package com.example.thispc.myapplication;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
import java.util.Scanner;
import edu.princeton.cs.algs4.EdgeWeightedDigraph;
import edu.princeton.cs.algs4.DirectedEdge;
import edu.princeton.cs.algs4.BellmanFordSP;
public class Arbitrage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_arbitrage);
Button Check_Arbitrage = findViewById(R.id.Check_Arbitrage);
Check_Arbitrage.setOnClickListener(new View.OnClickListener() {
#SuppressLint("SetTextI18n")
#Override
public void onClick(View view) {
EditText inputcurrencynumber;
EditText inputdata;
TextView outputarbitrage;
inputcurrencynumber = findViewById(R.id.GetNoCurrencies);
inputdata = findViewById(R.id.currency_table_input);
outputarbitrage = findViewById(R.id.result);
inputcurrencynumber = findViewById(R.id.GetNoCurrencies);
int V;
V = Integer.parseInt(inputcurrencynumber.getText().toString());
outputarbitrage = findViewById(R.id.result);
double rate,stake;
inputdata = findViewById(R.id.currency_table_input);
EdgeWeightedDigraph G = new EdgeWeightedDigraph(V);
outputarbitrage.setText("Hello World");
String [] name = new String[V];
// The error occures here when i try to take an input
for (int v = 0; v < V ; v++)
{`enter code here`
name[v] = inputdata.getText().toString();
for (int w = 0; w < V ; w++)
{
rate = Double.parseDouble(inputdata.getText().toString());
DirectedEdge e = new DirectedEdge(v, w, -Math.log(rate));
G.addEdge(e);
}
}
BellmanFordSP spt = new BellmanFordSP(G,0);
if (spt.hasNegativeCycle())
{
stake = 1000;
for (DirectedEdge e : spt.negativeCycle())
{
//outputarbitrage.setText((Double.toString(stake) + name[e.from()]) + " " + (Double.toString(stake) + name[e.to()]) + "\n");
outputarbitrage.setText("%10.5f %s " + stake + name[e.from()]);
stake = stake * Math.exp(-e.weight());
outputarbitrage.setText("= %10.5f %s\n" + stake + name[e.to()]);
}
}
else
{
outputarbitrage.setText("No Arbitrage Opportunity Found");
}
}
});
}
}
Note : This code works perfectly in java IDE (I use netbeans) but crashes in android studio.
======================================================================================================================================================
EDIT 1
Added the log as below :
com.example.thispc.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.thispc.myapplication, PID: 4876
java.lang.NumberFormatException: For input string: "USD 1 1.6 4
CAD 2.3 1 1.3
CHF 4 8 1"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:539)
at com.example.thispc.myapplication.Arbitrage$1.onClick(Arbitrage.java:57)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
======================================================================================================================================================
EDIT 2
output
Its getting crash because of the below line
rate = Double.parseDouble(inputdata.getText().toString());
You are trying to parse the string and parseDoubel() expects the string value which only holds numeric value, but in your case inputdata.getText().toString() contains character other than numbers.
Try extracting digits form the inputdata before passing to parseDouble() method
str.replaceAll("[^0-9]", "");
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
Whenever i run the app, enter the name and press the submit button the app crashes.Here's the code
public class MainActivity extends AppCompatActivity {
int x, sum=0;
String str,str2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final Button chk = findViewById(R.id.check);
final Button sub = findViewById(R.id.submit);
final EditText name = findViewById(R.id.name);
chk.setEnabled(false);
sub.setOnClickListener(
new View.OnClickListener() {
public void onClick(View view) {
x = str.length();
str = name.getText().toString();
if (x >= 4 && x <= 10)
chk.setEnabled(true);
}
});
And here's the xml code for the submit button
<Button
android:id="#+id/submit"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/submit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I'm a beginner and it's my first app so please excuse me if you find it a naïve question.
The following is the logcat message:
12-11 22:55:20.678 4277-4277/com.example.shantanu.namerank D/AndroidRuntime: Shutting down VM
12-11 22:55:20.702 4277-4277/com.example.shantanu.namerank E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.shanu.namerank, PID: 4277
java.lang.NullPointerException: Attempt to invoke virtual method 'int'java.lang.String.length()' on a null object reference
at com.example.shanu.namerank.MainActivity$1.onClick(MainActivity.java:32)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
x = str.length();
str = name.getText().toString();
these lines are disordered. Put the first line second and second line first.
Looks like str variable is null because you didn't initialize it, but please post your logcat output to confirm it.
The problem is in the onClick() function:
public void onClick(View view) {
x = str.length(); // length of 'str' calculated first
str = name.getText().toString(); // 'str' initialized later
if (x >= 4 && x <= 10)
chk.setEnabled(true);
}
You are calculating length of str before initializing it.
The code should be:
public void onClick(View view) {
str = name.getText().toString();
x = str.length();
if (x >= 4 && x <= 10)
chk.setEnabled(true);
}
First, initialize the varible str and then calculate the length of str.
Hope that helps :)
I am trying to implement chips inside input field that beside chips can accept free text using library splitwise/TokenAutoComplete. One chip is #mention that shows user name.
User can enter sign # and after that popup will show and than user selects user from list. The # sign just triggers API call that fetches new data and updates adapter. After selecting user from list, chip will appear without # sign, just chip with name. Also user can enter some free text and after that if he wants to mention another user he just enters # and choose other user from list.
For example: user enters "Hello #mark and #paul", result should be "Hello Marc and Paul".
This works fine, but the problem is when i try to delete chips with backspace. I got exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.yyy, PID: 7859
java.lang.IndexOutOfBoundsException: charAt: 12 >= length 12
at android.text.SpannableStringBuilder.charAt(SpannableStringBuilder.java:116)
at com.tokenautocomplete.TokenCompleteTextView$TokenTextWatcher.afterTextChanged(TokenCompleteTextView.java:1325)
at android.widget.TextView.sendAfterTextChanged(TextView.java:9078)
at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:11739)
at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:976)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:520)
at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:216)
at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:33)
at android.view.inputmethod.BaseInputConnection.deleteSurroundingText(BaseInputConnection.java:246)
at android.view.inputmethod.InputConnectionWrapper.deleteSurroundingText(InputConnectionWrapper.java:66)
at com.tokenautocomplete.TokenCompleteTextView$TokenInputConnection.deleteSurroundingText(TokenCompleteTextView.java:1561)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:389)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
I don't know how to fix it, and what is causing this exception.
Here is my implementation of Tokenizer:
class UsernameTokenizer implements MultiAutoCompleteTextView.Tokenizer {
#Override
public CharSequence terminateToken(CharSequence text) {
int i = text.length();
while (i > 0 && text.charAt(i - 1) == ' ') {
i--;
}
if (text instanceof Spanned) {
SpannableString sp = new SpannableString(text + " ");
TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
return sp;
} else {
return text + " ";
}
}
#Override
public int findTokenStart(CharSequence text, int cursor) {
int i = cursor - 1;
while (i > 0 && text.charAt(i) != '#') {
i--;
}
if (i < 1 || text.charAt(i) != '#') {
return cursor;
}
return i;
}
#Override
public int findTokenEnd(CharSequence text, int cursor) {
int i = cursor;
int len = text.length();
while (i < len) {
if (text.charAt(i) == ' ') {
return i;
} else {
i++;
}
}
return len;
}
}
This question already has answers here:
Proper way to avoid parseInt throwing a NumberFormatException for input string: ""
(7 answers)
Closed 6 years ago.
I've tried lot of things found here, but it keeps crashing. I wanna know what do i need to add in order to show a Toast message when button is clicked and EditText is empty.
INFO: The app is supposed to send the two values in the EditText's to another activity, showing Toast's in the following exceptions:the first value higher than 6; the second value higher than (firstvalue*14); and if the fields are empty (which is my problem)
Here's my code:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
TextView saludo_bienvenida;
EditText et1_creditos;
EditText et2_faltas;
Button boton_ingresar;
Button boton_info;
String numero_creditos;
String numero_faltas_actuales;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
saludo_bienvenida = (TextView) findViewById(R.id.saludo_bienvenida);
et1_creditos = (EditText) findViewById(R.id.edittext1_numero_creditos);
et2_faltas = (EditText) findViewById(R.id.edittext2_numero_faltas);
boton_ingresar = (Button) findViewById(R.id.boton_ingresar);
boton_info = (Button) findViewById(R.id.boton_info);
if (boton_ingresar != null) {
boton_ingresar.setOnClickListener(this);
}
if (boton_info != null) {
boton_info.setOnClickListener(this);
}
et1_creditos.setInputType(InputType.TYPE_CLASS_NUMBER);
et2_faltas.setInputType(InputType.TYPE_CLASS_NUMBER);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.boton_ingresar:
numero_creditos = et1_creditos.getText().toString();
numero_faltas_actuales = et2_faltas.getText().toString();
int numero_creditos1 = Integer.parseInt(numero_creditos);
int numero_faltas_actuales1 = Integer.parseInt(numero_faltas_actuales);
int o = numero_creditos1 * 14;
if (numero_creditos1>6) {
Toast.makeText(getApplicationContext(), "Ingrese un número válido de créditos", Toast.LENGTH_LONG).show();
}else if (numero_faltas_actuales1 > o){
Toast.makeText(getApplicationContext(), "El número de faltas ingresadas es mayor que el número de horas del curso", Toast.LENGTH_LONG).show();
}else{
Intent intent = new Intent(MainActivity.this,Resultados.class);
intent.putExtra("numero_creditos",numero_creditos);
intent.putExtra("numero_faltas_actuales",numero_faltas_actuales);
startActivity(intent);
}
break;
case R.id.boton_info:
Intent informacion = new Intent(MainActivity.this,Informacion.class);
startActivity(informacion);
break;
}
}
}
This is the log:
06-17 01:36:17.419 2738-2738/absence_counter.app.jorgepasco.com.absencecounter E/AndroidRuntime: FATAL EXCEPTION: main
Process: absence_counter.app.jorgepasco.com.absencecounter, PID: 2738
java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parseInt(Integer.java:358)
at java.lang.Integer.parseInt(Integer.java:334)
at absence_counter.app.jorgepasco.com.absencecounter.MainActivity.onClick(MainActivity.java:60)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
So thanks you for your log !
You can see on your log that you have a problem when you parseInt. You try to parseInt an empty String.
So when the user do not write anything, you have to set a default value yourself.
You can do something like that before your parse:
if(numero_creditos.equals(""))
numero_creditos = "0";
But if I were you, I would force the user to right directly an integer
Please, show us your log box.
Perhaps the app crash because you don't have any default case in your switch case. So if v.getId() is not what you think, it will crash.
Simply, add that at the end of your switch case:
switch(v.getId()){
case: ...
case: ...
default: Toast.makeText(getApplicationContext(),"v.getId = " + v.getId());
}
But I would be easier for me to solve your problem with your log box !
et1_creditos.getText() can maybe send a null value. Then null.toString() has no sense because null does not have toString().
try:
String creditos = et1_creditos.getText()
if(creditos != null){
//stuff here
}
It is failing on this line.
int numero_creditos1 = Integer.parseInt(numero_creditos);
If your numeor_creditos is empty it won't be integer.
Try
int numero_creditos1;
if(TextUtils.isEmpty(numero_creditos){
numero_creditos1 = 0;
} else {
numero_creditos1 = Integer.parseInt(numero_creditos);
}