Hello, I've written a fairly simple program to print a string in a window...But my Java compiler (JGrasp) will not compile it. It says:

JDemoGraphics.java:7: cannot find symbol
symbol : method String(java.lang.String)
location: class JDemoGraphics
String companyName = String("Event Handlers Incorporated");
^
I've checked my capitalization, run a debugging program, and even added another import function.

I'm sure the answer is obvious, but I'm new enough to programming that I can't figure it out.

Thanks in advance for the help.

import javax.swing.*;
import java.awt.*;
import java.util.*;

public class JDemoGraphics extends JFrame
{
	String companyName = String("Event Handlers Incorporated");

	public JDemoGraphics()
		{
			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		}

	public void paint(Graphics gr)
		{
			super.paint(gr);
			gr.drawString(companyName, 30, 100);
		}

	public static void main(String[] args)
	{
		JDemoGraphics frame = new JDemoGraphics();
		frame.setSize(300, 200);
		frame.setVisible(true);
	}
}

Recommended Answers

All 3 Replies

Shouldn't your String be initialized like this?

String companyName = "Event Handlers Incorporated";

Aha! That did it...The tutorial on the website that I've been running through told me to use the

String companyName = String("Event Handlers Incorporated");

Thanks!

Aha! That did it...The tutorial on the website that I've been running through told me to use the

String companyName = String("Event Handlers Incorporated");

Thanks!

You're Welcome! I think it would also work if you used (but I'm not sure)

String companyName =  new String("Event Handlers Incorporated");

but it would just be waste of typing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.