Solved

Unable to Create Class Instance, Build Issues with some IDEs

Posted on 2014-11-04
4
158 Views
Last Modified: 2014-11-05
I  have a selection screen for selecting project folders that the user wants to select in a JList control.

These folders are sub-folders to a path name that gets loaded from an INI (text) file, that has one item
in it describing a path which is not marked by REM in the file, which is where the JList brings up the
list of available folders for user selection.

When the button on the selection form is clicked, if there is a folder name selected in JList then the selection
JFrame will be set to invisible and an instance of another JFrame is created with 2 items from the selection
passed down through the constructor: The selection String from the JList, and the ArrayList<String> of all
possible selections.

For now, just to indicate that all info is correctly passed down to new class instance I make it show up with calling the super() method feeding it the selection String and the size of the ArrayList<String> to show , with this simplified example.

This all works fine using JDeveloper IDE, see screen shots below:

Select_Project2 selection screen running in JDeveloper IDE:

JFrame for selection running (Main) in JDeveloper IDE
The SecondScreen  class instance, that's created from the selection screen,
JDeveloper IDE:

Second Class instance running JDeveloper IDE
Now If I try to run in from another IDE, (JCreator) same version of JAVA, I get a build error, it cannot create
the class instance, the build error when compiling source:

--------------------Configuration: Select_Project2 - JDK version 1.7.0_55 <Default> - <Default>--------------------
C:\Users\Attila\Documents\JCreator Pro\MyProjects\Select_Project2\src\Select_Project2.java:28: error: cannot find symbol
        SecondScreen casconMainScreen;
        ^
  symbol:   class SecondScreen
  location: class Select_Project2
C:\Users\Attila\Documents\JCreator Pro\MyProjects\Select_Project2\src\Select_Project2.java:162: error: cannot find symbol
                    casconMainScreen = new SecondScreen( selectionLine, listOfAllProjectsInFolder);    // line crashing
                                           ^
  symbol:   class SecondScreen
  location: class Select_Project2
Note: C:\Users\Attila\Documents\JCreator Pro\MyProjects\Select_Project2\src\Select_Project2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

Process completed.

Open in new window


I need to have it compiling and running in JCreator IDE, because I will need to extract the clean class files this IDE creates to feed it another program.

Here is the code for the selection screen:

import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class Select_Project2 extends JFrame {
	
	// Variables declaration 
	private JLabel jlblSelectTest;
	private JScrollPane scrollPane1;
        private DefaultListModel model; 
	private JList jlstProjectList;
	private JButton jbtnOpenProject;
	// End of variables declaration 
        
        private String selectionLine = "";
        private ArrayList<String> listOfAllProjectsInFolder = new ArrayList<String>();
        
        SecondScreen casconMainScreen;
        
       
	public Select_Project2() {
	   super("BST Program ITC version 1.1 - Select Project" ); 
	        initComponents();
	    try {
	        // Set the look and feel for the current OS (Windows) Scheme
	        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	                initComponents();
            } catch (Exception e) {
                e.printStackTrace();
	                    }
            this.setSize(388,380);
	    this.setResizable(false);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setVisible(true);
	}

	private void initComponents() {
		// Component initialization 
		jlblSelectTest = new JLabel();
		scrollPane1 = new JScrollPane();
                model = new DefaultListModel();
                jlstProjectList = new JList(model);
                
		jbtnOpenProject = new JButton();

		//======== this ========
		Container contentPane = getContentPane();
		contentPane.setLayout(null);

		//---- jlblSelectTest ----
		jlblSelectTest.setText("Select Test Project to Open:");
		jlblSelectTest.setFont(new Font("Tahoma", Font.BOLD, 14));
		jlblSelectTest.setHorizontalAlignment(SwingConstants.CENTER);
		contentPane.add(jlblSelectTest);
		jlblSelectTest.setBounds(50, 10, 260, 25);

		//======== scrollPane1 ========
		{
			scrollPane1.setViewportView(jlstProjectList);
		}
		contentPane.add(scrollPane1);
		scrollPane1.setBounds(20, 45, 340, 245);

		//---- jbtnOpenProject ----
		jbtnOpenProject.setText("Open Project");
		jbtnOpenProject.setFont(new Font("Tahoma", Font.BOLD, 12));
		jbtnOpenProject.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				jbtnOpenProject_ActionPerformed(e);
			}
		});
		contentPane.add(jbtnOpenProject);
		jbtnOpenProject.setBounds(125, 305, 120, jbtnOpenProject.getPreferredSize().height);

		{ // compute preferred size
			Dimension preferredSize = new Dimension();
			for(int i = 0; i < contentPane.getComponentCount(); i++) {
				Rectangle bounds = contentPane.getComponent(i).getBounds();
				preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
				preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
			}
			Insets insets = contentPane.getInsets();
			preferredSize.width += insets.right;
			preferredSize.height += insets.bottom;
			contentPane.setMinimumSize(preferredSize);
			contentPane.setPreferredSize(preferredSize);
		}
		pack();
		setLocationRelativeTo(getOwner());
            
	    // Add a list selection listener anonymous instance to JList control:
            // (implementing valueChanged() method)
	                     ListSelectionListener lListener = new ListSelectionListener() {
	                         public void valueChanged(ListSelectionEvent e) {
	                             if (e.getValueIsAdjusting() == false) // it will prevent double firing when  valueChanged() is called
	                             {
	                                 JList list = (JList) e.getSource();
	                                 if (!(list.isSelectionEmpty())) {
	                                     selectionLine = (String) list.getSelectedValue();

	                                     System.out.println("Selected: " + selectionLine);
	                                     
	                                 }
	                             }
	                         }
	                     };

	                     jlstProjectList.addListSelectionListener(lListener);
                
                
            String dirName = readINIFileToLoadProjectsDirectory();
             
             if (!(dirName.equals("")))
                    listFoldersInFolder(dirName);
             
		// End of component initialization  
	}
        

    public static void main(String[] args) {
          
                  // The static utility method invokeLater(Runnable) is intended to execute a new runnable
                  // thread from a Swing application without disturbing the normal sequence of event dispatching
                  // from the GUI.
          
       SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                 try {
                                     // Set the look and feel for the current OS (Windows) Scheme and
                                     // all subsequent jFrames will also have the same look and feel
                                     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                                     Select_Project2 selectProject = new Select_Project2();
                                     selectProject.setLocationRelativeTo(null);
                                     
                                 } catch (Exception e) {
                                     e.printStackTrace();
                                 }
                            }
                        });
                  }  
      

    private void jbtnOpenProject_ActionPerformed(ActionEvent e) {
            System.out.println("Open project Button Clicked");
            if (selectionLine.equals("")){
                    JOptionPane.showMessageDialog(null, "       Select project to load ", "No Selection Made", JOptionPane.WARNING_MESSAGE);
                }
            else{
                    System.out.println("Open project: " + selectionLine);
                    // Creating Child Window Instances:
                    casconMainScreen = new SecondScreen( selectionLine, listOfAllProjectsInFolder);    // line crashing
                    this.setVisible(false);
                    casconMainScreen.setSize(565, 412);
                    casconMainScreen.setVisible(true);
                    casconMainScreen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                }  
    }
    
    // This will create a list of foldernames and add it
    // to the LList in the JFrame:
    public void listFoldersInFolder(String pathName)
       {
           model.clear();
           File [] paths;
           File file=new File(pathName);
           if(file.isDirectory()){
             paths = file.listFiles();  
                for (int i=0; i<paths.length; i++)
                {
                    if (paths[i].isDirectory()){
                    System.out.println(paths[i].getPath());
                    listOfAllProjectsInFolder.add(paths[i].getPath());
                    
                    model.addElement(paths[i].getName());
                    }
                }
           }
       }
    
    
    
    // This method will load the first uncommented line from
    // 'StartUp.ini' and return it as the project directory
    private String readINIFileToLoadProjectsDirectory(){
        String directoryName = "";
            try {
                    // Open the file
                    FileInputStream fstream =new FileInputStream("StartUp.ini");
                
                    // Get the object of DataInputStream
                    DataInputStream in = new DataInputStream(fstream);
                    BufferedReader br = new BufferedReader(new InputStreamReader(in));
                    String strLine;
                                      
                        //Read File Line By Line
                        while ((strLine = br.readLine()) != null) {
                                
                            if(!(strLine.startsWith("REM"))) {
                                if(!(strLine.trim().equals(""))){
                                    directoryName = strLine.trim();
                                        break;
                                             }
                                      }
                        } 
                    //Close the input stream
                    in.close();                   
                }
                    catch (Exception e) {
                    System.err.println("Error: " + e.getMessage());
                    e.printStackTrace();
        }
        return directoryName;
    }
    
}

Open in new window


And for the second screen:

import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;

public class SecondScreen extends JFrame {
    
      
	public SecondScreen(String testNameSelected, ArrayList<String> listOProjectsInFolder) {
            
            super("Test name selected:  " + testNameSelected + "   List Size: " + listOProjectsInFolder.size());
            
	   
            
	}  //     ------------------       End of constructor here 
        
        
	private void initComponents() {
            
		//======== this ========
		Container contentPane = getContentPane();
		contentPane.setLayout(null);
                
		
		{ // compute preferred size
			Dimension preferredSize = new Dimension();
			for(int i = 0; i < contentPane.getComponentCount(); i++) {
				Rectangle bounds = contentPane.getComponent(i).getBounds();
				preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
				preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
			}
			Insets insets = contentPane.getInsets();
			preferredSize.width += insets.right;
			preferredSize.height += insets.bottom;
			contentPane.setMinimumSize(preferredSize);
			contentPane.setPreferredSize(preferredSize);
		}
		pack();
		setLocationRelativeTo(getOwner());
		// End of component initialization  
              
	}

    
        }  // End of file

Open in new window


The contents of the StartUp.INI text file loaded from the selection screen:

REM  \\\\Main\\altium_files\\BST_Files_ForProduction\\Cascon_Galaxy_Test_Folders

REM     C:\\goepel\\CAS4WIN\\Uuts

\\\\MAIN\\Products\\Product\\Test\\BOUNDARY SCAN\\Cascon Galaxy Test Folders

Open in new window


What is happening here? How can I change this, so that I pass down the necessary data to the
other class created and it builds in any IDE?

Thanks for your help.

Attila
0
Comment
Question by:AttilaB
  • 2
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
Comment Utility
This sounds like it is a JCreator specific issue. There is nothing wrong with your code (from my initial look anyway), but it looks like JCreator doesn't have your project setup correctly and when it is compiling Select_project_2, the compiler can't see that SecondScreen is there also. Now, I haven't used JCreator so I can't help you with the specifics there. One thing that I will double check with you though, is your SecondScreen.java file in the same directory as the Select_Project2.java file?

I need to have it compiling and running in JCreator IDE, because I will need to extract the clean class files this IDE creates
Just curious about the above statement that you made... What do you believe is different about the class file JCreator makes compared to other IDEs?
0
 

Author Comment

by:AttilaB
Comment Utility
Yes, both files are in the same directory. I created the project completely from scratch, with both source
files in the same folder.

The reason I need the byte-code class files is because I would like to use the program called exe4j for creating a Windows executable out of it. I have done it a lot in the past, and worked well for me. What I found that if I use JDeveloper, or Eclipse to create the class files, because the various resources such as text, pdf files to be opened, images, icons, etc. are located in a file structure not flat in a single folder to be accessible from code.  When I extract the class files to be used I cannot have a single folder for my EXE application, because of all the scattered resources.

So to avoid that I use an IDE program JCreator that picks the resource files from a single place: the 'classes' folder
or subfolders of that one if that's what I want, and the resultant EXE file and the resource files can be placed in the same single-level folder containing the EXE file, and it works.

There must be something else out there, another IDE that uses a single-level file structure for resource files, if JCreator doesn't always work. It has always worked so far, though.

Isn't it possible that something is marginally wrong with my program?
(I don't know either what it is.)
0
 

Author Comment

by:AttilaB
Comment Utility
Well, actually I just thought that perhaps you are right, it is an IDE issue, not my code.
So I kind of remembered trying Netbeans IDE a few years ago and as I remembered that was not as complicated as the project structure of JDeveloper in general.

So, I created the class files using NetBeans 8, fed it all with icons and the INI text file to an exe4j folder, arbitrary folder and I could create a flat structure with a Windows EXE file that will run with the resources around it from
anywhere on the Windows machine.

It really makes it easy to distribute my Java program to any Windows user.

Now I just need to do the same for the full-fledged program, that I created this mini-program out of.

See screen shot:
The Windows EXE made out of the class files running from any folder
0
 
LVL 35

Expert Comment

by:mccarl
Comment Utility
Glad that you got it working with a different IDE
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now