Hi,

I am getting the following errors:

HelloWorldApp.java:54: <identifier> expected
public static Vector<int[]> breakTheMovementVector(int i,int j){
^
HelloWorldApp.java:102: ';' expected
}
^
2 errors

import java.io.*;
import java.util.*;
class HelloWorldApp {
    public static void main(String[] args) {
        try{
    // Open the file that is the first 
    // command line parameter
	String fname=args[0];
	int x=0;
    FileInputStream fstream = new FileInputStream(fname);
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine="",str1="";
    //Read File Line By Line
    while (x<2)   {
      // Print the content on the console
	  strLine = br.readLine();
	  x++;
	  if(x==1)str1=strLine;
	  if (x==2)
	  {
		  str1 = str1+" "+strLine;
	  }
	  // System.out.println (str1);
     
    }
    while ((strLine = br.readLine()) != null) 
	
			{

   System.out.println (strLine);
			}
	StringTokenizer st = new StringTokenizer(str1);
	st.nextToken();
    String width=st.nextToken();
	st.nextToken();
	String height = st.nextToken();
    //Close the input stream
	System.out.print ("width ");
	 System.out.println (width);
System.out.print ("height is  ");
	 System.out.println (height);
    in.close();
    }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }


    }

	//BreaktheMovement Vector

public static Vector<int[]> breakTheMovementVector(int i,int j){
                               
							   Vector<int[]> result=new Vector<int[]>();
                                int signOfI;
                                int signOfJ;
                                double ii=new Double(Math.abs(i));
                                double jj=new Double(Math.abs(j));
                                if(i==0 && j==0)
                                return result;
                                if(i>0) signOfI=1; else signOfI=-1;
                                if(j>0) signOfJ=1; else signOfJ=-1;
											if (j==0){
											for (int f=0;f<ii;f++){
											int[] point={signOfI,0};
											result.add(point);
											}
                                            return result;
                                           }
										if (i==0){
										for (int f=0;f<jj;f++){
										int[] point={0,signOfJ};
										result.add(point);
										}
										return result;
										}
										Double a=1.0;
										Double b=1.0;
										double cross=((ii/jj)*(a-.5)+.5);
										while (b<=ii || a<=jj){
										if (b>cross){
										int[] point={0,signOfJ};
										result.add(point);
										a++;
										cross=((ii/jj)*(a-.5)+.5);
										}else if (b==cross){
										int[] point={signOfI,signOfJ};
										result.add(point);
										a++;
										b++;
										cross=((ii/jj)*(a-.5)+.5);
										}else if (b<cross){
										int[] point={signOfI,0};
										result.add(point);
										b++;
										}
										}
										return result;
												}
}

Dani AI

Generated

reposted a cleaned-up version that compiled, so the problem in the original case was most likely environmental or file-related rather than a logic/syntax error in the Java language itself. Common root causes for the parser to complain at the start of a method declaration are: an older compiler compliance level, invisible/non-ASCII bytes in the source (BOM or zero-width characters), HTML-escaped text left in the file after copying, or an unmatched brace earlier in the file that leaves the compiler in the wrong parsing context.

Quick checklist and concrete checks:

  • Verify the Java compiler and project compliance level (generics and newer syntax require Java 5+).
  • Confirm the source file encoding and remove any BOM or stray control characters; web copies sometimes introduce HTML entities instead of raw symbols.
  • Use the IDE formatter and brace-matching to reveal mismatched braces or stray tokens.
  • Reproduce in a fresh file: paste pieces in incrementally and compile as each piece is added to isolate the offending fragment.

Minimal commands and tips to try (run in a shell or use the equivalent IDE actions):

javac -version
javac -source 1.6 -encoding UTF-8 HelloWorldApp.java

# quick hex check (Unix)
xxd HelloWorldApp.java | head

# on Windows: open in Notepad++ and choose Encoding -> UTF-8 without BOM

Isolation workflow: create a new class file, add the class skeleton, then paste the problematic method header and body bit by bit until compilation fails. If the fresh file compiles, diff the files or open them in a hex/viewer to find invisible differences. As a general note, generics require reference types (primitive types must be boxed), while array types are reference types and can be used as type arguments. Also heed 's point about submitting only the minimal failing example when seeking help; that keeps answers focused and avoids exposing whole assignments.

Recommended Answers

All 7 Replies

Sorry the code which I posted earlier was not properly indented.

import java.io.*;
import java.util.*;
class HelloWorldApp {
    public static void main(String[] args) {
        try{
    // Open the file that is the first 
    // command line parameter
	String fname=args[0];
	int x=0;
    FileInputStream fstream = new FileInputStream(fname);
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine="",str1="";
    //Read File Line By Line
    while (x<2)   {
      // Print the content on the console
	  strLine = br.readLine();
	  x++;
	  if(x==1)str1=strLine;
	  if (x==2)
	  {
		  str1 = str1+" "+strLine;
	  }
	  // System.out.println (str1);
     
    }
    while ((strLine = br.readLine()) != null) 
	
			{

   System.out.println (strLine);
			}
	StringTokenizer st = new StringTokenizer(str1);
	st.nextToken();
    String width=st.nextToken();
	st.nextToken();
	String height = st.nextToken();
    //Close the input stream
	System.out.print ("width ");
	 System.out.println (width);
System.out.print ("height is  ");
	 System.out.println (height);
    in.close();
    }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }


    }

	//BreaktheMovement Vector

public static Vector<int[]> breakTheMovementVector(int i,int j){
                               
	   Vector<int[]> result=new Vector<int[]>();
		int signOfI;
		int signOfJ;
		double ii=new Double(Math.abs(i));
		double jj=new Double(Math.abs(j));
		if(i==0 && j==0)
		return result;
		if(i>0) signOfI=1; else signOfI=-1;
		if(j>0) signOfJ=1; else signOfJ=-1;
					if (j==0){
					for (int f=0;f<ii;f++){
					int[] point={signOfI,0};
					result.add(point);
					}
					return result;
				   }
				if (i==0){
				for (int f=0;f<jj;f++){
				int[] point={0,signOfJ};
				result.add(point);
				}
				return result;
				}
				Double a=1.0;
				Double b=1.0;
				double cross=((ii/jj)*(a-.5)+.5);
				while (b<=ii || a<=jj){
				if (b>cross){
				int[] point={0,signOfJ};
				result.add(point);
				a++;
				cross=((ii/jj)*(a-.5)+.5);
				}else if (b==cross){
				int[] point={signOfI,signOfJ};
				result.add(point);
				a++;
				b++;
				cross=((ii/jj)*(a-.5)+.5);
				}else if (b<cross){
				int[] point={signOfI,0};
				result.add(point);
				b++;
				}
				}
				return result;
						}
}

Second version compiles without error for me.
Indentation is still useless - here's Eclipse's version.

class HelloWorldApp {

   public static void main(String[] args) {
      try {
         // Open the file that is the first 
         // command line parameter
         String fname = args[0];
         int x = 0;
         FileInputStream fstream = new FileInputStream(fname);
         // Get the object of DataInputStream
         DataInputStream in = new DataInputStream(fstream);
         BufferedReader br = new BufferedReader(new InputStreamReader(in));
         String strLine = "", str1 = "";
         //Read File Line By Line
         while (x < 2) {
            // Print the content on the console
            strLine = br.readLine();
            x++;
            if (x == 1) str1 = strLine;
            if (x == 2) {
               str1 = str1 + " " + strLine;
            }
            // System.out.println (str1);

         }
         while ((strLine = br.readLine()) != null)

         {

            System.out.println(strLine);
         }
         StringTokenizer st = new StringTokenizer(str1);
         st.nextToken();
         String width = st.nextToken();
         st.nextToken();
         String height = st.nextToken();
         //Close the input stream
         System.out.print("width ");
         System.out.println(width);
         System.out.print("height is  ");
         System.out.println(height);
         in.close();
      } catch (Exception e) {//Catch exception if any
         System.err.println("Error: " + e.getMessage());
      }

   }

   //BreaktheMovement Vector

   public static Vector<int[]> breakTheMovementVector(int i, int j) {

      Vector<int[]> result = new Vector<int[]>();
      int signOfI;
      int signOfJ;
      double ii = new Double(Math.abs(i));
      double jj = new Double(Math.abs(j));
      if (i == 0 && j == 0) return result;
      if (i > 0) signOfI = 1;
      else signOfI = -1;
      if (j > 0) signOfJ = 1;
      else signOfJ = -1;
      if (j == 0) {
         for (int f = 0; f < ii; f++) {
            int[] point = { signOfI, 0 };
            result.add(point);
         }
         return result;
      }
      if (i == 0) {
         for (int f = 0; f < jj; f++) {
            int[] point = { 0, signOfJ };
            result.add(point);
         }
         return result;
      }
      Double a = 1.0;
      Double b = 1.0;
      double cross = ((ii / jj) * (a - .5) + .5);
      while (b <= ii || a <= jj) {
         if (b > cross) {
            int[] point = { 0, signOfJ };
            result.add(point);
            a++;
            cross = ((ii / jj) * (a - .5) + .5);
         } else if (b == cross) {
            int[] point = { signOfI, signOfJ };
            result.add(point);
            a++;
            b++;
            cross = ((ii / jj) * (a - .5) + .5);
         } else if (b < cross) {
            int[] point = { signOfI, 0 };
            result.add(point);
            b++;
         }
      }
      return result;
   }
}

Stop posting your CSCI561 code to the internet. You are going to cause others to copy your code.

Stop posting your CSCI561 code to the internet. You are going to cause others to copy your code.

I don't know whether this is addressed to techie929 or to me, but either way your criticism is unfounded.

techie929 posted his code because he wanted help with compile errors. That's what we do here, we help people, and if he didn't post his code we couldn't help.

I took the code from his second post, ran it through Eclipse's source formatter and re-posted it so he could see that his idea of "properly indented" wasn't that good. I personally have no idea what CSCI561 is.

maybe LabsID

maybe so, perhaps I should have said "personally I neither know nor care care what CSCI561 is"!
I just had my feathers ruffled by a first-time anonymous poster criticising a perfectly normal and valid series of Daniweb posts. Time to move on...

that's true,

negative
... other hand, this forum has "more of democracy" as another forum where I meberber of, that very ... and counterproductive, topic by topic is very same, someone spllit out, hmmm then there is so difficult to choose if this post is about lazzynes, total ignore, soooo stopt and this people really need our hepl, maybe she/he want to learn more, yes, no or maybe its hard to decide, the result is superficiality

good/possitive ...but here isn't arrogance and personal attack

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.