• Post Reply Bookmark Topic Watch Topic
  • New Topic

JAVA Eclipse JOptionPane Array  RSS feed

 
Axel ostermaier
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i am a real Beginner. I hope you can help me.
I try to programm a Array with the JOptionPane mask.
But it dont work. I dont know what i can do now.

This is the Code:

import javax.swing.JOptionPane;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class Hauptfenster extends JFrame {

private JPanel contentPane;

/**
* Launch the application.
*/
public static void main(String[] args) {
int Arraygröße;
int Zähler = 0;


String a = JOptionPane.showInputDialog (null, "Geben sie ihren Namen ein");
if (a.equals("Axel"))
{
JOptionPane.showMessageDialog (null, "Access");
}
else
{
JOptionPane.showMessageDialog (null, "No Access");
System.exit(0);
}

--fail1-Arraygröße = JOptionPane.showInputDialog (null, "Wie viele Zahlen geben sie ein?");

--fail2-while (Arraygröße != Zähler) {
int [] array = new int[JOptionPane.showInputDialog (null, "Geben sie ihre Zahlen ein")];
Zähler =(Zähler + 1);
}
--fail3-JOptionPane.showMessageDialog (null, array);


}

At the Fail feelds Eclipse tells me:
Fail1: Multiple markers at this line
- Line breakpoint:Hauptfenster [line: 33] -
main(String[])
- Type mismatch: cannot convert from String to
int

Fail2:Multiple markers at this line
- Line breakpoint:Hauptfenster [line: 36] -
main(String[])
- Type mismatch: cannot convert from String to
int

Fail3:Multiple markers at this line
- array cannot be resolved to a variable
- Line breakpoint:Hauptfenster [line: 39] -
main(String[])

Can you Please help me. I have some ideas why it not works, or why it says that "array" is not deklariert.

 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Type mismatch: cannot convert from String to int


JOptionPane.showInputDialog() method returns string and you are collecting it in int object hence the exception.

Thanks,
Ashwini Kashyap | www.infocepts.com
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!