.class Error

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 1504 Views - Last Post: 24 March 2009 - 01:33 PM Rate Topic: -----

#1 natep67   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 66
  • Joined: 22-October 08

.class Error

Posted 23 March 2009 - 01:42 PM

Hey i cant figure out what im doing wrong here
ik its probably a brace or something but i cant figure out where
import java.util.Scanner;
public class People
{
	 public static void main(String[] args) 
{
  int arraySize;
  String names;
  String nameInput;
  nameInput=input.next;
  Scanner input = new Scanner(System.in);

  {
	System.out.println("how many names?");
	arraySize= input.nextInt();
	System.out.println(arraySize);
	  System.out.println("Input names");
	  String names[] = nameInput[];
	  System.out.println(names);
  }

}
}


Is This A Good Question/Topic? 0
  • +

Replies To: .class Error

#2 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: .class Error

Posted 23 March 2009 - 01:49 PM

Whats the error that you are getting?
nameInput=input.next;
needs to go below the scanner declaration, and alson needs to be next()
Was This Post Helpful? 0
  • +
  • -

#3 natep67   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 66
  • Joined: 22-October 08

Re: .class Error

Posted 23 March 2009 - 01:52 PM

View PostFuzzyness, on 23 Mar, 2009 - 12:49 PM, said:

Whats the error that you are getting?
nameInput=input.next;
needs to go below the scanner declaration, and alson needs to be next()



"Error: '.class' expected" is the error im getting
Was This Post Helpful? 0
  • +
  • -

#4 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: .class Error

Posted 23 March 2009 - 01:55 PM

Did you import Array? Can't create an array if its not imported
Was This Post Helpful? 0
  • +
  • -

#5 natep67   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 66
  • Joined: 22-October 08

Re: .class Error

Posted 23 March 2009 - 01:56 PM

i just added it and it still has the same error
Was This Post Helpful? 0
  • +
  • -

#6 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: .class Error

Posted 23 March 2009 - 01:59 PM

Well what line does it say the error is on?
Was This Post Helpful? 0
  • +
  • -

#7 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: .class Error

Posted 23 March 2009 - 02:03 PM

At one point during the program you are declaring your variables as strings. Then in another part you are re-declaring them as arrays. You cannot do this. Variables can only be initialized once. For example your names variable.
Was This Post Helpful? 0
  • +
  • -

#8 natep67   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 66
  • Joined: 22-October 08

Re: .class Error

Posted 23 March 2009 - 02:22 PM

line 17


this line
String names[] = nameInput[];
Was This Post Helpful? 0
  • +
  • -

#9 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: .class Error

Posted 23 March 2009 - 02:23 PM

It's like what i said. You are creating your array's wrong. In order to create an array correctly it needs to be...

String [] arrayName;

And not create it as a string and then make it into an array later. you can't do this.
Was This Post Helpful? 0
  • +
  • -

#10 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: .class Error

Posted 23 March 2009 - 02:24 PM

Its as mark said, you already have a variable that is a string names, cant make a array with name of names. doesnt work well. change one of them
Was This Post Helpful? 0
  • +
  • -

#11 thebpf   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 42
  • Joined: 19-March 09

Re: .class Error

Posted 23 March 2009 - 02:25 PM

View Postnatep67, on 23 Mar, 2009 - 12:42 PM, said:

Hey i cant figure out what im doing wrong here
ik its probably a brace or something but i cant figure out where
import java.util.Scanner;
public class People
{
	 public static void main(String[] args) 
{
  int arraySize;
  String names;
  String nameInput;
  nameInput=input.next;
  Scanner input = new Scanner(System.in);

  {
	System.out.println("how many names?");
	arraySize= input.nextInt();
	System.out.println(arraySize);
	  System.out.println("Input names");
	  String names[] = nameInput[];
	  System.out.println(names);
  }

}
}


Just remove the opening curly bracket after:

Scanner input = new Scanner(System.in);

and the closing curly bracket.
Was This Post Helpful? 0
  • +
  • -

#12 natep67   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 66
  • Joined: 22-October 08

Re: .class Error

Posted 23 March 2009 - 02:27 PM

even if i declare it lik that it doesnt change anything. i could take out the line String[] names; it still has the same error
Was This Post Helpful? 0
  • +
  • -

#13 natep67   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 66
  • Joined: 22-October 08

Re: .class Error

Posted 23 March 2009 - 02:34 PM

and curly brackets dont work either


and curly brackets dont work either
Was This Post Helpful? 0
  • +
  • -

#14 thebpf   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 42
  • Joined: 19-March 09

Re: .class Error

Posted 23 March 2009 - 02:41 PM

View Postnatep67, on 23 Mar, 2009 - 01:27 PM, said:

even if i declare it lik that it doesnt change anything. i could take out the line String[] names; it still has the same error


Are you trying to enter a line of names and place them into a string array? if so you are going about it the wrong way.
Try:
import java.util.Scanner;
import java.util.Vector;

public class People
{
	 public static void main(String[] args) {
	   Vector names = new Vector();
	   Scanner input = new Scanner(System.in);

	   while (input.hasNext()) {
		 names.add(input.next());
	   }

	   System.out.println("how many names?");
	   System.out.println(names.size());
	   System.out.println("Input names");
	   System.out.println(names);
	 }
}


Was This Post Helpful? 0
  • +
  • -

#15 natep67   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 66
  • Joined: 22-October 08

Re: .class Error

Posted 23 March 2009 - 02:45 PM

that seems to be working but i never get to the printlines b/c its always asking for another input
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2