CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Mar 2009
    Posts
    48

    class array issue

    If anyone can explain the compiler error below I'd be grateful and it would end hours of torment. I'm sure its simple but I can't see it. The highlighted error in Eclipse is in bold (line 25).

    And any smooth way to initialise a class array when you do not know how many elements you want? I thought the method here would work but perhaps not.

    Thanks in anticipation.

    The error: No enclosing instance of type autodefcreate is accessible. Must qualify the allocation with an enclosing instance of type autodefcreate (e.g. x.new A() where x is an instance of autodefcreate).

    at autodef.autodefcreate.main(autodefcreate.java:25)


    Code:
    package autodef;
    import java.io.*;
    public class autodefcreate {
    	String scriptname;
    	public static void main(String[] args) {
    	
    	String scriptname;
    	// read *.def and store value, database and column name in arrays
    				
    		try {
    		             if (args[0] == null) {
    		            	 scriptname = "fred";
    		             }
    		             else {
    		            	 scriptname = args[0];
    		            }
    		             System.out.println(scriptname);
    		             FileReader input = new FileReader(scriptname + ".def");
            
    		              /* Filter FileReader through a Buffered read to read a line at a
    		                 time */
    		              BufferedReader bufRead = new BufferedReader(input);
    		              
    		              defvariable[] arraydef = new defvariable[5];  // array to hold def lines
    		              arraydef[1] = new defvariable("AA", "BB", "CC");
    		              String line;    // String that holds current file line
    		              int count = 0;  // Line number of count 
    		              
    		              line = bufRead.readLine();
    		              
    		              // Read through file one line at time. Print line # and line
    		              while (line != null){
    		                  
    		            	  // split line and load components into array
    		            	  String[] temp;
    		            	  temp = line.split("\\|");
    		            	  
    		            	  // if length = 4 then a valid def definition
    		            	  if ( temp.length == 4 ) {
    		            		  System.out.println(count);     // zero
    		            		  System.out.println(temp[1]);   // 1234
    		            		  System.out.println(temp[2]);   // database1
    		            		  System.out.println(temp[3]);   // datacol1
    		            		  
    		            		  System.out.println(arraydef[0].getDatabase());
    		            		 
    			            	  count++;
    		            	  
    		            	  }
    			                  line = bufRead.readLine();
    	            	  }
    		              
    		              bufRead.close();
    		  
    		          }catch (IOException e){
    		              // If another exception is generated, print a stack trace
    		              e.printStackTrace();
    		          }
    		      
    	           try {
    	        	   FileWriter outFile = new FileWriter("javawritefile");
    	        	   // FileWriter outFile = new FileWriter(args[0]);
    		           PrintWriter out = new PrintWriter(outFile);
    	              
    	              // Also could be written as follows on one line
    	              // Printwriter out = new PrintWriter(new FileWriter(args[0]));
    	          
    	              // Write text to file
    	              out.println("This is line 1");
    	              out.println("This is line 2");
    	              out.print("This is line3 part 1, ");
    	              out.println("this is line 3 part 2");
    	              out.close();
    	          } catch (IOException e){
    	              e.printStackTrace();
    	     }
    	
    	} 
    
    	class defvariable {
    		
    		
    		String substitution;
    		String database;
    		String datacolumn;
    		
    		public defvariable(String bit1, String bit2, String bit3) {
    			this.substitution = bit1;
    			this.database = bit2;
    			this.datacolumn = bit3;
    		}
    				
    		public String getSubstitution() {
    			return substitution;
    		}
    		public void setSubstitution(String substitution) {
    			this.substitution = substitution;
    		}
    		public String getDatabase() {
    			return database;
    		}
    		public void setDatabase(String database) {
    			this.database = database;
    		}
    		public String getDatacolumn() {
    			return datacolumn;
    		}
    		public void setDatacolumn(String datacolumn) {
    			this.datacolumn = datacolumn;
    		}
    	 }
    
    }
    Last edited by nigelhoath; April 12th, 2012 at 03:16 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured