2 Replies - 9386 Views - Last Post: 25 July 2009 - 10:11 AM Rate Topic: -----

#1 Gsirtak  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 72
  • Joined: 30-June 09

unclosed string literal error

Post icon  Posted 25 July 2009 - 10:01 AM

I have an unclosed String literal error on line 32,
System.out.println("My name is " + " nflplayersreference[i].getName());.
	 public abstract class NFLPlayersReference {
	private static Runningback[] nflplayersreference;
	private static Quarterback[] players;
	private static WideReceiver[] nflplayers;

	public static void main(String args[]){

	Runningback r = new Runningback("Thomlinsion");
	Quarterback q = new Quarterback("Tom Brady");
	WideReceiver w = new WideReceiver("Steve Smith");
	NFLPlayersReference[] NFLPlayersReference;


		Run();// {
		NFLPlayersReference = new NFLPlayersReference [3];
		nflplayersreference[0] = r;
		players[1] = q;
		nflplayers[2] = w;


			for ( int i = 0; i < nflplayersreference.length; i++ ) {
			System.out.println("My name is " + " nflplayersreference[i].getName());
			nflplayersreference[i].run();
			nflplayersreference[i].run();
			nflplayersreference[i].run();
			System.out.println("NFL offensive threats have great running abilities!");
		}

	}

	private static void Run() {
		System.out.println("Not yet implemented");
	}	   

}


Is This A Good Question/Topic? 0
  • +

Replies To: unclosed string literal error

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: unclosed string literal error

Posted 25 July 2009 - 10:10 AM

You're missing a double quote, however, just get rid of that single one since you don't need to put quotes around data being inserted into the string concatenation.

			System.out.println("My name is " + nflplayersreference[i].getName());


This post has been edited by KYA: 25 July 2009 - 10:10 AM

Was This Post Helpful? 1
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10566
  • View blog
  • Posts: 39,107
  • Joined: 27-December 08

Re: unclosed string literal error

Posted 25 July 2009 - 10:11 AM

Let's take a look at your println() statement.

System.out.println("My name is " + " nflplayersreference[i].getName());



Here, you begin & end the String "My name is " with double quotes. After the plus sign, you begin a new String literal with a double quote (") but never end the literal with another double quote ("). In order for something to be read literally (meaning the computer doesn't check for a variable), double quotes have to surround the phrase/String, or if it is a character then single quotes must surround the literal.

However, it looks like you're trying to insert a variable here, so remove the 3rd double quote:

System.out.println("My name is " + nflplayersreference[i].getName());



Also, look through your code to make sure all variables have been
1- declared
2- initialized before they are called
3- Named correctly (ie, the datatype cannot be the name of a field)

If you still have trouble after this, feel free to post again.
Hope this helps!

This post has been edited by macosxnerd101: 25 July 2009 - 10:12 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1