Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Errors when compiling this code  RSS feed

 
Sam Coote
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am only a learner coder. I am having trouble with this code here. I am hoping someone can give me a few hinters with what i need to do. I keep getting the error

import java.lang.Object.*;
> import java.awt.*;
> import javax.swing.*;
>
> public class JDisplay
> {
> private Maximum in;
> private JWindow win;
> private int maxValue;
> private JTextArea text;
> private int[] values;
> private int counter;
>
> public JDisplay()
> {
> in = new Maximum();
> maxValue = in.getMax();
> win = new JWindow(0, 0, 300, 300);
> text = new JTextArea(0,0,300,300);
>>>>>>>>>>>>>>>>>>>>>>>> Error here saying cant find Symbol -
constructor

JWindow(int,int,int,int)
> text.setBackground(Color.yellow);
> text.setFontSize(20);
> values = in.getValues();
> for (int i = 0; i < maxValue; i++){
> text.appendln("Frog");
>
> }
> for (int j = 0; j < in.getCounter();j++){
> text.append(values[j]+ " ");
> }
> text.place(win);
> win.repaint();
> }
>
>
> }
>
> Maximum Class
> import java.util.*;
>
> public class Maximum{
> private int max;
> private int[] values;
> private int counter;
>
> public Maximum(){
> Scanner input = new Scanner(System.in);
> values = new int[30];
> int num = 0;
> int i = 0;
> System.out.println("Enter an integer");
> while(input.hasNext()){
> if (input.hasNextInt()){
> num = input.nextInt();
> values[counter++] = num;
> if (num > max) max = num;
> }
> else{
> if (input.findInLine("exit") != null) break;
> }
> }
> System.out.println("The max is " + max);
> }
>
> public int getMax(){
> return max;
> }
> public int[] getValues(){
> return values;
> }
> public int getCounter(){
> return counter;
> }
> }
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could see the following problems

You do not need to import java.lang.* package.

The following line is wrong:
import java.lang.Object.*;
there is no java.lang.Object package.

There is no constructor in JTextArea object which accepts 4 integer values. So the following line is wrong:
text = new JTextArea(0,0,300,300);

Not sure if there are more problems in your code.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

What error is it you're getting? Post the full stack trace.
 
Sam Coote
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the error is cant find Symbol -
constructor JWindow(int,int,int,int)

do you have any coding suggestions i could use
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam Coote:
the error is cant find Symbol -
constructor JWindow(int,int,int,int)

do you have any coding suggestions i could use


Look at the following Java api for valid constructors for JTextArea:
JTextArea

As Ulf suggested if you tell what errors you are getting or post full stack trace it is easier to guide you.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the error is cant find Symbol - constructor JWindow(int,int,int,int)

do you have any coding suggestions i could use


Yes - use a constructor that actually exists JWindow does not have a constructor that takes 4 ints, just like the error message suggests.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!