Run KM from main method

Hello,
For some business reason I have to run and test KM functionality from main method.
I need some examples
1. how to connect to KM,
2. how to create IUser and how to implement createUser method.
3. how to instantiate IResource
from main method.
Any Help Will be greatly appreciated ...

Hi Costa,
Prior to using the code, give reference to the following jar files in your build path using the PORTAL_HOME variable name.
bc.rf.framework_api.jar
bc.util.public_api.jar
com.sap.security.api.ep5.jar
prtapi.jar
Right click on your project, goto Properties > Web Dynpro References > Sharing References > Add > type <b>PORTAL:sap.com/com.sap.km.application</b>
You may use the following code to get connected to a folder in KM and to create an instance of IResource.
Assumption:
The folder name being SPAP under the documents folder in KM.
try {
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
IUser sapUser = wdClientUser.getSAPUser();
com.sapportals.portal.security.usermanagement.IUser ep5User =
WPUMFactory.getUserFactory().getEP5User(sapUser);
ResourceContext context = new ResourceContext(ep5User);
RID rid = RID.getRID("/SPAP");
IResourceFactory factory = ResourceFactory.getInstance();
//get an instance of the current folder under which we have to create subfolders
ICollection folder = (ICollection) factory.getResource(rid, context);
ICollection newfolder = folder.createCollection(wdContext.currentContextElement().getQNtest(),null,null);
// To get a resource from a folder
//Assumption: template being the file under SPAP folder
RID templateRID =RID.getRID("/SPAP/template");
IResourceFactory fileFactory = ResourceFactory.getInstance();
IResource templateResource =fileFactory.getResource(templateRID, context);
//To create an instance of IResource
//Assumption: We have a byte[] <b>inBytes</b> which corresponds to the content of a PDF/any file.
ByteArrayInputStream dataStream = new ByteArrayInputStream(inBytes);
//getting content
IContent getContent =     new Content(dataStream, "text/XML", dataStream.available());               
RID rid =     RID.getRID("/SPAP");
IResourceFactory factory = ResourceFactory.getInstance();
IResource resource = factory.getResource(rid, context);
ICollection folder =     (ICollection) factory.getResource(rid, context);
//"template" is nothing but the name of the resource that we are trying to create
IResource resourceNew = folder.createResource("template", null, getContent);
} catch (Exception e) {
//  wdContext.currentContextElement().setTest(e.getMessage());
Can you tell me why you want to create a user using IUser API?
As you are deploying the code on your J2EE engine using the SDM user ID and password, it should take that authentication and access the KM folder in EP.
Hope this helps.
Regards,
Rekha Malavathu

Similar Messages

  • How can I run my doclet from main method?

    I want to run doclet from main method.
    My source is:
    command = String.format("%s%s%s%s",
    "cmd /c ",
    "% javadoc -doclet ",
    "ExportJavaLib ",
    "-private " + dir.getAbsolutePath() + ".java");
    Runtime.getRuntime().exec(command);My doclet class file is in the same directory where is my class containing main method.
    I run the main class from bat file and set
    set CLASSPATH=%CLASSPATH%;D:\jdk1.5.0_06\lib\Tools.jarBut my code does nothing when it must execute the doclet.

    I've done it. 10x :)

  • Cant call simple method from main method

    hi guys, this maybe a stupid question, im a newbie to java programming. Im trying to call the method calculateArea in main method and its not working.
    Any ideas?
    Thanks.
    package project1;
    public class makePurchase {
        public int calculateArea(int width, int height){
                int myArea = width * height;
                return myArea;
        public static void main(String[] args){
            int vTestResult = calculateArea(1,3);
            System.out.println("The total is:" +vTestResult);
    }

    jverd wrote:
    mishmash wrote:
    Is there a easy way of determining if the method should be static? maybe only if your using a math class and not using the method in any other class?Static means associated with the class as a whole, not with any particular instance. If your method doesn't use or set any state that is part of individual instances, it may be a candidate to be static. Another difference is that static methods cannot be overridden. That is, you can't defer until runtime which class' implementation of a static method to call.
    public class Person {
    private static int numPersonsCreated;
    private String name;
    private Date birthdate;
    public int calculateAgeInYears () {
    // use birthdate to calculate age
    public static int getNumPersonsCreated() {
    return numPersonsCreated;
    }Here, the calc method cannot be static, since it uses the birthdate field that is particular to each Person object created. The number of Person objects created by your program, however, is not associated with any particular Person object, but with the Person class as a whole, so it can be static.Perhaps to expand a bit more...
    Highly reusable methods are candidates for static such as utility methods that may be used multiple times.This is true if this methods API remains consistent and does not care a bout the surrounding class. Usually such a method would require all its fields to be provided by parameters or as static members as any instance variables would not make this methods reusable.
    in jverd's example you can see that many related classes may be interested in finding out how many people have been created and they may wish to know so at the same time. It certainly makes sense to provide such a method as static as it does not change and most likely never will. More importantly all interested classes now are assured of seeing the exact same method because that is what static is: It exposes the same to all interested parties.
    Edited by: Yucca on Oct 19, 2009 6:35 AM

  • Running Fop from JAVA program

    Hi all,
    this may be a rookie question....hope you can help.
    I can run Fop (0.18.0) perfectly from the command line. I created a style
    sheet (xsl file), which converts the xml file. On the command line, I input
    the xsl file, the xml file, and state the name for the pdf file.
    Now I'm trying to run Fop from within method in my JAVA program. This
    doesn't seem to work. Here's the code. Can someone tell me what I'm doing
    wrong? Is it okay to run Fop this way? My classpath is set up properly
    (it runs on the command line).
    Here's the code..............Thanks in advance for any help.
    String [] pdfParams = new String[6];
    pdfParams[0] = "-xsl";
    pdfParams[1] = xslFile;
    pdfParams[2] = "-xml";
    pdfParams[3] = xmlFile;
    pdfParams[4] = "-pdf";
    pdfParams[5] = pdfFile;
    org.apache.fop.apps.Fop.main(pdfParams);
    Regards,
    Suryakant.

    When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.
    One thing that jumps out at me is that you're calling waitFor() and then trying to read the process' stdout. But waitFor waits for the process to die, so the stream is no longer there when you try to read it.
    See this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to use Action listener from Static method

    Hello,
    I am begginer in Java. I am trying to add JButton and add ActionListener to it in the Java tutorial example (TopLevelDemo).
    The problem i am facing are:
    1. Since "private static void createAndShowGUI" method is static I cannot reference (this) in the method addActionLisetener when trying to add the JButton
    JButton pr = new JButton("Print Report");
         pr.addActionListener(this);
    2. If I make "private static void createAndShowGUI" a non static method then it does not run from main method giving me the error(cannot reference non-static).
    3. Where do I put actionPerformed method?
    I did not post the errors for all situations. Just asking how I can Add JButton and add ActionListener to it in the following code
    Thanks
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    /* TopLevelDemo.java requires no other files. */
    public class TopLevelDemo {
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("TopLevelDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create the menu bar. Make it have a cyan background.
    JMenuBar cyanMenuBar = new JMenuBar();
    cyanMenuBar.setOpaque(true);
    cyanMenuBar.setBackground(Color.cyan);
    cyanMenuBar.setPreferredSize(new Dimension(200, 20));
    //Create a yellow label to put in the content pane.
    JLabel yellowLabel = new JLabel();
    yellowLabel.setOpaque(true);
    yellowLabel.setBackground(Color.yellow);
    yellowLabel.setPreferredSize(new Dimension(200, 180));
    //Set the menu bar and add the label to the content pane.
    frame.setJMenuBar(cyanMenuBar);
    frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }

    Here is one way of doing it...
    JButton btn = new JButton("Click on Me");
    btn.addActionListener(new ActionListener(){
                              public void actionPerformed(ActionEvent ae){
                                // do something
                                }});here we create an anonymous inner class ActionListener and add it to our button...
    - MaxxDmg...
    - ' I am not me... '

  • Calling Classes main method

    I have two classes, I want to create a new instance of Class B and run it's main method...not sure if I'm being clear. Any help is greatly appreciated :)

    Actually, I have Class A that sends an email with an attachment, copies the File into another folder (backup), and deletes the old file. Class B deletes all backed-up files with a last modified greater than 30 days. I wish to run Class B's main method from Class A....somewhat of a method call (main method).
    Do I just have to import the DeleteFile and create a new instance of DeleteFile? I'm just getting back into the swing of java and have forgotten :)
    Also, do you know how to place a timer around a Delete method? I'm calling the following methods in a row, but my Delete method will only delete on the very first iteration....although the Copy, SendEnrollMail works properly everytime...hmmmm? I've looked throughout support, but cannot find exactly what I'm looking for.
    // Import packages/classes
    import IKEvent;
    import java.io.*;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    import java.text.*;
    // Class declaration
    class StringToken{
    // Static method called from main method - can't instantiate
    public static void copyFile(String aOldFile, String aNewFile, String aAttachment)throws IOException{
    // Local variables
    String oldFile = aOldFile;
    String newFile = aNewFile;
    String attachment = aAttachment;
    String currentDate = "";
    // Instantiate a Date object
    Date myDate = new Date();
    // Convert myDate(long) to String
    currentDate = myDate.toString();
    // Format currentDate variable
    SimpleDateFormat format = new SimpleDateFormat("dd_MM_yyyy");
    currentDate = format.format(new Date());
    // Copy instructor report
    File inputFile = new File(oldFile);
    File outputFile = new File(newFile + currentDate + "_" + attachment);
    FileInputStream in = new FileInputStream(inputFile);
    FileOutputStream out = new FileOutputStream(outputFile);
    int c;
    while ((c = in.read()) != -1)
    out.write(c);
    in.close();
    out.close();
    // Static method called from main method - can't instantiate
    public static void deleteFile(File aDeletedFile)throws IOException{
    // Local variables
    File delFile = aDeletedFile;
    // Delete the instructor report
    delFile.delete();
    // sendEnrollMail method
    public static boolean sendEnrollMail(String aSmtpServer, String anEmail, String aFirstName, String aLastName, String logFile, String ccAddress, String aCourseSession, String aFileName, String aReportDir)throws IOException{
    // Local variables
    Properties props = System.getProperties();
    String mailServer = aSmtpServer;
    String crseSession = aCourseSession;
    String emailAddress = anEmail;
    String firstName = aFirstName;
    String lastName = aLastName;
    String filename = aFileName;
    String reportDir = aReportDir;
    // Begin error checking
    try{
    // SMTP protocol, relays message to the SMTP server of the recipient(s)
    // eventually to be acquired by the user(s) through POP or IMAP
    props.put ("mail.smtp.host", mailServer);
    // Instantiate a basic mail session object, uses java.util.Properties
    Session emailsession = Session.getDefaultInstance(props, null);
    // Create a message, pass along the session object to the MimeMessage constructor
    Message email = new MimeMessage(emailsession);
    // Set from of email - administration
    InternetAddress fromAddress = new InternetAddress(ccAddress, "Name");
    email.setFrom(fromAddress);
    // Set recipient(s) of email
    InternetAddress[] address = {new InternetAddress(emailAddress), new InternetAddress(ccAddress)};
    email.setRecipients(Message.RecipientType.TO, address);
    // Set subject/date
    email.setSubject("Evaluations Results Report for Session " + crseSession);
    email.setSentDate(new Date());
    // Fill the message
    StringBuffer welcomeMessage = new StringBuffer();
    welcomeMessage.append("Hi ").append(firstName + " " + lastName + ":"+'\n'+'\n');
    welcomeMessage.append("The Evaluations Results Report for Session " + crseSession + " has been attached to this email. If you have any problems accessing the file, please contact aName at there-email."+'\n'+'\n');
    // Creation of message part
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText(welcomeMessage.toString());
    // Create a multipart
    Multipart multipart = new MimeMultipart();
    // Part one is inputting the text of the message
    multipart.addBodyPart(messageBodyPart);
    // Part two is attachment
    // Create second body part, attachment
    messageBodyPart = new MimeBodyPart();
    // Get the attachment
    DataSource source = new FileDataSource(reportDir + filename);
    // Set the data handler to the attachment
    messageBodyPart.setDataHandler(new DataHandler(source));
    // Set the filename
    messageBodyPart.setFileName(filename);
    // Add part two
    multipart.addBodyPart(messageBodyPart);
    // Put parts in message
    email.setContent(multipart);
    // Send the message
    Transport.send(email);
    // Append the log file with success
    FileOutputStream fout = new FileOutputStream ( logFile , true );
    PrintStream pout = new PrintStream (fout);
    // Log a successful email
    pout.println ('\r');
    pout.println (new java.util.Date() + " - Send Enroll Email Successful!");
    pout.println ("email: " + emailAddress);
    pout.println ("first name: " + firstName);
    pout.println ("last name: " + lastName);
    pout.close();
    // End of error checking for sendEnrollMail function
    catch (MessagingException e) {
    // Append the log file with failure
    FileOutputStream fout = new FileOutputStream ( logFile , true );
    PrintStream pout = new PrintStream (fout);
    // Print message to log upon failure
    pout.println ('\r');
    pout.println (new java.util.Date() + " - Send Enroll Email Failure!");
    pout.println ("email: " + emailAddress);
    pout.println ("first name: " + firstName);
    pout.println ("last name: " + lastName);
    pout.close();
    return false;
    Thank you!

  • How can I assign image file name from Main() class

    I am trying to create library class which will be accessed and used by different applications (with different image files to be assigned). So, what image file to call should be determined by and in the Main class.
    Here is the Main class
    import org.me.lib.MyJNIWindowClass;
    public class Main {
    public Main() {
    public static void main(String[] args) {
    MyJNIWindowClass mw = new MyJNIWindowClass();
    mw.s = "clock.gif";
    And here is the library class
    package org.me.lib;
    public class MyJNIWindowClass {
    public String s;
    ImageIcon image = new ImageIcon("C:/Documents and Settings/Administrator/Desktop/" + s);
    public MyJNIWindowClass() {
    JLabel jl = new JLabel(image);
    JFrame jf = new JFrame();
    jf.add(jl);
    jf.setVisible(true);
    jf.pack();
    I do understand that when I am making reference from main() method to MyJNIWindowClass() s first initialized to null and that is why clock could not be seen but how can I assign image file name from Main() class for library class without creating reference to Main() from MyJNIWindowClass()? As I said, I want this library class being accessed from different applications (means different Main() classes).
    Thank you.

    Your problem is one of timing. Consider this simple example.
    public class Example {
        public String s;
        private String message = "Hello, " + s;
        public String toString() {
            return message;
        public static void main(String[] args) {
            Example ex = new Example();
            ex.s = "world";
            System.out.println(ex.toString());
    }When this code is executed, the following happens in order:
    1. new Example() is executed, causing an object to constructed. In particular:
    2. field s is given value null (since no value is explicitly assigned.
    3. field message is given value "Hello, null"
    4. Back in method main, field s is now given value "world", but that
    doesn't change message.
    5. Finally, "Hello, null" is output.
    The following fixes the above example:
    public class Example {
        private String message;
        public Example(String name) {
            message = "Hello, " + name;
        public String toString() {
            return message;
        public static void main(String[] args) {
            Example ex = new Example("world");
            System.out.println(ex.toString());
    }

  • Is it possible to modify private member of a class directly from main?

    This is the code which modifies the private String stk[] indirectly from main method when sorting option is called from main method:
    import java.io.*;
    class Stack
        private String stk[];
        private int tos;
        private int size;
        Stack()
            size=5;
            stk=new String[size];
            tos=-1;
        Stack(int sz)
            size=sz;
            stk=new String[size];
            tos=-1;
        boolean push(String s)
            if(tos==size-1) return false;
            stk[++tos]=s;
            return true;
        String pop()
            if(tos<0) return "Stack Underflow";
            return stk[tos--];
        String[] display()//array type function to return an array called "stk"
            return stk;
        int returnSize()
            return tos;
    class myStack
        public static void main(String args[]) throws IOException
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            Stack S=new Stack();
            int opt=-1;
            while(opt!=6)
                System.out.println("\n\n\n");
                System.out.println("[1] - Create Stack");
                System.out.println("[2] - Push");
                System.out.println("[3] - Pop");
                System.out.println("[4] - Display");
                System.out.println("[5] - Display List In Ascending Order");
                System.out.println("[6] - Exit");
                System.out.print("Option: ");
                opt=Integer.parseInt(br.readLine());
                if(opt==1)
                    System.out.print("\n\nEnter the size of stack: ");
                    int size=Integer.parseInt(br.readLine());
                    S=new Stack(size);
                    System.out.print("\nStack Created...");
                else if(opt==2)
                    System.out.print("\n\nEnter String: ");
                    String s=br.readLine();
                    if(S.push(s))
                        System.out.print("\nSuccessfull...");
                    else
                        System.out.print("\nStack Overflow...");
                else if(opt==3)
                    System.out.print("\nItem Deleted: "+S.pop());
                else if(opt==4)
                    int sz=S.returnSize();
                    System.out.print("\n\n\nStack Contains: "+(sz+1)+" Item(s)\n");
                    String st[]=S.display();
                    while(sz>=0)
                        System.out.println(st[sz]);
                        sz--;
                else if(opt==5)
                    int s=S.returnSize();
                    String stc[]=S.display();
                    for(int i=0;i<=s;i++)
                        for(int j=i+1;j<=s;j++)
                            if(stc[j].compareTo(stc[i])<0)
                                String t=stc[i];
                                stc[i]=stc[j];
                                stc[j]=t;
                    System.out.println(stc[i]);
                else if(opt>6)
                    System.out.print("\nPress 6 To Exit....");

    Actually, since it is returning the reference value of the array, and he is changing the array elements using that reference, then he IS "changing the array".
    @OP:  When you return a reference value to an object (and, in this regard, an array IS an object), then use that reference value to change things in the object (NOT assigning a new value to the variable holding that reference value), then, of course, those items are changed, and everything using that same reference value will "see" those changes, as they ALL point to the SAME object.
    Edit:  My first answer was going under the assumption that you meant DIRECTLY changing (i.e. stk = ...) since all you provided was the "title" and a blurb of code.  Next time you should think about actually providing some information about the actual "problem".
    See http://www.javaranch.com/campfire/StoryCups.jsp (to get associated with the "terms" they use)
    then see http://www.javaranch.com/campfire/StoryPassBy.jsp for some easy to understand explanations of reference values and objects.

  • Is it possible to modify private member of a class directly from main function?

    This is the code which modifies the private String stk[] indirectly from main method when sorting option is called from main method:
    import java.io.*;
    class Stack
        private String stk[];
        private int tos;
        private int size;
        Stack()
            size=5;
            stk=new String[size];
            tos=-1;
        Stack(int sz)
            size=sz;
            stk=new String[size];
            tos=-1;
        boolean push(String s)
            if(tos==size-1) return false;
            stk[++tos]=s;
            return true;
        String pop()
            if(tos<0) return "Stack Underflow";
            return stk[tos--];
        String[] display()//array type function to return an array called "stk"
            return stk;
        int returnSize()
            return tos;
    class myStack
        public static void main(String args[]) throws IOException
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            Stack S=new Stack();
            int opt=-1;
            while(opt!=6)
                System.out.println("\n\n\n");
                System.out.println("[1] - Create Stack");
                System.out.println("[2] - Push");
                System.out.println("[3] - Pop");
                System.out.println("[4] - Display");
                System.out.println("[5] - Display List In Ascending Order");
                System.out.println("[6] - Exit");
                System.out.print("Option: ");
                opt=Integer.parseInt(br.readLine());
                if(opt==1)
                    System.out.print("\n\nEnter the size of stack: ");
                    int size=Integer.parseInt(br.readLine());
                    S=new Stack(size);
                    System.out.print("\nStack Created...");
                else if(opt==2)
                    System.out.print("\n\nEnter String: ");
                    String s=br.readLine();
                    if(S.push(s))
                        System.out.print("\nSuccessfull...");
                    else
                        System.out.print("\nStack Overflow...");
                else if(opt==3)
                    System.out.print("\nItem Deleted: "+S.pop());
                else if(opt==4)
                    int sz=S.returnSize();
                    System.out.print("\n\n\nStack Contains: "+(sz+1)+" Item(s)\n");
                    String st[]=S.display();
                    while(sz>=0)
                        System.out.println(st[sz]);
                        sz--;
                else if(opt==5)
                    int s=S.returnSize();
                    String stc[]=S.display();
                    for(int i=0;i<=s;i++)
                        for(int j=i+1;j<=s;j++)
                            if(stc[j].compareTo(stc[i])<0)
                                String t=stc[i];
                                stc[i]=stc[j];
                                stc[j]=t;
                    System.out.println(stc[i]);
                else if(opt>6)
                    System.out.print("\nPress 6 To Exit....");

    Short answer is: no.
    Long answer is: you should not try to. Information hiding is the fundamental principle of OOP. This means that the code dealing with an object has no knowledge about the objects inner structure. It only knows the methods provided by its interface.
    You should declare all object properties private and prevent any other code outside the owning class to manipulate it. This includes leaking properties via "getter" methods. In your example the display() method is bad in two ways:
    its name does not convey its purpose.
    it a "getter" that returns the private property stk to the caller who may change it. Eg. the caller could add or delete an entry without changing tos accordingly.
    bye
    TPD

  • How to run executable Java app from command line: No Main( ) method

    This is the opposite question from what most users ask. I have the Java source code and a running Java executable version of the program in a windows environment. I don't want to run it in the normal way by double-clicking on it or using the executable. I need to be able to run the same application from the command line. If I can do this, I can then compile and run the code on my Mac, too, which is what I am ultimately trying to accomplish.
    Normally, this would be easy. I would look for a Main method, normally public static void main (String[] args ) or some variation. I cannot find a main() anything, anywhere when searching the files. There must be some windows executable that links to the Java classes. It's very clever, no doubt, but that's not helping me.
    I am trying to run what I can determine as the Main class, with a standard command line call, but that is not working either.
    It is a Java graphics program, so mostly Swing container stuff.
    I am not finding a manifest.txt file, telling me where a main method is, nor anything about the Main Class. There is no readme file for the program.
    Any insight that would point me in the right direction? What should I be looking for?
    Thanks in advance, Bloozman

    It's possible there's a clever Windows executable that runs the class. But if it's a plain old Java class then there's a good chance there's a constructor. Look for that; it's possible you may be able to start by writing another Java class that creates an instance of your mystery class.
    When you have that done, try running it. It's possible that just creating an instance might be sufficient to run it. Swing programs are sometimes written like that. If not, then start looking for methods with names like "run" or "go" or "start" that your little controller program can call.

  • Running a main Method from another class??

    Hi,
    I am trying to run a main method from another class, eg the main method is in Class1 and i am trying to run it from class2.
    So I have
    class1 c1 = new class1();
    c1.main();and I get the following compilation error:
    clas2.java:42: main(java.lang.String[]) in class1 cannot be applied to () c1.main();
    any ideas on how to do this correctly
    thanks in advance,
    Donal

    Hi thanks for the replies,
    tried just passing a string earlier and that just gave errors too, I should have been more specific and pass a string array.
    Its working now thanks again.
    Donal

  • Running a method in a class from main.mxml

    So... this seems dumb, but I can't seem to run a method on an instance of a class. I should be able to
    arraycollectioninstance[0].methodinclass();    //this doesn't work
    I also tryed arraycollectioninstanace.getItemAt().methodinclass();
    All I want to do in run the function sortByUdn() that resides in the class definition from main.mxml on an instance of an arraycolleection. How do I do this and why doesn't the above attempts work? What am I missing?
    Below is my class:
    package status
    import mx.collections.ArrayCollection;
    import mx.collections.IViewCursor;
    import mx.collections.Sort;
    import mx.collections.SortField;
    import org.osmf.layout.AbsoluteLayoutFacet;
    [Bindable]
    public class Rack
      public var currentSort:String = 'udn';
      public var lowestUdn:int;
      public var highestUdn:int;
      public var circuits:int;
      public var rackModel:String;
      public var rackLevels:ArrayCollection = new ArrayCollection;
      public function Rack(response:XMLList):void
       circuits = response[0].info.length();
       for (var i:int=0; i < circuits; i++)
        rackLevels.addItem(new Level(
         response[0].info[i].@udn,
         response[0].info[i].@circuit,
         response[0].info[i][email protected](),
         response[0].info[i][email protected]()
       findMinMax();
    protected function sortByUdn():void
       var udnSort:Sort = new Sort()
       udnSort.fields = new Array();
       udnSort.fields.push(new SortField('udn',true,false,true));
       this.rackLevels.sort = udnSort;
       this.rackLevels.refresh();

    Thanks for the response!!!
    So my problem is that my class (Rack) has the functions, but I'm using an arraycollection of instances of this class. So in my main Application I have:
    public var current_rack:ArrayCollection = new ArrayCollection;
    then later on I'm using a current_rack.addItem(new Rack(.......)  several times to make the instances.
    I'm trying to call a function in one instance of current_rack[7] to perform a sort on that instance. I'm storing the sort function as part of the class, as it sorts the inards of the class instance.
    I really want to current_rack[0].sortByUdn();
    Though the above doesn't generate a compiler error, I get a runtime error of RangeError: 'Index '0' specified is out of bounds'

  • Running a java application without a main method

    class MainMethodNot
        static
            System.out.println("This java program have run without the run method");
            System.exit(0);
    }The reason this works is that static initialization blocks get executed as soon as the class is loaded, even before the main method is called. During run time JVM will search for the main method after exiting from this block. If it does not find the main method, it throws an exception. To avoid the exception System.exit(0); statement is used which terminates the program at the end of the static block itself.
    got it from http://www.java-tips.org/

    This has been published many times on this forum. What is your question?

  • Static main methods and run()

    I am having trouble with main methods, and how to structure code, im not 100% sure on what static methods are, and im not sure how to use it when calling other methods etc cos its static and stuff - i read that i should put stuff in the constructor - but im not sure how this will work with a run()
    I have written a program to draw some objects (just an oval at a certain position)
    anyway here is the main method:
    public static void main(String[] args) {
            // TODO code application logic here
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    Main game = new Main();
                    game.createAndShowGUI();
                    //Create some graphics objects at the desired position!
                    GOA[0] = new GraphicsObject(300,200);         *
                    GOA[1] = new GraphicsObject(350,200);         *
                    game.frame.updateGraphics(GOA);            *
        }I am getting "non-static variable GOA cannot be referenced from a static context" at * i cant just make everything static, how should this be structured? where should the run() be?
    Thanks for any help

    Ok, i might as well include the whole thing - its not too big , and i would like to see if any of it is right really.
    ackage joefootball2;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferStrategy;
    public class Main {
        GameWindow frame;
        //Create the graphics object array to pass to the painting stuff
        GraphicsObject[] GOA;
        private void createAndShowGUI() {
            //Create and set up the window.
            frame = new GameWindow();
            frame.DrawWindow();
        public static void main(String[] args) {
            // TODO code application logic here
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    Main game = new Main();
                    game.createAndShowGUI();
                    //Create some graphics objects!
                    GOA[0] = new GraphicsObject(300,200);
                    GOA[1] = new GraphicsObject(350,200);
                    game.frame.updateGraphics(GOA);
    class GameWindow extends JFrame
        DrawPanel canvas;
        public void updateGraphics(GraphicsObject[] GOA)
            canvas.updateObjects(GOA);
        public void DrawWindow()
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            canvas = new DrawPanel();
            canvas.setDoubleBuffered(true);
            this.getContentPane().add(canvas);
            this.setVisible(true);
            this.setSize(800, 600);
            this.setResizable(false);
    class DrawPanel extends JPanel
        //Create the graphics object array to draw
        GraphicsObject[] GOA;
        public void updateObjects(GraphicsObject[] givenGOA)
            GOA=givenGOA;
        public void paint(Graphics g)
            for (int i=0 ; i<GOA.length ; i++)
                g.drawOval(GOA.x-5, GOA[i].x-5, 10, 10);
    class GraphicsObject
    //for now, just make the graphics object a point to draw a circle
    int x; int y;
    }thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Question of the day: In which Thread context does the main method run ?

    let's say, you create a JFrame in the main method:
    public static void main(String[] args)
    new MyJFrame();
    let's suppose, you construct the whole JFrame
    inside the constructor, which contains a lot
    of other Swing components, like JTree's and more.
    AND the JFrame calls setVisible(true) in its
    constructor.
    -> According to my knowledge, this won't work
    properly - it will function, BUT you will get one
    or two quite big exceptions (which usually start
    with a nullpointer exception, produced by the
    PLAF, but the whole stacktrace shows, that the
    the exception was thrown AND catched inside
    the Swing objects.
    Reason for this would be, that all operations
    after the "setVisible(true)" statement must be
    carried out in the eventdispatch thread, according
    to Swing rules.
    Now, as you can see by running the source below,
    the main() method always is processed in special thread,
    NOT the event dispatch thread - which produces the above behaviour.
    My Question:
    Wouldn't it have been easier to let the JVM
    process the main() methods right in the
    event dispatch thread ?
    Or:
    Why is the JVM designed to process the
    main() method in a special thread and not
    the Swing event dispatch thread ?
    opinions?
    Regards
    JPlaz / SnowRaver
    package Test1;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Frame1 extends JFrame
    public Frame1( final String title, int position )
    this.setSize(400,300);
    this.setLocation(position,position);
    this.setVisible(true);
    if( SwingUtilities.isEventDispatchThread() )
    System.out.println("Constructor of "+title+" is processed IN the event dispatch thread.");
    else
    System.out.println("Constructor of "+title+" is processed in ANOTHER than the event dispatch thread.");
    public static void main(String[] args)
    // First creation just from the startup thread context :
    new Frame1("first Frame", 60);
    // Now we let the second creation be done in the
    // eventdispatch thread context for sure :
    SwingUtilities.invokeLater( new Runnable()
    public void run()
    new Frame1("second Frame",120);

    Matt,
    it's been so long, I don't have the full answer in my head.
    This page on Adobe.com has an example that shows Flash 4
    mouse stuff (I'm Mr
    Vague today) when you scroll down. Your timelinme reference
    will be
    something like
    TellTarget(_Root, gotoAndPlay(50))
    Hopefully from that vagueness you can locate the right
    answer.
    Steve
    Adobe Community Expert: Authorware, Flash Mobile and Devices
    My blog -
    http://stevehoward.blogspot.com/
    Authorware tips -
    http://www.tomorrows-key.com

Maybe you are looking for

  • Problems with Mac OSX 10.5.2 and installing my pro tools le 7.1.1

    Problems with Mac OSX 10.5.2 and installing my pro tools le 7.1.1. My garage band & reason software don´t open anymore giving me a error messasge regarding the midi drivers in the operating system. Please help!!! Thanks, Paolo

  • Downloading iTunes / Windows 7

    I just downloaded iTunes to my PC that runs Windows 7 and get the message - iTunes stopped working, even after uninstalling and re-installing the program? Please help!

  • Why does address book quit responding in lion?

    Since installing Lion on my MacBook Pro, the address book, after opening, quits responding and will only close with a force quit. What should I do to fix it?

  • Preview crashes when opening documents

    Beginning today, when I try to open documents with Preview, the application freezes. Any suggestions?

  • Tablespace allocation

    Hi Please recommend for the following: 1. I have a 30gb data to be transferred to production DB, its a cluster database. can i create a tablespace with two 15gb datafile having a 30gb tablespace or three 10gb datafile having 30 gb tablespace. For a b