Hi! I'm getting this error that says that I need another '}'... The problem is that I have all of the needed ones


The error report is:

"Syntax error, insert "}" to complete ClassBody"

The problem is that you don't have all the needed ones.
Or, possibly, you have found a bug in the Java compiler that not one of the thousands and thousands of users have discovered in the last 2 decades.
So, less self-confidence and more careful code reading.

Ok, I have re-gone through the my code and yes, I have all of the needed '}'s... I even tried adding more to see if the compiler likes it then... It gives me the same error... What do you (or anyone else) suggest I do?

Post the code here (in code tags, indented)

Also, look immediately after the place where the } was requested - you may have some other error that makes the compiler think you must have finished the current class definition

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;


public class parse {
	public void print(String out,boolean line)
	{
		if(line)
		{
			System.out.println(out);
		}
		else
		{
			System.out.print(out);
		}
	}
String place;
char []go={'p','r','i','n','t',' '};
String cmd;
Cmds cmds;
public void getId()
{
	cmd=go.toString();
}
BufferedReader br1 =null;
public void createFileReader()
{
	try{
	 br1 = new BufferedReader(new FileReader("home/jack/abcd.txt"));//declare in
	 if(br1.ready())
	 {
		 print("Application ready!",true);
	 }
	 else
	 {
		 print("Application Failure",true);
	 }
	}
	catch(Exception e)
	{
		
	}
}

@SuppressWarnings("null")
public void getID()
{int i=0;char []use=null;
try{
	
	for (;i<100;i++)//use will have a length of 100
	{
		use[i]='a';//keep as a until rewrite
	}
}
catch (Exception e)
{
	
}
	i=0;
	try{
	while (i!=' '||i!='\n')//read go to use until we encounter a  space or newline
	{
		use[i]=(char) br1.read();
		i++;
	}}
	catch(Exception e)
	{
		
	}
	
	//String toEnum=use.toString();
	cmd=use.toString();//put use into enum form
	
//}	
}
}
}//why do we need another?


/*//this is used for getting the next command
 * 	
	try{
	while (i!=' '||i!='\n')//read go to use until we encounter a  space or newline
	{
		go[i]=use[i];
		i++;
	}}
	catch(Exception e)
	{
		
	}
 */
*/

There's the code, and I don't think theres a class end, though I know only one way to do that ('}')...


Please tell me if you find something that I don't

Problem is on you very last line. If we delete the final comment block then we are left with...

...
	//String toEnum=use.toString();
	cmd=use.toString();//put use into enum form
	
//}	
}
}
}//why do we need another?

*/

Delete the incorrectly duplicated */ and its OK

Ahhh... I had caught that just a few minutes after I had posted.

Now, I'm actually trying to do what I was in a faster, more compact and (hopefully) easier way (I was having soooo much trouble with File I/O, especially reading.

thanks,
JT

int i=0;
char []use=null;
try {
  for (;i<100;i++)//use will have a length of 100 
  {
    use[i]='a';//keep as a until rewrite
  }
}
catch (Exception e) {
}

That looks wrong.
Array "use" is null, then you try to access elements in this (non-existent) array, and use an empty catch block to ignore the resulting NPE.
Maybe I misunderstand your code, or is this something more cunning than it appears?

Well, I want to be able to make use[] more or less, depending on the situation...

So, I'm using this loop

for (;i<100;i++)//use will have a length of 100 
  {
    use[i]='a';//keep as a until rewrite
  }
}

as a way on creating the array use[]... Because I tested that, I'm almost positive that that works.

The one problem is that it does return the NPE (NullPointerException) even though I told it through the loop that the array is real.

There are two separate steps needed to create an initialised array.

1. You create an array of a given size, as in

int size = 100;
char[] use = new char[size];

use now contains 100 uninitialised slots (not strictly true for an array of primitives, but still the safest way to think about it)

2. Now you can fill those slots with values, as in

for (int i = 0;i<size;i++){
   use[i]='a';//keep as a until rewrite
}

You were getting the NPEs that you had to suppress because you omitted the first step, and were trying to put things into an array that didn't exist yet.

Ok, Thanks.

I come from C/C++ where you can do that, so I thought you could do that. Also, It "seemed" to be working, it wasn't.

Thanks,
JT

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.