Results 1 to 5 of 5
  1. #1
    danbwater is offline Member
    Join Date
    Oct 2013
    Location
    Arkansas
    Posts
    10
    Rep Power
    0

    Default problem with public and private

    The error is FileManager is not public in Games.utilities; can not be accessed from outside package...

    Java Code:
    java.lang.ExceptionInInitializerError
    Caused by: java.lang.RuntimeException: Uncompilable source code - Games.utilities.FileManager is not public in Games.utilities; cannot be accessed from outside package
    	at BoardGameTester.<clinit>(BoardGameTester.java:2)
    Exception in thread "main" Java Result: 1
    Here is the main

    Java Code:
    //<editor-fold defaultstate="collapsed" desc="comment">
    import Games.utilities.FileManager;
    import games.board.Board;
    import games.board.Cell;
    import games.board.Mark;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.nio.file.*; 
    import java.nio.charset.Charset;
       
       
    public class BoardGameTester { 
       
        /**
         * @param args
         */ 
        private static Board tttgameboard, mmgameboard, cfgameboard ; 
        private static Object ticTacToe;
        private static Object connectFour;
        private static Object mastermind;
        public static void main(String[] args) throws IOException { 
            // TODO Auto-generated method stub 
            // 3x3 board for TicTacToe 
            @SuppressWarnings("LocalVariableHidesMemberVariable")
            Board tttgameboard; 
            tttgameboard = new Board(3,3);
            
                // 6x7 board for Connect Four 
               Board cfgameboard;       
            cfgameboard = new Board (6,7);
            
               // 5x8 board for MasterMind; blue mark 
               Board mmgameboard = new Board (5,8);
               
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    FileManager.writeToFileAsync(ticTacToe.toString(), "ttt.txt");                
                }
            };
            Runnable runnable1 = new Runnable() {
                @Override
                public void run() {
                    FileManager.writeToFileAsync(connectFour.toString(), "c4.txt");
                }
            };
     
            Runnable runnable2 = new Runnable() {
                @Override
                public void run() {
                    FileManager.writeToFileAsync(mastermind.toString(), "mm.txt");
                }
            };
    Path file = Paths.get("activity.txt"); Charset cset = Charset.forName("UTF-16");
    if (Files.notExists(file))	{ //Check for file
    System.out.println("Enter text for new file. Hit ENTER on a blank line to end.");
    try (BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in));
    BufferedWriter Lout = Files.newBufferedWriter(file, cset);) {
    String line = "";
    while ((line = stdin.readLine()) != null && line.length() != 0 ) {
    fout.write(line);
    fout.newLine();
    }
    fout.flush();
    }System.out.println("File written.");
    } else {
    System.out.println("Reading file ....");
    try (java.io.BufferedReader fin = Files.newBufferedReader(file, cset);) {
    String line = "";
    while ((line = fin.readLine()) != null) { 
        System.out.println(line);
            }
    }}
    
    
                  
               System.out.println (" Tic Tac Toe game board "); 
                tttgameboard.setCell(Mark.NOUGHT,1,1); 
                System.out.println(tttgameboard.toString()); 
            
                System.out.println(" Connect Four game board "); 
                cfgameboard.setCell(Mark.YELLOW,0,0); 
                System.out.println(cfgameboard.toString()); 
            
                System.out.println (" Mastermind game board "); 
                mmgameboard.setCell(Mark.BLUE,0,0); 
                System.out.println(mmgameboard.toString()); 
                   
            class Board { 
                  private Cell[][] cells;
                   
                public Board(int rows, int columns) { 
                    cells = new Cell[rows][columns]; 
                    int r = 0; 
                    int c = 0; 
                    for (int r1 = 0; r1 < cells[c].length; r1++) {       // taking out [0]; replacing [0] w/ [c] 
                        for (int c1 = r; c1 < cells[r1].length; c1++) {  //taking out [1]; replacing [1] w/ [r] 
                           cells [r1][c1] = new Cell (r1,c1); 
            
                        } 
                    } 
                 } 
               
              }    
        } 
        
    
        
        public static Board getTttgameboard() { 
            return tttgameboard; 
        } 
        public static void setTttgameboard(Board tttgameboard) { 
            BoardGameTester.tttgameboard = tttgameboard; 
        } 
        public static Board getMmgameboard() { 
            return mmgameboard; 
        } 
        public static void setMmgameboard(Board mmgameboard) { 
            BoardGameTester.mmgameboard = mmgameboard; 
        } 
        public static Board getCfgameboard() { 
            return cfgameboard; 
        } 
        public static void setCfgameboard(Board cfgameboard) { 
            BoardGameTester.cfgameboard = cfgameboard; 
        }
    
        private static class length {
    
            public length() {
            }
        }
    
        private static class fout {
    
            private static void write(String line) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
    
            private static void newLine() {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
    
            private static void flush() {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
    
            public fout() {
            }
        }
    
    
    
    
        }
    Here is the Games.utilities

    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package Games.utilities;
    /**
     *
     * @author Danny
     */
    public class FileManager {
        
         public static void writeToFile(final String saveState, final String fileName) {
             //TODO: Write a string to a new file synchronously
        
        /**
         *
         * @param saveState
         * @param fileName
         */
    
            
          new Thread() {
    @Override
    public void run() {
    writeToFile(saveState, fileName); }
    }.start();
    
    }
    
        public static void writeToFileAsync(String toString, String c4txt) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
        }
    public static void writeToFileAsync(final String saveState, final String fileName) {
    //TODO: Write a string to a new file asynchronously
        
    
    
    
    
    };
    
       
            }enum

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: problem with public and private

    Uh, do you have a question?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    danbwater is offline Member
    Join Date
    Oct 2013
    Location
    Arkansas
    Posts
    10
    Rep Power
    0

    Default Re: problem with public and private

    the error states... java.lang.ExceptionInInitializerError
    Caused by: java.lang.RuntimeException: Uncompilable source code - Games.utilities.FileManager is not public in Games.utilities; cannot be accessed from outside package
    at BoardGameTester.<clinit>(BoardGameTester.java:2)
    Exception in thread "main" Java Result: 1

    Can you please explain what is actually wrong. I don't see or understand, because everything in Games.utilities.FileManager is public. Also could it be because of line 35 in Games.utilities.FileManager.

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: problem with public and private

    It is hard to say what is going on because your code lacks formatting so its hard to follow. And you have a dangling enum declaration at the end which is syntactically wrong.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    danbwater is offline Member
    Join Date
    Oct 2013
    Location
    Arkansas
    Posts
    10
    Rep Power
    0

    Default Re: problem with public and private

    Ok thank you for your time.

Similar Threads

  1. Public Arrays with Private Elements
    By jim829 in forum Advanced Java
    Replies: 4
    Last Post: 01-12-2013, 11:36 PM
  2. store the public/Private keys in Database
    By kumar11 in forum Forum Lobby
    Replies: 1
    Last Post: 07-03-2012, 02:55 PM
  3. Replies: 1
    Last Post: 02-10-2011, 04:43 AM
  4. Public, private or (nothing) class
    By tyang in forum New To Java
    Replies: 3
    Last Post: 01-31-2010, 11:37 PM
  5. How to access private data types from public classes?
    By kevzspeare in forum New To Java
    Replies: 3
    Last Post: 03-07-2009, 04:19 AM

Posting Permissions

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