New instances of main class

Hi People.
I'm currently programming a toolbox of applications in Java - each tool is a main program in its own right (i.e. has main method). I'm also programming an organiser which has buttons, which will (eventually) run the main programs i have already mentioned 'on demand'. I've tried using ClassLoader etc. but keep getting errors (see below). Does anyone have a better solution, please? Links to helpful sites will be much appreciated!
By the way, i'm fairly new to Java so be gentle! :)
Cheers, folks.
ERRORS I GET WHEN USING CLASSLOADER (and i'm 100% sure i've got the file name and directory correct):
java.io.FileNotFoundException: (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:64)
at java.io.FileReader.<init>(FileReader.java:38)
at TestClass.main(TestClass.java:9)

Ok now I think you have a fundamental flaw in your design, and also your understanding of object oriented programming.
Here's what I think you want to achieve:
-A series of components which can be accessed in two ways - either independently through running "java classname" on them, and also through a container which lets you access them via buttons.
This is not a hard problem, and here is my (simplified) solution in code:
File: Component1.java
public class Component1 extends JFrame{
//do some stuff in here specific to this component
public static void main(String[] args){
  Component1 comp1 = new Component1();
  comp1.show();
}========================================
File: Component2.java
public class Component2 extends JFrame{
//do some stuff in here specific to this component
public static void main(String[] args){
  Component2 comp2 = new Component2();
  comp2.show();
}========================================
File: Container.java
public class Container extends JFrame{
public Container(){
  //get a reference to the components
  Component1 comp1 = new Component1();
  Component2 comp2 = new Component2();
//Button click listener code
public void onClick(Component comp){
  comp.show();
//do some stuff in here specific to this component
public static void main(String[] args){
  Container cont = new Container();
  cont.show();
}Ok so I simplified it a lot and missed out all the button listener stuff (plus the design would be a lot nicer using interafces for the components...but one step at a time!) but it should show you how main methods interact with classes in java.
Please reply if you still dont understand, or this is wrong!

Similar Messages

  • Why create a new instance of Main?

    I see many code samples posted that create a new instance of Main, but none of them seem to use it. But yet the Netbeans IDE won't seem to run without it. What is it for? How can it be utilized? How can it be nullified if it's not needed?

    Yes, that's a fair interpretation of my question. Why
    would Netbeans, or other IDE's, create a new instance
    of Main? Common logic says that there can only be one
    Main. More than one creates confusion.There can only be one main(String[] args) per class, but there's nothing which says that there can't be one main method in each class. I usually uses main methods to show example code, or to have some code which performs some kind of tests.
    Kaj

  • Create a new instance of a class without starting new windows.

    I've a class with basic SWING functions that displays an interface. Within this class is a method which updates the status bar on the interface. I want to be able to reference this method from other classes in order to update the status bar. However, in order to do this, I seem to have to create a new instance of the class which contains the SWING code, and therefore it creates a new window.
    Can somebody give me an example, showing how I might update a component on the interface without a new window being created.
    Many thanks in advance for any help offererd.

    I've a class with basic SWING functions that displays
    an interface. Within this class is a method which
    updates the status bar on the interface. I want to be
    able to reference this method from other classes in
    order to update the status bar. However, in order to
    do this, I seem to have to create a new instance of
    the class which contains the SWING code, and
    therefore it creates a new window.
    Can somebody give me an example, showing how I might
    update a component on the interface without a new
    window being created.
    Many thanks in advance for any help offererd.It sounds like you have a class that extends JFrame or such like and your code must be going
               Blah  test = new Blah();
                test.showStatus("text");Whereas all you need is a reference to that Classs.
    So in your class with basic SWING functions that displays an interface.
    You Might have something like this
              // The Label for displaying Status messages on
              JLabel statusLabel = new JLabel();
              this.add( statusLabel , BorderLayout.SOUTH );What you want to do is provide other Classes a 'method' for changing your Status Label, so in that class you might do something like:
          Allow Setting of Text in A JLabel From various Threads.
         And of course other classes......
         The JLabel statusLabel is a member of this class.
         ie defined in this class.
        @param inText    the new Text to display
       public void setStatusText( String inText )
                    final String x = inText;
                    SwingUtilities.invokeLater( new Runnable()
                              public void run()
                                       statusLabel.setText( x );
      }You still need a reference to your first class in your second class though.
    So you might have something like this:
            private firstClass firstClassReference;        // Store Reference
            public secondClass(  firstClass  oneWindow )
                          // create whatever.........
                         this.firstClassReference = oneWindow;
    // blah blah.
          private someMethod()
                            firstClassReference.setStatusText( "Hello from Second Class");
        }Hope that gives you some ideas

  • Unable to make a new instance of a class?

    Why can't I make a new instance of this object?
    This doesn't work:
            static void generateConfirmationDialog(String s1, String s2,
                String s3)
                int optionConfirmation = JOptionPane.showConfirmDialog(null,
                    "Confirm inputs: \n" +
                    "\n1: " + s1 +
                    "\n2: " + s2 +
                    "\n3: " + s3,
                    "Input Confirmation",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
                if (optionConfirmation == JOptionPane.YES_OPTION)
                    //A new instance of an object.
                    //Class UserInterface
                    //Inner Class FileChooser
                    UserInterface.FileChooser fc = new
                        UserInterface.FileChooser.FileChooser();
                else if (optionConfirmation == JOptionPane.NO_OPTION)
                    //Returns the user to the main menu, with inputs intact.
            }Here's that class:
        public class FileChooser extends JFrame
            FileChooser()
                JFileChooser filechooser = new JFileChooser();
                int returnValue = filechooser.showDialog(this, "Upload");
                //Not done yet, but it should be able to display it
        }But this works:
        public static void main(String args[])
            UserInterface menu = new UserInterface();
        }

    1. Does class FileChooser need direct access to any nonstatic member variables or methods in the enclosing class (by your claim UserInterface)?
    If not, then just make the nested class static by:public static class FileChooser extends JFrame
        // body
    }note the static qualifier in the class definition. People frequently make inner classes where static nested classes would do equally as well or even better. Only if the nested class is "attached" to the instance is it necessary to make it non-static.
    2. If so, does the generateConfirmationDialog() have to be static?
    If not, simply remove the static qualifier from the method.
    3. If so, you will have to pass the instance created in your main() method to the method and use it to instantiate the inner class. The syntax isUserInterface menu = new UserInterface();
    FileChooser fc = menu.new FileChooser();4. Is there some reason you can't just use a filechooser from Swing?

  • Creating a new instance of a class within a superclass

    I have a class with 2 subclasses and in the top classs I have a method that needs to create a new instance of whihc ever class called it.
    Example:
    class Parent
         void method()
              addToQueue( new whatever type of event is calling this function )
    class Child1 extends Parent
    class Child2 extends Parent
    }What I mean is , if Child1 calls the method then a new Child1 gets added to the queue but if Child 2 calls method a new Child 2 gets added to the queue. Is this possible?
    Thanks.

    try
    void method()
    addToQueue(this.getClass().newInstance());
    }Is this what you want ?Won't that always add an object of type Parent?
    no if we invoke this method on the child object...
    we currently dun know how op going to implement the addToQueue()
    so... just making my guess this method will always add to same queue shared among
    Parent and it's childs......

  • Class not registered Exception while initializing a new instance of SpeechRecognizer Class

    Hi,
    in my Windows 8.1 Store App with HTML/Javascript I want to use Bing Speech Recognition Control.
    But when I call the contructor of Bing.Speech.Recognizer Class with the language and the authorization Parameters a WinRT "Class not registered" error occurs.
    What could be the reason for this problem?
    I am using Visual Studio 2013.4 by the way.
    Thanks in advance.

    You need to follow all the steps here:
    https://visualstudiogallery.msdn.microsoft.com/521cf616-a9a8-4d99-b5d9-92b539d9df82
    Jeff Sanders (MSFT)
    @jsandersrocks - Windows Store Developer Solutions
    @WSDevSol
    Getting Started With Windows Azure Mobile Services development?
    Click here
    Getting Started With Windows Phone or Store app development?
    Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

  • Can't create new instance of class in servlet.

    I'm running Tomcat 5.5 and am trying to create a new instance of a class in a servlet. The class is an Apache Axis (1.4) proxy for a Web Service.
    Is there any particular reason this is happening, and any way to fix it?
    The stack trace is as follows:
    WARNING: Method execution failed:
    java.lang.ExceptionInInitializerError
         at org.apache.axis.utils.Messages.<clinit>(Messages.java:36)
         at org.apache.axis.configuration.EngineConfigurationFactoryFinder.newFactory(EngineConfigurationFactoryFinder.java:184)
         at org.apache.axis.configuration.EngineConfigurationFactoryFinder.access$200(EngineConfigurationFactoryFinder.java:46)
         at org.apache.axis.configuration.EngineConfigurationFactoryFinder$1.run(EngineConfigurationFactoryFinder.java:128)
         at java.security.AccessController.doPrivileged(Native Method)
         at org.apache.axis.configuration.EngineConfigurationFactoryFinder.newFactory(EngineConfigurationFactoryFinder.java:113)
         at org.apache.axis.configuration.EngineConfigurationFactoryFinder.newFactory(EngineConfigurationFactoryFinder.java:160)
         at org.apache.axis.client.Service.getEngineConfiguration(Service.java:813)
         at org.apache.axis.client.Service.getAxisClient(Service.java:104)
         at org.apache.axis.client.Service.<init>(Service.java:113)
         at server.proxies.webservicex.net.stockquote.StockQuoteLocator.<init>(StockQuoteLocator.java:12)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)

    Of course there's a particular reason it's happening. Nothing in a computer happens unless it's for a particular reason. You question ought to be what is that reason.
    Well, I don't know what it is. The class org.apache.axis.utils.Messages threw some kind of exception when it was being loaded, because <clinit> means "class initialization" in a stack trace. That would most likely be in a static initializer block in that class. I expect it is because of some mis-configuration in your system, but you'd have to read and understand the apache code to find out what. Or maybe ask over at the Axis site, where there might be a forum or a mailing list.

  • Execute jar file: "could not find the main class" program will terminate

    Hey,
    I am new to Java. I have started to make a small java program which supposed to help me at my studies to lean the Dominic Memory System. I have used the latest version of Netbeans 5.5.1 to build my program in. I have two problems which I cannot figure out how to solve, please help me.
    The first problem is that the java script I have made works when I compile it in Netbeans, but when I create a Jar file it does not work. I receive a pop up message in windows ?could not find the main class program will terminate? when I execute the jar file.
    The second problem I have is that I need to compare the strings generated by the "numbers" and "TIP" and if the numbers is not identical the numbers in the ?Center? JPanel should be highlighted as red.
    If anyone would like to clean up the code I would be pleased. I have copied quite a lot from anyone because of my one lack of knowledge.
    * GoListener.java
    * Created on 12. september 2007, 21:48
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package grandmaster;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Vector;
    import java.util.StringTokenizer;
    import java.awt.Color;
    * @author Computer
    public class GoListener implements ActionListener {
    private JTextField viewer;
    private JTextField TIP;
    private JTextField freq;
    private JTextField max_num;
    private Vector numbers;
    public GoListener(JTextField j,JTextField k, JTextField m, JTextField f, Vector n) {
    freq = f;
    max_num = m;
    viewer = j;
    numbers = n;
    TIP = k;
    public void actionPerformed(ActionEvent e){
    int time = Integer.valueOf(max_num.getText());
    int f = Integer.valueOf(freq.getText());
    if (e.getActionCommand() == "GO") {
    for (int i = 0; i< time;++i) {
    int number=0;
    number = (int)Math.floor(100*Math.random());
    while(number>51){
    number = (int)Math.floor(100*Math.random());
    if(number<=9){
    viewer.setText(" "+"0" + String.valueOf(number) + " ");
    } else{
    viewer.setText(" " + String.valueOf(number) + " ");
    viewer.paintImmediately(viewer.getBounds());
    numbers.add(number);
    try {
    Thread.sleep(f*1000);
    } catch (Exception exp) {
    viewer.setText(" XX ");
    viewer.paintImmediately(viewer.getBounds());
    if (e.getActionCommand() == "VIEW") {
    try {
    //int numb = Integer.valueOf( TIP.getText() ).intValue();
    StringTokenizer tokenizer = new StringTokenizer(TIP.getText(), " ");
    String[] split = null;
    int tokenCount = tokenizer.countTokens();
    if (tokenCount > 0) {
    split = new String[tokenCount];
    for (int current = 0; current < tokenCount; current++) {
    split[current] = tokenizer.nextToken();
    viewer.setText(" " + String.valueOf(numbers) + " ");
    // k=numbers(1);
    /*while(c<i){
    String.valueOf(k).equals(split[1]);
    c++;
    TIP.setText(" " + split[2] + " ");
    } catch (Exception exp) {
    try {
    //string testit = numb.toString();
    //String str = "" + numb;
    //viewer.setText(str);
    //viewer.setText(numbers.toString());
    numbers.clear();
    } catch (Exception exp) {
    * Main.java
    * Created on 12. september 2007, 21:07
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package grandmaster;
    import java.util.Vector;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.JButton;
    import java.awt.*;
    import grandmaster.GoListener;
    * @author Computer
    public class Main extends JFrame {
    private JTextField viewer;
    public JTextField TIP;
    // private TextInputPanel TIP;
    private Vector numbers;
    /** Creates a new instance of Main */
    public Main() {
    numbers = new Vector();
    JPanel p = new JPanel(new GridLayout(0,4));
    JButton go = new JButton();
    JButton view_num = new JButton();
    go.setText("Go!");
    go.setVisible(true);
    go.setActionCommand("GO");
    view_num.setText("VIEW");
    view_num.setVisible(true);
    view_num.setActionCommand("VIEW");
    JTextField max_num = new JTextField();
    max_num.setText("5");
    JTextField freq = new JTextField();
    freq.setText("1");
    viewer = new JTextField();
    viewer.setText("XX");
    TIP = new JTextField("");
    p.add(go);
    p.add(max_num);
    p.add(freq);
    p.add(view_num);
    getContentPane().add(p,BorderLayout.NORTH);
    getContentPane().add(viewer,BorderLayout.CENTER);
    getContentPane().add(TIP,BorderLayout.SOUTH);
    setSize(200,200);
    GoListener g = new GoListener(viewer,TIP,max_num, freq, numbers);
    go.addActionListener(g);
    view_num.addActionListener(g);
    * @param args the command line arguments
    public static void main(String[] args) {
    // TODO code application logic here
    Main window = new Main();
    window.setVisible(true);
    }

    NetBeans questions should be posted to the NB site. It has mailing lists and associated forums.
    This tutorial from the NB site addresses running programs outside of NB
    http://www.netbeans.org/kb/articles/javase-deploy.html
    When you compare objects, use ".equals()" and reserve == for comparing values.

  • Create multiple instances of same class but with unique names

    Hi,
    I'm creating an IM application in Java.
    So far I can click on a user and create a chat session, using my chatWindow class. But this means I can only create one chatWindow class, called 'chat'. How can I get the application to dynamically make new instances of this class with unique names, for examples chatWindowUser1, chatWindowUser2.
    Below is some code utlising the Openfire Smack API but hopefully the principle is the clear.
        private void chatButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
            int selectedUserIndex = rosterList.getSelectedIndex();
            String selectedUser = rostAry[selectedUserIndex].getUser();
            System.out.println("Chat with: " + selectedUser);
            if (chatBox == null) {
                JFrame mainFrame = CommsTestApp.getApplication().getMainFrame();
                chatBox = new CommsTestChatBox(mainFrame,conn,selectedUser);
                chatBox.setLocationRelativeTo(mainFrame);
            CommsTestApp.getApplication().show(chatBox);
    }  

    yes, an array would work fine, just realize that by using an array, you're setting an upper bound on the number of windows you can have open.
    As for unique names, if you mean unique variable name, you don't need one. The array index serves to uniquely identify each instance. If you mean unique title for the window, set that however you want (username, index in array, randomly generated string, etc.). It's just a property of the window object.

  • Creating new instances

    Hi all, quick query,
    I need to get a parameter passed to a method to reference a new instance of another class... how can i do this?
    Thanks

    I'd probably go about it like this.
    Two class
    Student class: represents a student
    Students class: the collection of students.
    Students class
    -can add new students
    -can remove students
    -etc,
    for the student class it gets a bit tricky
    private TreeSet<Student> treeSetStudents;
    private String name;
    //Contstructor
    private Students(String name, TreeSet<Student> students){
      treeSetStudents = students;
      this.name = name;
    //other methods removed for brevity
    public static void addStudent(String name, TreeSet<Students> set){
      Student mStu = new Student(name, set);
      set.add(mStu);
    }so you'd start by instantiating your collection then passing it to addStudent along with the students name when you call Students static method addStudent.

  • Creating new instances of MDBs at runtime

    I am creating an application with a single input point (messages on a JMS Queue). The application needs to be multi-threaded, but would like to process the messages sequentially based on the message type.
    For example, a message of type A and a message type B can be processed simultaneously, but only 1 message of type A can be processed at a time. So if the application is processing a message of type A, and it receives another type A message, it must complete the first message before processing the second message.
    What I would like to do is have a single MDB (called the dispatcher MDB) that listens on the input point (JMS Queue). The dispatcher MDB calls onMessage() which will look at the message type and the forward to another JMS Queue based on the type. For example, if message type is A, send to Queue A, else if message type B, send to Queue B and so on. Each queue would have a MDB instance servicing the messages. In order to process the messages sequentially on each queue, the pool size for each MDB would be 1.
    My problem is that I don't know how many message types there are, this is decided at runtime.
    How can I create the Queues and register MDB at runtime?
    After some research, I have found the ability to create the Queues using JMX. But, I cannot seem to find details on how to create a register an MDB and tell it to listen on a particular Queue. Has anyone had any experience doing such a thing?

    OK, i have some code similar to below, where I want to
    create a new instance of the class BookRecord which
    takes parameters from Book b, which is an instance if
    the class Book.
    //This is code from the Libraray class
    public void addBookRecord(Book  b, String author,
    String title)
    bookHolder  = new BookRecord(b, author, title);
    }Now this creates a new BookRecord object that has an
    author and title which refer to the Book b. Now when i
    invoke the method again, choosing the same object for
    b as i did last time it creates a second BookRecord
    object, when I just want it to overwrite the values of
    the previous BookRecord object. how can i do this
    simply?
    Thanks in advanceWell I am not quite sure if I understood.
    But refering to what you wrote I would say:
    //This is code from the Libraray class
    public void addBookRecord(Book  b, String author, String title)
            if(bookHolder.getBook() != b)
               // Not the same book object
               bookHolder  = new BookRecord(b, author, title);
             else
                // same book object
                bookHolder.setAuthor(author);
                book.setTitle(tile);
    As I said may be totally not what you are looking for.
    Regards
    Tarik

  • Getting new Instance

    Hi,
    This is the same problem which I had already posted.
    But I cant find a solution yet.
    Iam reiterating the problem in a much clear way now
    The problem i face is my jsp(user interface page) calls a servlet Class(Quetion) which has a seperate method named questionHandle(), Up to this there is no problem.
    The problem is when I try to open a fresh (new Internet Explorer) the instance of Question which is already
    created is shared with this explorer also,I dont want this to happen.
    I want a new Instance of the class (Question ) to be created each time I open the new jsp page

    Iam developing a online test application.
    It just returns some questions randomnly picked from the database
    This is the skeleton of Question Servlet class
    package myquiz;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.StringTokenizer;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class Question extends HttpServlet {
         public void init()
         public void doGet(HttpServletRequest request, HttpServletResponse response)
                   throws ServletException, IOException
              PrintWriter out=response.getWriter();
                   out = response.getWriter();
                   response.setContentType("text/html");
                   out = response.getWriter();
                   out.println("Online Test");
         public String[] questionHandler()
    This is the skeleton of my JSP(quizjsp.jsp)
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <body>
    <form NAME="testform" METHOD="POST" onSubmit="return(checkSelection(testform))" action="/quizagain/quizjsp.jsp">
    <%@page import = "myquiz.*" %>
    <%@page import = "java.util.*" %>
    <%!
         Question q = new Question();      
    %>
    <%
    if(first)
    <%
         if(no_of_ques>0)
         ans=str_que_ans[3];
         if(ans.equals(request.getParameter("r1")))
    //     System.out.println(no_of_ques);
    //     correct_ans[ind++]=no_of_ques;
         marks=marks+1;
         // out.println(marks);
    %>
    <%
         else if(i==0 || i>4)
              s=q.questionHandler("operator",comp_level_from,++comp_level_from);
              comp_level_from++;
         if(start)
              showQuestion();
              no_of_ques++;
    %>
    <%!
         public void showQuestion()
    // System.out.println("in Show question");
    j=0;
    StringTokenizer st=new StringTokenizer(s[i++],"$");
    while(st.hasMoreTokens())
         str_que_ans[j++]=st.nextToken();
         if(i >4)
         i=0;
    %>
    <center><h2>Question No. <%=no_of_ques%></h2>
    </center><br><br><br><br><br><br>
    <h2><%=str_que_ans[0]%></h2>
    <center>
    <table align="left" width=10>
    <tr><td><input type=radio name=r1 value="1"></td><td><b><%=str_que_ans[1]%></td></tr>
    <tr><td><input type=radio name=r1 value="2"></td><td><b><%=str_que_ans[2]%></td></tr>
    <tr><td><center><input type=submit value="Next"></input></center></td></tr>
    </table>
    </center>
    </form>
    </body>
    </html>
    I use to invoke my application from myjsp.jsp

  • Reassign class variable to a blank instance of its class

    When I declare a class variable
    private var myVar:MyClass = new MyClass();
    It creates a new instance of that class that will trace as [Object MyClass].
    However, as soon as I assign it to something
    myVar = thisOtherVar;
    It will now trace as [Object thisOtherVar].
    I need to get it back to where it's just an "empty" blank class instance, if that makes any sense at all.
    How do I go about doing that? Thanks!

    I'm brand new to OOP - I've been watching iTunes U videos and reading books but it's still all pretty abstract in my mind and it's difficult for me to pin point how all that stuff translates to actually writing good code.
    Basically, it's an open ended kid's dictionary. You drag the lettes to drop boxes, touch the check to see if it's a word, and then a picture representing the word pops up on the screen.
    All of it works except if you try to remove a letter that's already been placed. Originally, I wanted the check button to do a sweep of the dropped letters and see if they had formed a word - but I couldn't figure out a way to do that. So then I started tracking movements of letters in real time, and that's when it got really confusing. I think I just need to start over and try to make the code a bit cleaner. Right now this is what I've got:
    if (currentUsedBlank is BlankSquare) {  //if they have removed a letter that has already been dropped
                    if (currentUsedBlank != currentBlank) { //and it's been placed back on a different square
                        currentUsedBlank.letter = null;
                else {
                    currentUsedBlank.letter = null;
                if (this.dropTarget.parent is BlankSquare && currentBlank.letter == null) {
                    SpellingGlobals.lettersInBlanks[SpellingGlobals.lettersInBlanks.length] = this;
                    this.x = this.dropTarget.parent.x + 10;
                    this.y = this.dropTarget.parent.y - 10;
                    var myClass:Class = getDefinitionByName(getQualifiedClassName(MovieClip(this))) as Class;
                    var newLetter:MovieClip = new myClass();
                    newLetter.x = currentLetter.startPoint.x;   
                    newLetter.y = currentLetter.startPoint.y;
                    newLetter.letter = currentLetter.letter;
                    newLetter.reference = currentLetter.reference;
                    newLetter.startPoint.x = currentLetter.startPoint.x;
                    newLetter.startPoint.y = currentLetter.startPoint.y;
                    newLetter.isVowel = currentLetter.isVowel;
                    currentBlank.letter = currentLetter.letter;
                    if (SpellingGlobals.isCaps == true) {
                        newLetter.txt.text.toUpperCase();
                        if (SpellingGlobals.isColor == true) {
                            if (newLetter.isVowel) {
                                newLetter.txt.textColor = SpellingGlobals.colorVowel;
                            else {
                                newLetter.txt.textColor = SpellingGlobals.colorCon;
                    MovieClip(root).addChild(newLetter);
                    SpellingGlobals.copiedLetters[SpellingGlobals.copiedLetters.length] = newLetter;
                    currentBlank.alpha = 0;
                else {
                    this.x = MovieClip(this).startPoint.x;
                    this.y = MovieClip(this).startPoint.y;
                this.stopDrag();

  • Creating a new instance of a member class?

    I'm writting a serialization library for a college project and I have a problem with deserializing an object which class contains a member class. A rough example:
    class Outer{
         class Member{
              double d =0;
         public Member member =new Member();     
    }Most basically I tried to get a new instance of the Member class in order to get the double field, change it's value, then use that new instance as a field of an object of the Outer class.
    Field f = Outer.class.getDeclaredField("member");
    f.setAccessible(true);
    f.getClass().newInstance(); Both this and the Constructor method throw an exception:
    Exception in thread "main" java.lang.InstantiationException: java.lang.reflect.Fieldpointing at the line with newInstance().
    Is there anything I can do to create an object of a member class? And if not then taking into account that I have to deserialize the Outer object from an XML file what could be the alternative?

    The error message already gives you a hint that it's not class Outer.Member you're instantiating there (review the API docs)...
    import java.lang.reflect.*;
    public class Outer{
      public static void main(final String[] args) {
        final Field f = Outer.class.getDeclaredField("member");
        f.setAccessible(true);
        final Constructor ctor =
                f.getType().getDeclaredConstructor(new Class[] { Outer.class });
        final Object outer = new Outer();
        final Object member = ctor.newInstance(new Object[] { outer });
        // set member.d
        f.set(outer, member);
      class Member{
        double d =0;
      public Member member =new Member();     
    }

  • Instance of a Main Class

    Hi guys,
    I need to create an instance of the main class in my project.
    This main has the standard main method : public static void main (String args[])
    ,which requires a character by command line.
    How to create an instance of this class from another class in the same project passing the required parameter ??
    Note : I'm using this to test the class , with Eclipse and Junit
    Thanks a lot

    Same way you create any other class. Except "main" is a static method, so you don't need to create the class. Just call the following:
    Main.main(new String[] {"FirstArg", "SecondArg", "ThirdArg"});Where Main is the class with your "main" method. You can build up the String array separately, and then pass it as the argument to "main" (as you would for any other method that takes a String array).

Maybe you are looking for

  • Looking for a good media reader

    I am looking at either the SIIG 11 in 1 media reader for my express card slot or the Cables unlimited brand, My question is, the SIIG had issues in 10.4 with not allowing the MBP to sleep when installed and also XD cards would not mount does anyone k

  • Memory usage Difference

    When I was trying to check the difference in the VI memory usage when the controls are places as Icons and Terminals. Surprisingly when I was using the controls as Icons the memory usage (shown in vi properties) is less than the controls when they ar

  • Group Mailer error

    Hi I am trying to set up a workflow to simply send the same email newsletter to a group in the address book. The workflow looks like this: New mail message Find groups in Address Book Group Mailer Send outgoing messages Everything works until the Gro

  • How do I fix a "medium write error" when I try to burn a MP3 CD?

    how do I fix a "medium write error" when I try to burn a MP3 CD? Thanks, Jackie

  • Edit in lower bitrate and export in higher bitrate

    Is there a way i can edit HD movie in a lower bitrate for better workflow, and then when im finished edititing the movie, i can export the movie out in original HD bitrate.