Jump to content

Why doesn't this work?

grimFandingo
Go to solution Solved by rufee,

Well im no expert in Java, but aren't you passing too much parameters into the toString() function ?

Hi I am making a simple Decimal to binary converter with a simple GUI in Java;

 

However I seem to have hit a snag that I hope one of you will be able to help with.

 

Main Class:

import javax.swing.JOptionPane;import javax.swing.JFrame;import java.awt.*;import javax.swing.*;public class mainClass{		static int decimal;		public static void main (String[]args){			//Input Box	String decimal =JOptionPane.showInputDialog(null, "Please Enter a Number: ", 				"Decimal to Binary Converter", JOptionPane.PLAIN_MESSAGE);				textBox.createWindow();	}}

GUI Class
 

import javax.swing.JOptionPane;import javax.swing.JFrame;import java.awt.*;import javax.swing.*;public class textBox {		public static void createWindow(){		JFrame frame = new JFrame("Decimal to Binary Converter");		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 		 JLabel textLabel = new JLabel(mainClass.decimal + " In Binary is -> " + Integer.toString(mainClass.decimal, 2,				 SwingConstants.CENTER)); textLabel.setPreferredSize(new Dimension(300, 100)); 				 frame.getContentPane().add(textLabel, BorderLayout.CENTER);				 frame.setLocationRelativeTo(null); 				 frame.pack(); 				 frame.setVisible(true); 				 	}}

 on the JFrame textLabel decolarion line above, I get the following error: 

 

"the method toString (int, int) in the type integer is not applicable for the arguments  (int,  int, int)"

 

I cannot figure out why

Link to comment
Share on other sites

Link to post
Share on other sites

Well im no expert in Java, but aren't you passing too much parameters into the toString() function ?

Something wrong with your connection ?

Run the damn cable :)

Link to comment
Share on other sites

Link to post
Share on other sites

Well im no expert in Java, but aren't you passing too much parameters into the toString() function ?

I just deleted some of the parameters and it worked, thanks man!

Link to comment
Share on other sites

Link to post
Share on other sites

The result of your program will be

 

"0 in binary is -> 0" - regardless of what you put in to the input box.

 

I can tell you why if you'd like?

Case Bitfenix Shinobi | CPU - i5 3570K @ 4.2Ghz | Motherboard -  Asus P8Z77 | GPU - 7870 | PSU - Corsair CXM 600w | 
Harddrive - Seagate Barracuda 1Tb x 2 | SSD - Samsung 840 256Gb | Cooling - Custom 2x Dual 120mm Radiator, Watercooling Loop |

Ultimate Programming Resources Thread ||| CompSci Masters Degree Student and Professional Java and C# Programmer

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×