Home     |     Java    |     Php General    |     Oracle Database    |     Oracle Server  

MS Dynamics CRM 3.0

  •  Setting up and Configuring Microsoft Dynamics CRM 3.0
  •  Managing Security and Information Access
  •  Entity Customization: Concepts and Attributes
  •  Entity Customization: Forms and Views
  •  Entity Customization: Relationships, Custom Entities, and Site Map
  •  Reporting and Analysis
  •  Workflow
  •  Server-Side SDK
  •  Client-Side SDK
  •  Integration with External Applications
  • Cervo Technologies
    The Right Source to Outsource

    Sharepoint Portal Server KB

    Microsoft CRM Info

    WPF Interview Questions

    SilverLight Interview Qs

    Asp.Net 2.0 Interview Qs

    Asp.NET 1.1 FAQs

    Oracle Interview Questions

    SAP Interview Questions

    Java Programming

    How to solve this problem of initialization


    / Create JradioButton and add to jrpnlRadBtn
                    String temp[] = {"Compilers","Operating
    Systems","Computer Networks"};
                    JRadioButton jrbtnSub[];
                    for(int i=0;i<3;i++) {
                            jrbtnSub[i] = new JRadioButton(temp[i]);
                            jpnlRadBtn.add(jrbtnSub[i]);
                    }

    Above code snippet gives the error: JRadioButtonDemo.java:22: variable
    jrbtnSub might not have been initialized
                            jrbtnSub[i] = new JRadioButton(temp[i]);

    Ravi wrote:
    > / Create JradioButton and add to jrpnlRadBtn
    >                 String temp[] = {"Compilers","Operating
    > Systems","Computer Networks"};
    >                 JRadioButton jrbtnSub[];

         This says: "jrbtnSub is a variable that can refer to
    arrays of JRadioButton references."  It does not actually
    create an array, it just says that jrbtnSub can refer to
    one if you ever decide to create one.  For example, you
    might continue with

            jrbtnSub = new JRadioButton[3];  // or perhaps more

    to create a three-element array and set jrbtnSub to point
    at it.  Or you could declare and initialize in one line with

            JRadioButton[] jrbtnSub = new JRadioButton[3];

         (Stylistic note: Most Java practitioners prefer
    `SomeType[] arrayRef' over `SomeType arrayRef[]', although
    both forms are legal.  It is felt that the first form collects
    all the type information in one place, while the second spreads
    it out in separate chunks.  Using the second form also calls
    into question one's dedication to Java by showing that one has
    not yet fully renounced C!)

    --
    Eric Sosman
    esos@acm-dot-org.invalid

    "Ravi" <ra.ravi.@gmail.com> wrote:
    >/ Create JradioButton and add to jrpnlRadBtn
    >                String temp[] = {"Compilers","Operating
    > Systems","Computer Networks"};
    >                JRadioButton jrbtnSub[];
    >                for(int i=0;i<3;i++) {
    >                        jrbtnSub[i] = new JRadioButton(temp[i]);
    >                        jpnlRadBtn.add(jrbtnSub[i]);
    >                }

    > Above code snippet gives the error: JRadioButtonDemo.java:22: variable
    > jrbtnSub might not have been initialized
    >                        jrbtnSub[i] = new JRadioButton(temp[i]);

    Yup. The more conventional form of the loop might have given you a clue:

    for(int i = 0; i < jrbtnSub.length; i++) {

    You need to intialize jrbtnSub. You probably mean something like:

    JRadioButton jrbtnSub[] = new JRadioButton[temp.length];

    -- Adam Maass

    Ravi wrote:
    > / Create JradioButton and add to jrpnlRadBtn
    >                 String temp[] = {"Compilers","Operating
    > Systems","Computer Networks"};
    >                 JRadioButton jrbtnSub[];
    >                 for(int i=0;i<3;i++) {
    >                         jrbtnSub[i] = new JRadioButton(temp[i]);
    >                         jpnlRadBtn.add(jrbtnSub[i]);
    >                 }

    > Above code snippet gives the error: JRadioButtonDemo.java:22: variable
    > jrbtnSub might not have been initialized
    >                         jrbtnSub[i] = new JRadioButton(temp[i]);

    In addition to what other replies have said, you might consider using a
    (java.util.)List instead of an array for the buttons. With a List you
    don't need to know the number of elements when you create it (and there
    are many other advantages). So your code could become:

             String[] subjectNames = {
                 "Compilers", "Operating Systems",
                 "Computer Networks"
             };
             List<JRadioButton> subjectButtons =
                 new java.util.ArrayList<JRadioButton>();
             for (String name : subjectNames) {
                 JRadioButton button = new JRadioButton(name);
                 subjectButtons.add(button);
                 subjectPanel.add(button);
             }

    (I've changed then identifier names, because I find the likes of "jrbtn"
    unreadable and unhelpful.)

    Tom Hawtin

    Ravi wrote:
    >> / Create JradioButton and add to jrpnlRadBtn

    Please do not multi-post.  No one is able to see who else answered your
    question or what they said, which is rather rude to the people you want to
    help you.  It is also rude to the people trying to follow the thread for their
    own edification.  So please do not multi-post.

    Patricia Shanahan gave a good answer over in clj.help, for those of you who
    missed it over in cjl.programmer:

    Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc