
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For inpu t string: "1
Publicado por Lucho9964 (17 intervenciones) el 04/04/2020 01:54:29
Hola chicos este es mi codigo: no se porque me marca error, si alguien sabe. Gracias.
cada vez que doy en el boton aceptar me marca este error.
y este el error:
********
*Error:*
********
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For inpu
t string: "1
"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.math.BigInteger.<init>(Unknown Source)
at java.math.BigInteger.<init>(Unknown Source)
at NumerosPrimos.actionPerformed(NumerosPrimos.java:74)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
cada vez que doy en el boton aceptar me marca este error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.util.Scanner;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.math.BigInteger;
public class NumerosPrimos extends JFrame implements ActionListener{
private JLabel l1, l2, l3;
private JTextField tf1;
private JTextArea ta1;
private JScrollPane sp1;
private JButton b1;
String s1 = "";
public NumerosPrimos(){
setLayout(null);
getContentPane().setBackground(new Color(0,0,0));
setTitle("#Primo?");
l1 = new JLabel("Introduce tu numero: ");
l1.setBounds(10,10,200,20);
l1.setFont(new Font("Time New Romans", 0, 14));
l1.setForeground(new Color(230,230,230));
add(l1);
l2 = new JLabel("Tu numero Si es Primo");
l2.setBounds(10,80,100,20);
l2.setFont(new Font("Time New Romans", 0, 14));
l2.setForeground(new Color(230,230,230));
add(l2);
l2.setVisible(false);
l3 = new JLabel("Tu numero No es primo");
l3.setBounds(10,80,100,20);
l3.setFont(new Font("Time New Romans", 0, 14));
l3.setForeground(new Color(230,230,230));
add(l3);
l3.setVisible(false);
tf1 = new JTextField();
tf1.setBounds(10,40,150,30);
tf1.setBackground(new Color(230,230,230));
tf1.setFont(new Font("Time New Romans", 0, 12));
tf1.setForeground(new Color(0,0,0));
add(tf1);
ta1 = new JTextArea();
ta1.setEditable(false);
sp1 = new JScrollPane(ta1);
sp1.setBounds(10,150,400,500);
sp1.setBackground(new Color(30,30,30));
sp1.setFont(new Font("Time New Romans", 0, 12));
sp1.setForeground(new Color(230,230,230));
add(sp1);
b1 = new JButton("Aceptar");
b1.setBounds(10,110,150,30);
b1.setBackground(new Color(30,30,30));
b1.setFont(new Font("Time New Romans", 0, 14));
b1.setForeground(new Color(230,230,230));
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent s){
if(s.getSource() == b1){
s1 += tf1.getText().replaceAll("\\s","");
if(s1.equals("")){
JOptionPane.showMessageDialog(null, "Debe ingresar un numero");
}else{
s1 += "\n";
BigInteger bi1 = new BigInteger(s1);
BigInteger a = new BigInteger("1");
BigInteger b = new BigInteger("2");
BigInteger c = new BigInteger("3");
BigInteger d = new BigInteger("5");
BigInteger e = new BigInteger("7");
int f;
int g;
int h;
int i;
int j;
BigInteger k;
BigInteger l;
BigInteger m;
BigInteger n;
int o;
int p;
int q;
int r;
f = bi1.compareTo(a);
g = bi1.compareTo(b);
h = bi1.compareTo(c);
i = bi1.compareTo(d);
j = bi1.compareTo(e);
k = bi1.mod(b);
l = bi1.mod(c);
m = bi1.mod(d);
n = bi1.mod(e);
o = k.compareTo(a);
p = l.compareTo(a);
q = m.compareTo(a);
r = n.compareTo(a);
if(g==0 || h==0 || i==0 || j==0){
String s2 = new String("el numero" + bi1 + "Si es primo");
ta1.setText(s2);
tf1.setText("");
}else if(f<=0 || o==-1 || p==-1 || q==-1 || r==-1){
String s3 = new String("el numero" + bi1 + "No es primo");
ta1.setText(s3);
tf1.setText("");
}else{
String s4 = new String("el numero" + bi1 + "Si es primo");
ta1.setText(s4);
tf1.setText("");
}
}
}
}
public static void main(String args[]){
NumerosPrimos np1 = new NumerosPrimos();
np1.setBounds(0,0,430,740);
np1.setVisible(true);
np1.setResizable(false);
np1.setLocationRelativeTo(null);
}
}
y este el error:
********
*Error:*
********
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For inpu
t string: "1
"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.math.BigInteger.<init>(Unknown Source)
at java.math.BigInteger.<init>(Unknown Source)
at NumerosPrimos.actionPerformed(NumerosPrimos.java:74)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Valora esta pregunta


0