Creating array of objects of JLabel , JTextField type

hello,
I wanted to create an array of objects of JLabel class. I wrote and complied the following lines. it was successfully compiled but during execution it showed - 'start: applet not initialized' on the applet's window. What wrong have I done and how can I get rid of that?
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
/*<html>
<applet code="test.class" width=200 height=300>
</applet>
</html> **/
public class test extends JApplet
     Container c = getContentPane();
     JLabel lb[];
     public void init()
               for( int i = 0; i < 10; i++ )
               lb[i] = new JLabel( "Line" + i );
               c.add( lb[i] );
}

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
/*<html>
<applet code="test.class" width=200 height=300>
</applet>
</html> **/
public class test extends JApplet
     Container c = getContentPane();
     JLabel lb[] = new JLabel[10];
     public void init()
               for( int x = 0; x < 10; x++ )
               lb [x]= new JLabel( "Line" + x );
               c.add( lb );
// showing applet not initiliazed
// generating nullPointerException
// please helpLast post, thats a promise!!! :-)Still wrong. See corrections in 'for' loop. :)

Similar Messages

  • Creating array of object

    Using JNI, I'm trying to pass an array of object from the C native side to
    the Java side. I have the following code:
    JNIEXPORT jint JNICALL Java_classA_methodB(
    JNIenv *env,
    jobject obj,
    jobjectArray objArr )
    jclass objClass = ( *env )->FindClass( env, "arrObjClass" );
    jmethodID methodID = ( *env )->GetMethodID( env, objClass, "<init>", "()V" ); // Default constructor
    jobject objElement = ( *env )->NewObject( env, objClass, methodID );
    // ... Fill objElement with values
    ( *env )->SetObjectArrayElement( env, objArr, 0, objElement ); // <-- program core dumps here.  WHY? 
    return 1;
    The program core dumps at the line above and I don't understand why?
    objArr is originally set to null when pass to the native function. Does
    objArr have to be allocated using new before pass to the native function?
    Thank you in advance,
    Duong

    You seem to be trying to write into an array passed as an input argumenet, when you haven't in fact passed an array object.
    (At least that's what I interpreted you to say what you are doing.)
    Either construct an array in java and pass it to C++, or if that is probelmatic, then change the C++ return object from an int to an array, and do the construction in C++.

  • Help With Creating Array of Objects

    I made a little test class
    class MyClass
        public int x = 0, y = 0;
    }Then I tried to declare an array.
    MyClass testObjs = new MyClass[10];However, when I tried to assign values using
    testObjs[0].x = 3;I got an error. What's the problem?
    Thanks.

    I'm thinking that you'll get a compile time message even without assigning anything. So what is the actual code and the actual error message?
    In general terms the procedure is:
    (1) Declare a variable of the type "array of MyClass"
    (2) Create (with "new") and assign a reference to an array to the variable - possibly in the same line
    (3) Populate the array - that is create (with "new") references to MyClass objects and assign them to slots in the array
    (4) Do things with the references to MyClass objects that are in the array slots.

  • Creating array of objects of class which extends Thread

    getting NullPointerException
    can i not create thread array this way?
    class sample extends Thread
    { int i,id;
      public sample(int c)
       { id=c;
      public void run()
      { for(i=0;i<6;i++)
         System.out.println("Thread "+id+" "+i);
    public class thread extends Frame implements ActionListener
    {  Button b1;
       sample s[];
       thread()
       { for(int i=0;i<2;i++)
              s=new sample(i);
         setLayout(new FlowLayout());
         b1=new Button("OK");
         add(b1);
         b1.addActionListener(this);
         public void actionPerformed(ActionEvent e)
         {   b1.setEnabled(false);
              for(int i=0;i<2;i++)
              { s[i]=new sample(i);
              s[i].start();
         public static void main(String args[])
         { thread t1=new thread(); 
         t1.setVisible(true);
         t1.setSize(150,150);

    You need:
    sample [] s = new sample[2];However
    1) You should get into the habit that class names start with capital letters, variable and field names with lower case.
    2) It's not a good idea to extend Thread, make a class which implements the Runnable interface and hook a standard Thread object to that.

  • How do I create Arrays for objects?

    I want to create an array of type Cards. Is this the right way of doing it?
    Card decker[];
    decker = new Card[5];
         I always get the error DeckofCards: java:47: missing return statement whenever I compile this.

    Look at line 47 of DeckOfCards.java and see what you've done wrong. The example you posted isn't the problem.
    %

  • Reading arrays of objects

    I am new to OCI programming, but have read the manuals on reading objects, but can not figure out how to do what I want to do from that documentation. I am using oracle 9.2.0.7
    I have a package that produces a bunch of data. Currently this data is stored as records in local variables. From my understanding OCI can not read oracle records
    so that I will need to change package to use either varrary or associative arrays. I do not want to place this data into a actual oracle table because the data only has meaning at time package procedure is run and then is out of date for any other purposes. I Only want to read the data that is created in sql packages so that my C program can do other work with that data. It will change data into an XML format that Internet Application will use.
    This is where I am stuck, it is implied that OCI should be able to read these created arrays of objects, but all examples are reading oracle tables that have objects in them. So I would like either an example or some suggestions on how to get started on doing this. So far I have created and oracle object type that has my fields in it. Since I do not know how many records I will be creating when I
    run this package I think I should put data in an associative array.

    Hi
    Yes, you'll need to publish the data somehow. One way to do it is to place the data into a PL/SQL collection; then select from that.
    There's a write up of some examples at http://www.dbasupport.com/oracle/ora9i/cast.shtml
    HTH
    regards Nigel

  • Array of Object

    How to create array of object dynamically and the class is also having constructor.
    like:
    class Cir{
    private double radius;
    Cir(double r){
    redius=r;
    10 objects are to be created within for loop

    Cir c[]=new Cir[10]
    for(int i=0;i<10;i++)
    c [ i ] =new Cir(radious);
    Message was edited by:
    ramireddi

  • Check this out: making a copy of an array of objects

    I have an array of objects called Figs of type Figure and I am making a copy of this array called OriginalFigs so later when Figs change, I can use the original values stored in OriginalFigs.
    But I found out that when values in Figs change, values in OriginalFigs also change.
    I tried to store values in Vector too but even in Vector values are changing.
    seems like they both are storing reference to Figs and when Figs change , they(Vector and OriginalFigs) chnage too.
    Is there any way to come around this problem?
    if u know then plz share with me..........

    Hi,
    how do you copy them - if you use the method from Object(? was it there, never use this), you will get a shallow copy - that is a new object with the same references in it - not a new object with new objects of the figures in it.
    How about providing a methode in your figure-objects which can do a total copy? - This must be easy as so you know how to construct such an object efficiently.
    Another way to hold a copy is to write the figures out to a stream temporarily - all objects are serializable and so they can be stored to a stream - but your figures should not have references to other parts of the program in it, because the serialisation-process tries to serialize all references the object has, that is to be serialized. If there is for exampe a link to the main JFrame in it, the serialisation process tries to store your hole program to the stream and this may be impossible - I hat this with parts of a JTree that refuse to be stored to a stream.
    Hope, this will help
    greetings Marsian

  • Create array of arbitrary dimensions / get Class object for primitive types

    Here's an interesting problem: is there any way to code for the creation of an n-dimensional array where n is only known at runtime (input by user, etc.)?
    java.lang.reflect.Array has a newInstance method which returns an array of an arbitrary number of dimensions specified by the int[] argument, which would give me what I want. However, the other argument is a Class object representing the component type of the array. If you want to use this method to get an array of a primitive type, is it possible to get a Class object representing a primitive type?

    That doesn't help, since the whole problem is that the number of dimensions aren't known until runtime. You can't simply declare a variable of type int[][] or use an int[][] cast, since the number of []'s is variable.
    The int.class construction was partly what I was looking for. This returns the array needed (assuming some read method):
    int dimensions = read();
    int size = read();
    int[] index = new int[dimensions];
    for (int i = 0; i < dimensions; i++)
        index[i] = size;
    Object myArray = Array.newInstance(int.class, index);The only problem is, as an Object, I can't use myArray usefully as an array. And I can't use a cast, since that requires a fixed number of dimensions.

  • Creating an array of objects of a class known ONLY at RUNTIME

    I have a method in a class which expects an array of objects of particular type (say A) as its only argument. I 'invoke' this method using reflection. I have the instances of the class A stored in a Vector. When I do 'toArray' on this vector, what I get back is an array of Objects and not an array of objects of A. I assign this array to the zeroth element of another Object array and pass that array as a second argument to the 'invoke' method. Of course, it throws an Exception saying - argument types mismatch. Because I am sending an array of Objects to a method expecting an array of objects of A. My problem is I don't know A until runtime. So I have to handle whatever I am getting back after doing 'toArray' on a vector as a Generic Object. I know there's another version of 'toArray' in the Vector class. But it's API documentation didn't help a lot.
    Can anybody please help me solve this problem? Any sort of hints/code snippet would be of great help.
    Does the above description makes any sense? If not, please let me know. I would try to illustrate it with a code sample.
    Thanks a lot in advance.

    Sorry, for the small typo. It is -
    clazz[] arr = (clazz [])java.lang.reflect.Array.newInstance(clazz, n);
    instead
    Thanks for the reply. I could do this. But I am
    getting a handle to the method to be 'invoke'd by
    looking at the types of the parameters its
    expecting(getParameterTypes). So I can't change it to
    accept an array of Generic Objects.
    I looked at the java.lang.reflect.Array class to do
    this. This is what I am trying to do-
    String variableName is an input coming into my
    program.
    n is the size of the array I'm trying to create.
    Class clazz = Class.forName(variableName);
    clazz[] arr = (clazz
    [])java.lang.reflect.newInstance(clazz, n);
    According to Reflection API, it should work, right?
    But compiler yells at me saying 'class clazz not
    found'.
    Any suggestions/hints/help?
    Thanks, again.

  • Problem in creating a callable object of type Business Logic

    Hi SDN,
    I am trying to create a callable object of type Business Logic in CE.
    When I give all information and click Next, I get this error message.
    Error while loading configuration dialog: Failed to create delegate for component com.sap.caf.eu.gp.ui.co.CExpConfig. (Hint: Is the corresponding DC deployed correctly? Does the DC contain the component?)
    Can anybody help me out with this problem.
    Regards,
    Sumangala

    Hi.
    I'm having the same problem as Senthil in NW2004s SP15 with my application service and methods not showing up in the Callable Object wizard for Composite Application Services after I choose the Endpoint.  The only application name that shows up in the wizard is caf.tc, and the only service names that show up for it are LDDataAccessor, Metadata, and PropPermissionService.
    My IDE is on one machine and the application server I deploy to is located on a different machine.  My endpoint to the remote application server looks to be correctly configured.  The Composite Application Service seems to be deployed properly as I'm able to see it and test that it works in the Web Services Navigator <http://remotehost:50000/wsnavigator/>
    My deployed application service is a remote enabled service and is also web services enabled as well.
    I'm not sure if this is relevant, but I noticed that the generated Java code does not create any remote EJB interfaces (only home and local interfaces were generated).
    Something else I noticed is that when I proceed to the External Service Configuration -> Business Entities screen <http://remotehost:50000/webdynpro/dispatcher/sap.com/cafUIconfiguration>, I only see three business entities displayed, and the following error message is displayed: "Corrupt metadata has been detected. This may prevent some objects from being displayed. Check the server log for more details."  I was unable to find anything in the instance log files.  Is the error message indicative of the problem?
    I am developing locally without a NetWeaver Development Infrastructure (NWDI) in place.
    I'm wondering if the credentials specified in the endpoint require any special roles or privileges.
    Senthil, do any of these additional descriptions apply to you as well?
    Edited by: Ric Leeds on Jun 20, 2008 4:37 PM

  • Unable to create a Driver object from driver with Media type string CTC PHO

    Hi All,
    I am trying to develop a siebel cti adapter for avaya.
    I have loaded a custom dll into siebel server but it is throwing error "SBL-CSR-00500: Unable to create a Driver object from driver C:\Mydriver\cti.dll with Media-Type-String CTC Phone ".
    It has been long time without any progress.
    Please help
    Thanks
    Nishant

    Hi tomhowell,
    According to your description, my understanding is that you got an error when you created a site from a custom site template after migrading SharePoint 2010 to your server.
    Did you have the original solution file of the site template? Please re-deploy the solution to your SharePoint site, then create a site from the new site template, compare the result.
    Also use  SPDisposeCheck to indentify the memory leak:
    http://archive.msdn.microsoft.com/SPDisposeCheck
    http://www.fewlines4biju.com/2012/11/detected-use-of-sprequest-for.html
    Here are some similar posts for your reference:
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/3a25eb86-8415-4053-b319-9dd84a1fd71f/detected-use-of-sprequest-for-previously-closed-spweb-object-please-close-spweb-objects-when-you?forum=sharepointdevelopmentprevious
    http://social.msdn.microsoft.com/Forums/en-US/50ce964f-94a6-4fda-abc0-caa34e7111f1/error-detected-use-of-sprequest-for-previously-closed-spweb-object-occurs-when-new-site-gallery
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • Creating a generic class with a constructor that takes an array of objects

    I am relatively new to java and want to build a quick utility class that can generate a Run Length Encoding of any object. The idea is to take an array of objects of type "O" and then encode a string of objects that are "equal" to each other as an integer that counts the number of such equal instances and a single copy of the instance. This has the potential to very quickly reduce the size of some objects that I want to store. I would like to implement this class as a generic.
    public class RunLengthEncoding<O> {
         private class RLEPair {
              private int length;
              private O object;
         public RunLengthEncoding(O[]) {
    }As you can see, I need to make a constructor that takes an array of type "O". Is this possible to do? I can't seem to find the right syntax for it.
    Thanks,
    Sean

    Sorry. Obvious answer:
    public RunLengthEncoding(O[] oarray) {Again, sorry for the noise.

  • Trouble creating and populating an array of objects.

    I'm trying to create/populate an array of objects with consisting of a {string, double, integer}, and am having trouble getting this theory to work in Java. Any assistance provided would be greatly appreciated. Following are the two small progs:
    public class HairSalon
    { private String svcDesc; private double price; private int minutes;
    //Create a constructor to initialize data members
    HairSalon( )
    svcDesc = " "; price = 0.00; minutes = 0;
    //Create a constructor to receive data
         HairSalon(String s, double p, int m)
         svcDesc = s; price = p; minutes = m;
    //Create methods to get the data members
    public String getSvcDesc( )
         return svcDesc;
    public double getPrice( )
         return price;
    public int getMinutes( )
         return minutes;
    public class SortSalon
         public static void main(String[ ] args)
         SortSalon [] sal = new SortSalon[6];
    //Construct 6 SortSalon objects
              for (int i = 0; i < sal.length; i++)
              sal[i] = new SortSalon();
    //Add data to the 6 SortSalon objects
         sal[0] = new SortSalon("Cut"; 10.00, 10);
         sal[1] = new SortSalon("Shampoo", 5.00, 5);           sal[2] = new SortSalon("Sytle", 20.00, 20);
         sal[3] = new SortSalon("Manicure", 15.00, 15);
         sal[4] = new SortSalon("Works", 30.00, 30);
         sal[5] = new SortSalon("Blow Dry", 3.00, 3);
    //Display data for the 6 SortSalon Objects
         for (int i = 0; i < 6 ; i++ )
         { System.out.println(sal[i].getSvcDesc( ) + " " + sal.getPrice( ) + " " + sal[i].getMinutes( ));
         System.out.println("End of Report");

    Hey JavaMan5,
    That did do the trick! Thanks for the assistance. I was able to compile and run the program after adding my sorting routine. Do you happen to see anything I can do to clean it up further, or does it look ok? Thanks again,
    Ironjay69
    public class SortSalon
         public static void main(String[ ] args) throws Exception
         HairSalon [] sal = new HairSalon[6];      
         char selection;
    //Add data to the 6 HairSalon objects
         sal[0] = new HairSalon("Cut", 10.00, 10);
         sal[1] = new HairSalon("Shampoo", 5.00, 11);      
         sal[2] = new HairSalon("Sytle", 20.00, 20);
         sal[3] = new HairSalon("Manicure", 15.00, 25);
         sal[4] = new HairSalon("Works", 30.00, 30);
         sal[5] = new HairSalon("Blow Dry", 3.00, 3);
    System.out.println("How would you like to sort the list?");
         System.out.println("A by Price,");
         System.out.println("B by Time,");
         System.out.println("C by Description.");
         System.out.println("Please enter a code A, B or C, and then hit <enter>");
              selection = (char)System.in.read();
    //Bubble Sort the Array by user selection
              switch(selection)
              case 'A':
              BubbleSortPrice(sal, sal.length);
                   break;
                   case 'a':
              BubbleSortPrice(sal, sal.length);
                   break;
                   case 'B':
              BubbleSortTime(sal, sal.length);                    break;
                   case 'b':
              BubbleSortTime(sal, sal.length);
                   break;
                   case 'C':
              BubbleSortService(sal, sal.length);
                   break;
                   case 'c':
              BubbleSortService(sal, sal.length);
                   break;
                   default:
              System.out.println("Invalid Selection, Randomly Sorted List!");
    //Display data for the 6 HairSalon Objects
              for (int i = 0; i < sal.length ; i++ )
         System.out.println(sal.getSvcDesc( ) + " " + sal[i].getPrice( ) + " " + sal[i].getMinutes( ));
              System.out.println("___________");
              System.out.println("End of Report");
    public static void BubbleSortPrice(HairSalon[] array, int len)
    // Sorts the items in an array into ascending order by price
    int a, b;
    HairSalon temp;
    int highSubscript = len - 1;
    for(a = 0; a < highSubscript; ++a)
         for(b= 0; b < highSubscript; ++b)
         if(array.getPrice() > array[b + 1].getPrice())
              temp = array[b];
              array[b] = array [b + 1];
              array[b + 1] = temp;
    public static void BubbleSortTime(HairSalon[] array, int len)
    // Sorts the items in an array into ascending order by time
         int a, b;
         HairSalon temp;
         int highSubscript = len - 1;
         for(a = 0; a < highSubscript; ++a)
              for(b= 0; b < highSubscript; ++b)
         if(array[b].getMinutes() > array[b + 1].getMinutes())
         temp = array[b];
         array[b] = array [b + 1];
         array[b + 1] = temp;
    public static void BubbleSortService(HairSalon[] array, int len)
    // Sorts the items in an array into ascending order by time
         int a, b;
         HairSalon temp;
         int highSubscript = len - 1;
         for(a = 0; a < highSubscript; ++a)
         for(b= 0; b < highSubscript; ++b)
         if(array[b].getSvcDesc().compareTo( array[b + 1].getSvcDesc()) > 0)
                   temp = array[b];
                   array[b] = array [b + 1];
                   array[b + 1] = temp;

  • Formatted .data file, reading in and creating an array of objects from data

    Hi there, I have written a text file with the following format;
    List of random personal data: length 100
    1 : Atg : Age 27 : Income 70000
    2 : Dho : Age 57 : Income 110000
    3 : Lid : Age 40 : Income 460000
    4 : Wgeecnce : Age 43 : Income 370000
    and so on.
    These three pieces of data, Name,Age and Income were all generated randomly to be stored in an array of objects of class Person.
    Now what I must do is , read in this very file and re-create the array of objects that they were initially written from.
    I'm totally lost on how to go about doing this, I have only been learning java for the last month so anyone that can lend me a hand, that would be superb!
    Cheers!

    Looking at you other thread, you are able to create the code needed - so what's the problem?
    Here's an (not the only) approach:
    Create an array of the necessary length to hold the 3 variables, or, if you don't know the length of the file, create a class to contain the data. Then create an ArrayList to hold an instance of the class..
    Use the Scanner class to read and parse the file contents into the appropriate variables.
    Add each variable to either the array, or to an instance of the class and add that instance to the arraylist.

Maybe you are looking for