Why "parent is null"?

Hi guys,
I'm developing a simple Applet application with JDK 1.3.1.
All of codes are the following,
DemoApplet.java
public class DemoApplet extends Applet {
  private static final long serialVersionUID = -371112038768840393;
  public DemoApplet() {
    BorderLayout gridLayout = new BorderLayout();
    setLayout(gridLayout);
    add(new DemoPanel(), BorderLayout.CENTER);
  public void init() {
}DemoPanel.java
public class DemoPanel extends Panel {
  private static final long serialVersionUID = -5992125460349250223;
  private DemoPopupMenu popupMenu = new DemoPopupMenu();
  public DemoPanel() {
    addMouseListener(mouseAdapter);
  private MouseAdapter mouseAdapter = new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
      if (SwingUtilities.isRightMouseButton(e)) {
        popupMenu
            .show((DemoPanel) e.getComponent(), e.getX(), e.getY());
}DemoPopupMenu .java
public class DemoPopupMenu extends PopupMenu {
  private static final long serialVersionUID = -7751149413579159572;
  private Menu menu = new Menu("PopuMenu");
  public DemoPopupMenu() {
    add(menu);
}When I run DemoApplet with appletviewer, an exception was thrown:
Exception occurred during event dispatching:
java.lang.NullPointerException: parent is null
  at java.awt.PopupMenu.show(PopupMenu.java:102)
  at test.demo.DemoPanel$1.mouseClicked(DemoPanel.java:23)
  at java.awt.Component.processMouseEvent(Component.java:3713)
  at java.awt.Component.processEvent(Component.java:3539)
  at java.awt.Container.processEvent(Container.java:1159)
  at java.awt.Component.dispatchEventImpl(Component.java:2588)
  at java.awt.Container.dispatchEventImpl(Container.java:1208)
  at java.awt.Component.dispatchEvent(Component.java:2492)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:334)
  at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:126)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:93)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:88)
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:80) But if I changed all of PopupMenu/Menu to JPopupMenu/JMenu, all was OK.
Although the old AWT codes aren't recommended, I don't think the application is wrong.
I'm puzzled by the matter.
I wish some friend would explain the matter.
Thanks in advance!
a cup of Java, cheers!
Sha Jiang
Edited by: jiangshachina on Oct 29, 2007 4:44 PM

Oh, I get it.
Thanks for the reply.
Rewards a Duck star :-D
You never added the popupMenu to anything. Therefore, it has no parent and is not part of any component hierarchy.With the error output, I known the DemoPopupMenu need a "parent" component.
But I simple think DemoPanel is the parent for DemoPopupMenu,
because DemoPopupMenu is included by DemoPanel (so foolish!)
Also, you should not use isRightMouseButton() for handling popup actions.
There is a method called isPopupTrigger() in the MouseEvent class.
Call this in the mousePressed() and mouseReleased() methods of your MouseListener (instead of mouseClicked).I know the method isPopupTrigger().
In fact, at the beginning, I used isPopupTrigger(), but it didn't work.
Whether I right-click or left-click, both of the values of isPopupTrigger() are "false".
Then I have to redirect to isRightMouseButton() :-(

Similar Messages

  • HSlider trackSkin parent is null

    Hi
    I'm creating a programmatic skin for a slider track that is based on the value of the slider. The examples I've seen get the containing control from the skin's parent, and indeed for a button skin this works fine,  but for my trackSkin, the parent is always null.
    Is there something special I need to do in this case?
    Cheers

    This is wierd - I was checking parent yesterday and it was always null - today it's not null, so the proposed solution works.
    But I'm still comfused...
    Ah well
    Cheers

  • Can't figure out why this object = null

    I have a component which is used as an itemrenderer(in a
    datagrid). Inside the checkIfEditable() function it can't seem to
    find "img". It says it's null. I've got no clue why it would do
    that? If I look at the this.img variable during debugging it also
    says null.

    I fixed it by removing the HBox from the itemrenderer's
    component and doing like this:
    <mx:DataGridColumn headerText="" dataField="Open">
    <mx:itemRenderer>
    <mx:Component>
    <mx:HBox horizontalAlign="center" width="18">
    <local:OpenKastRenderer data="{data}"
    isEditable="{isEditable}"/>
    </mx:HBox>
    </mx:Component>
    </mx:itemRenderer>
    </mx:DataGridColumn>
    Altough now i get another error: Access of undefined property
    isEditable.(it's talking about {isEditable})
    I don't get why it says that, isEditable is defined as
    [Bindable]
    public var isEditable:int = new int();
    outside of any function and it's set by another component.
    EDIT: nevermind, i've made it static

  • Why this_date becoming null in dbms_job

    Hi ,
    This is how my code looks....
    decalre
    mysql VARCHAR2(1000);
    BEGIN
    mysql :='XXXXXXXXXXXX';
    DBMS_JOB.submit (jobno, 'begin ' || mysql || '; end;');
    commit;
    END;
    Using mysql I m invoking a procedure.When I am executing above block , jobs are getting inserted into dbms_jobs.
    But they are not getting executed.In user_jobs table, this_date column is going as NULL.
    ANy suggestions please

    Hi,
    930414 wrote:
    Hi ,
    This is how my code looks....
    decalre
    mysql VARCHAR2(1000);
    BEGIN
    mysql :='XXXXXXXXXXXX';
    DBMS_JOB.submit (jobno, 'begin ' || mysql || '; end;');
    commit;
    END;
    Using mysql I m invoking a procedure.When I am executing above block , jobs are getting inserted into dbms_jobs.
    But they are not getting executed.In user_jobs table, this_date column is going as NULL.If you're getting any results other than error messages, then I don't believe you're really running this code.
    DECLARE is mis-spelled, and jobno is not declared.
    ANy suggestions pleasePost a complete test script that people can run to re-create the problem and test their ideas. Include the CREATE PROCEDURE code for XXXXXXXXXXXX, and some code that checks whether the procedure ran or not.
    Why are you using dbms_jobs?
    If you want to run a procedure over and over (say, once a day), or at a particular time, then use dbms_scheduler.
    If you want to run the procedure just once, right away, then just run the procedure. Don't botherr with either dbms_jobs or dbms_scheduler.

  • Why delete [appserverdomain]/null folder during the Livecycle Es4 configuration

    Deploying LiveCycle EARs
    This operation may take several minutes to complete. When the deployment has completed successfully, click
     Next.
    Note:  After this step, ensure that you stop the managed server, node manager, and admin server, and then start them in the reverse order. Ensure that a directory named adobe is created in [appserverdomain] after the restart. This is required so that the [appserverdomain]/null directory does not get created, which can lead to the run time issues. Delete the [appserverdomain]/null directory if it gets created.
    ❖ On the Deploy LiveCycle ES4 EARs screen, select the EAR files to deploy and then click Deploy 
    Why is that folder created if we just delete it and why do we delete it?  The null folder has an abobe folder in it that looks identicle to the [appserverdomain]/adobe.

    This issue does not occur when deploy the EARs manually.
    It occurs intermittently when deploying the EARs using LCM and it is specific to Weblogic only. Reason behind this is Weblogic (as opposed to JBoss and Websphere) does not guarantee a particular start-up order of WARs within an EAR.
    The initialization does rely on a particular start-up order.
    Thus the null folder gets created sometimes.
    Hence it is always suggested to restart the server in a particular order to ensure that intialization happens properly. In case the [appserverdomain]/null directory gets created earlier, remove it.
    Hope this answers your question.
    ~ Varun Nohria

  • Why JDBC getConnection null? what is the problem?

    i have been using one class as thus clause:
    public java.sql.Connection getConnection(){
    String url = "jdbc:oracle:thin:@192.168.0.142:1521:test8152";
    java.sql.Connection con =null;
    java.sql.Statement stmt =null;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con = java.sql.DriverManager.getConnection(url,"conn","connection");
    } catch(Exception ex) { }
    return con;
    this method has been used normal in several instance for a long time, the oracle is all 816 enterprise, both for nt or linux or solaris.
    however, while i install a new oracle for linux on redhat6.2 which purchased recently, 816ee, i can not connect to it from other computers by this class, although i can connect to it by net8.sqlplus from other . nevertheless, i can connect to it in local computer by the same class with the same driver as classes12.zip; even if i use the drivers, which containd in the $ORACLE_home/jdbc/, the one is classes111.zip, the results is the same.
    the error message is the object do not exist, once i add the global service name, such as test8152.my_domain, the new message is 'refused connection'.
    thanks for your tips.
    null

    I had the same problem on this. The Linux Version of Oracle 8i seems have bugs on jdbc driver classes111.zip and classes12.zip ???
    I faced the same situation !!
    Do you find any other solution? It seems Oracle 8i oci/jdbc driver only support jdk 1.1.X . I am looking for oci/jdbc driver for 1.2. BUT I can not find it inside Oracle website ?!
    Do you find any ?
    Tommy Yang ( [email protected] )

  • Why does getParameter("uri") returns null ???

    Hi !
    JAVA can be rather frustrating and I have run of of dukes. How about IOU ?
    Unfortunately none of the previous questions in the db shed light on my problem.
    I am trying to get at the "uri" and I have the following code fragment :
    package com.developer;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.IOException;
    import java.io.PrintWriter;
    public class proptest extends HttpServlet
      public void doGet( HttpServletRequest req,  HttpServletResponse resp)
        throws ServletException, IOException
        PrintWriter out = resp.getWriter();
        out.println("Parameter Name: " + req.getParameter("uri"));
      public void init() throws ServletException
        // initialie the servlet here. Use ServletConfig object to get
        //    initialization parameters...
        ServletConfig config = getServletConfig();
        // ... more stuff ...
      }

    Hi!
    In case anyone stumbles upon this in the database, I worked aroung it by using req.getRequestURI().
    However I still do not know why getParameter() returns null. It would be useful e.g. if you want to display a list of all request params e.g.:
    // stub code follows...
    java.util.Enumeration enum = rea.getParameterNames();
    while (enum.hasMoreElements())
    String name = (String) enum.nextElement();
    System.out.println("Parameter "+name + " " + req.getParameter(name))
    ...For me, nope, all nulls. If it works for you , do tell me.
    Also if you look at the "bugs db" there seems to be a number of issues concerning getParameter().

  • Why is the itemRenderer null after a tab key in my DataGrid ?

    Hello all,
    I progress in my Flash application Thanks to all for your help !
    But now, I have a very strange problem:
    In my DataGrid, when I click on an item to edit it, in the ITEM_EDIT_BEGINNING event, the DataGridEvent.itemRenderer is set and has the correct value.
    When I use the TAB key, I go on the next column, the ITEM_EDIT_BEGINNING on the newly selected field is triggered, but in that case, the DataGridEvent.itemRenderer is null.
    I need that itemRenderer to have its x, y, width and height.
    Do you have an idea why it's null ?
    Thanks for all

    You may want to feedback to Apple
    http://www.apple.com/feedback

  • How to display all parent regions (repeatedly reference cursor)?

    CREATE TABLE regions
    PARENT_NAME VARCHAR2(30),
    CHILD_NAME VARCHAR2(30)
    INSERT INTO regions VALUES(NULL,'Asia');
    INSERT INTO regions VALUES(NULL,'Australia');
    INSERT INTO regions VALUES(NULL,'Europe');
    INSERT INTO regions VALUES(NULL,'North America');
    INSERT INTO regions VALUES('Asia','China');
    INSERT INTO regions VALUES('Asia','Japan');
    INSERT INTO regions VALUES('Australia','New South Wales');
    INSERT INTO regions VALUES('New South Wales','Sydney');
    INSERT INTO regions VALUES('Canada','Ontario');
    INSERT INTO regions VALUES('China','Beijing');
    INSERT INTO regions VALUES('England','London');
    INSERT INTO regions VALUES('Europe','United Kingdom');
    INSERT INTO regions VALUES('Illinois','Aurora');
    INSERT INTO regions VALUES('Illinois','Chicago');
    INSERT INTO regions VALUES('Illinois','Rockford');
    INSERT INTO regions VALUES('Japan','Osaka');
    INSERT INTO regions VALUES('Japan','Tokyo');
    INSERT INTO regions VALUES('North America','Canada');
    INSERT INTO regions VALUES('North America','United States');
    INSERT INTO regions VALUES('Ontario','Ottawa');
    INSERT INTO regions VALUES('Ontario','Toronto');
    INSERT INTO regions VALUES('United States','Colorado');
    INSERT INTO regions VALUES('United States','Illinois');
    INSERT INTO regions VALUES('United States','Texas');
    INSERT INTO regions VALUES('United Kingdom','England');
    COMMIT;
    Based on the REGIONS table, write a PL/SQL anonymous block that accepts a region name from the user input and display all its parent regions.
    right now this is what I have so far:
    ACCEPT p_1 PROMPT 'Please enter the region name: '
    DECLARE
    v_rname regions.child_name%type := '&p_1';
    v_count number;
    v_counter number := 0;
    v_parent regions.parent_name%type;
    v_child regions.child_name%type;
    cursor reg_cur is
    select parent_name, child_name from regions;
    BEGIN
    open reg_cur;
    fetch reg_cur into v_parent, v_child;
    select count(*) into v_count
    from regions
    where upper(child_name) = upper(v_rname);
    if v_count = 0 then
    dbms_output.put_line(v_rname || ' is not in the regions table.');
    else
    while reg_cur%found loop
    if upper(v_rname) = upper(v_child) then
    if v_parent is null then
    v_parent := v_child;
    dbms_output.put_line(v_count || ') ' || upper(v_parent));
    else
    dbms_output.put_line(v_count || ') ' || rpad(upper(v_rname), 20) || '<<<<<' || lpad(upper(v_parent), 10));
    end if;
    end if;
    fetch reg_cur into v_parent, v_child;
    end loop;
    end if;
    close reg_cur;
    END;
    if user inputs 'chicago' my query returns only a single parent. I'm not certain how to keep referencing the cursor so that I could output the rest of the parent_names and child_names until parent becomes null
    the output should be:
    chicago <<<<< illinois
    illinois <<<<< united states
    united states <<<<< North america

    Hi,
    If you have to do this in PL/SQL, then why don't you use Solomon's solution in PL/SQL?
    BEGIN
         FOR  regions_info  IN
                   select  child_name || ' <<<<< ' || parent_name     AS txt
                       from       regions
                       where      parent_name      is not null
                       start with      child_name      = '&p_1'
                       connect by      child_name      = prior parent_name
         LOOP
              dbms_output.put_line (regions_info.txt);
         END LOOP;
    END;
    /However, if you want to see what's happening with your code, add some code to make sure you don't get into an infinite loop. I used the local variable v_counter (which you had declared, but not used for anything else) to count how many times you had gone through the loop, and EXIT once you reach 100 times.
    Also, add some more calls to dbms_output, so you can see what's going on.
    For example:
         else
              v_counter := 0;
              loop
                   v_counter := v_counter + 1;
                   EXIT WHEN  v_counter > 100;
                   dbms_output.put_line (  v_child   || ' = v_child, '
                                  || v_parent  || ' = v_parent in LOOP'
                   open reg_cur;
                   fetch reg_cur into v_child, v_parent;
                   if upper(v_rname) = upper(v_child) then
                        dbms_output.put_line(v_counter + 1 || ') ' || rpad(upper(v_child), 20) || '<<<<<' || lpad(upper(v_parent), 10));
                   end if;
                   fetch reg_cur into v_child, v_parent;
                   close reg_cur;
                   v_parent := v_child;
                   exit when v_parent is null;
              end loop;
    ...Make sure you issue the SQL*Plus command
    SET   SERVEROUTPUT   ONbefore running this; otherwise, you won't see the output from put_line.
    What do you see?
    Do you understand why you're in an infinite loop?
    Do you really want the cursor to do exactly the same thing every time you call it?
    Maybe you should add a parameter to the cursor, which can be used in, say, a WHERE clause.
    Edited by: Frank Kulash on Feb 2, 2011 11:50 PM

  • ObjectInputStream() returning null and EOFException - need help

    I have been working on this little snippet of code all day and I cannot understand why I get null values when I run a display application. The code is posted below for 3 file. PhoneList.java is for serialization. CreatePhoneList is to populate a saved file with phone numbers and names of contacts. DisplaySavedPhoneList.java is to display the saved names and numbers. I'm not looking for the correct code, put for someone to point me in the right direction on why I'm getting these results so I can find a solution.
    Here is the PhoneList class:
    import java.io.*;
    public class PhoneList implements Serializable
        private String name;
        private String num;
        private String phName;
        private String phNum;
        PhoneList(String phNum, String phName)
            setName(phName);
            setNum(phNum);
        public String getName()
            return phName;
        public String getNum()
            return phNum;
        public void setName(String phName)
            name = phName;
        public void setNum(String phNum)
            num = phNum;
    }Here is the CreatePhoneList class
    import java.io.*;
    import java.util.*;
    public class CreatePhoneList
        public static void main(String[] args) throws IOException
            ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("PhoneList.txt"));
            PhoneList list;
            String phName;
            String phNum;
            final String QUIT = "QUIT";
            Scanner in = new Scanner(System.in);
            System.out.println("Enter a phone number or " + QUIT + " to quit.");
            phNum = in.next();
            while(!phNum.equals(QUIT))
                System.out.println("Enter the contact name.");
                phName = in.next();
                list = new PhoneList(phNum, phName);
                output.writeObject(list);
                System.out.println("Enter a phone number or " + QUIT + " to quit.");
                phNum = in.next();
            output.close();
    }and this is the DisplaySavedPhoneList class:
    import java.io.*;
    import java.util.*;
    public class DisplaySavedPhoneList
        public static void main(String[] args) throws IOException, ClassNotFoundException
            ObjectInputStream input = new ObjectInputStream(new FileInputStream("PhoneList.txt"));
            PhoneList list;
            final int SHOW = 1;
            int showList;
            int count = 0;
            Scanner in = new Scanner(System.in);
            try
                System.out.print("To display Phone List enter " + SHOW);
                showList = in.nextInt();
                while(showList == SHOW)
                    list = (PhoneList)input.readObject();
                    System.out.println("Name: " + list.getName() + " Phone Number: " + list.getNum());
                    count++;
            catch(EOFException e)
                System.out.println("Oops, something broke!");
                input.close();
    }This is the result from running the DisplaySavedPhoneList application:
    To display Phone List enter 1
    1
    Name: null Phone Number: null
    Name: null Phone Number: null
    Oops, something broke!

    ok, I did that, and its pointing me to the line commented below. I did a practical exercise where the code was almost identical and it worked fine. The only difference are the variables.
    try
                System.out.print("To display Phone List enter " + SHOW);
                showList = in.nextInt();
                while(showList == SHOW)
                    list = (PhoneList)input.readObject(); //this is the line that was identified in the stacktrace
                    System.out.println("Name: " + list.getName() + " Phone Number: " + list.getNum());
                    count++;
            catch(EOFException e)
                System.out.println("Stack Trace");
                e.printStackTrace();
                input.close();
            }here is the total stack trace, in case you were wondering...
    To display Phone List enter 1
    1
    Name: null Phone Number: null
    java.io.EOFException
    Name: null Phone Number: null
    Stack Trace
            at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2554)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1297)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
            at DisplaySavedPhoneList.main(DisplaySavedPhoneList.java:21)I'm still not quite sure what this is telling me though.

  • Why does PL/SQL not support 0 length strings?

    Why does Trim(' ') return null instead of an empty string?
    Why does '' return null instead of an empty string?
    Because of this, LENGTH(Trim(' ')) returns null. And I want zero.
    I ask because I'm cutting up a string and in other languages (even ones that support Null) when these techniques are used, I get a valid empty string.
    Am I wrong in feeling that an empty string is the equivilent to a 0 in a numeric field and that null in a string is equivilent to null in a numeric field?
    Andy

    For Oracle, by definition, a null string is a string of length 0 since at least Oracle 5.0 (i do not know the previous ones).
    use NVL
    Why does Trim(' ') return null instead of an empty string?
    Why does '' return null instead of an empty string?
    Because of this, LENGTH(Trim(' ')) returns null. And I want zero.
    I ask because I'm cutting up a string and in other languages (even ones that support Null) when these techniques are used, I get a valid empty string.
    Am I wrong in feeling that an empty string is the equivilent to a 0 in a numeric field and that null in a string is equivilent to null in a numeric field?
    Andy

  • NULL Value in Journal Entry and Wrong Tax Summary

    Hi people,
    I need your expert help for a big problem that appens to some customers.
    They run SAP BO 8.8 SP:00 PL:12
    This is the scenario:
    You insert a new documet,  A/R Invoice or A/P Invoice is the same, problem appear in all of them.
    After you insert the document, using SQL Server Management try this Select statment:
    Select * from JDT1 where JDT1.debit is null OR JDT1.credit is null
    A list of record where listed. And, this is the problem, NULL values are all in the VAT Lines in debit or credit colums.
    If you try to make a SUM(debit-credit) you discovery that, 1000,00-null=null
    Consequently, TAX Sumary report, that probably use arithmetic operation like me in SELECT statment,  count a wrong number when null values in DEBIT or CREDIT column in JDT1 for VAT declaration.
    How could I solve? And how i can make invoices store 0 rather than NULL in the VAT Line?
    Thanks in advance for your tips and solutions

    Thaks Neetu for your answer.
    I thinks there is a misurandertanding.
    My problem is not SQL.
    My problem is the SAP TAX Report.
    I used SQL only for check data and discover why SAP raise a wrong TAX Summary report.
    So, my question is: Why invoices write null values in journal entry, and how I can solve the problem that TAX summary report use null value in operations so the results are wrong.
    Thanks,
    Jonny Cortonicchi

  • How to check for null value of output parameter?

    Hi guys, I get a test procedure with 2 output parameters and do nothing:
    CREATE OR REPLACE PACKAGE BODY p_parameters_test AS
      PROCEDURE p_null_output_basetype(p1 OUT NUMBER,p2 OUT VARCHAR2)
      AS
      BEGIN
        DBMS_OUTPUT.PUT_LINE('DO NOTHING');
      END p_null_output_basetype;
    END;And I have below C# code:
    cmd.CommandText = "p_parameters_test.p_null_output_basetype";
    OracleParameter p1 = new OracleParameter("p1", OracleDbType.Decimal, System.Data.ParameterDirection.Output);
    OracleParameter p2 = new OracleParameter("p2", OracleDbType.Varchar2, System.Data.ParameterDirection.Output);
    cmd.Parameters.Add(p1);
    cmd.Parameters.Add(p2);
    try
        conn.Open();
        cmd.ExecuteNonQuery();
        if (p1.Value==null)
            Console.WriteLine("p1.Value==null");
        else if (Convert.IsDBNull(p1.Value))
            Console.WriteLine("Convert.IsDBNull(p1.Value)");
        else
            Console.WriteLine("p1 else "+p1.Value);
        if (p2.Value==null)
            Console.WriteLine("p2.Value==null");
        else if (Convert.IsDBNull(p2.Value))
            Console.WriteLine("Convert.IsDBNull(p2.Value)");
        else
            Console.WriteLine("p2 else "+p2.Value);
        Console.WriteLine("finished");
    catch......The output of it is:
    p1 else null
    p2 else null
    Does anyone have any idea why it always goes to the 'else' of the condition-branching, and how can I check if the output parameter is null?
    Thanks in advance.

    Morven... I ran into similar problems. Maybe you've found a solution of your own by now, but here's what I've learned...
    The Value property of output parameters, like p1 and p2 in your code, actually varies, according to (I think) the OracleDbType of the parameter. You've got OracleDbType.Decimal for p1 and OracleDbType.Varchar2 for p2. These look about right, since they match the parameter types in your actual stored procedure.
    After cmd.ExecuteNonQuery() executes, the respective Value properties of p1 and p2 are actually of different types. For p1, it's going to be "OracleDecimal" and for p2 it's "OracleString". Keep in miind that these are the types of the Value property of the OracleParameter objects, not the OracleParameter objects themselves.
    OracleDecimal and OracleString (and some other types like OracleDate, etc.) have an "IsNull" property you can use if you cast the Value property to its runtime type...
    if ((OracleDecimal)cmd.Parameters["p1"].Value).IsNull) { …do something… }
    else { …do something else… }
    Or maybe something like this...
    Decimal p1val = ((OracleDecimal)cmd.Parameters["p1"].Value).IsNull ? 0 : ((OracleDecimal)cmd.Parameters["AVG_SALARY"].Value).Value;
    I'll admit that expressions like this: ((OracleDecimal)cmd.Parameters["AVG_SALARY"].Value).Value look a little weird. But the "Value" of the "OracleDecimal" property is a regular .NET decimal type (System.Decimal). So, it's a "Value" of the "Value" property of the OracleParameter class.
    Even when the stored procedure returns a null, the Value property is still populated. In the case of p1, it's populated with an OracleDecimal object (actually a struct) where IsNull is true. That's why "p1.Value==null" tests false.
    From what I can see, OracleDecimal, OracleString, etc. will never be typed as DbNull, or DBNull.Value. So, that would be why Convert.IsDBNull(p1.Value)) always returns false. btw, it appears that these are Value types. That would suggest that coding something like like this, should be avoided…
    OracleString p2val = ((OracleString)cmd.Parameters["p2"].Value;
    if (p2val.IsNull) { …do something… }
    else { …do something else… }
    By assigning the value to another variable, you’d be actually creating an entire copy of the OracleString structure, which is pointless.
    I hope that helps
    Edited by: 897674 on Jan 3, 2012 10:44 AM
    Edited by: 897674 on Jan 3, 2012 10:46 AM

  • Problem with trees(Duplication of the parent node in creation of  children)

    Hi guys i am experiencing a slight problem with the creation of trees.Here is a clear explanation of my program.I created a program that generates edges from a set of datapoints then use each and every edge that is generated to create multiple trees with the edge as the rootnode for each and every tree.Everything up to so far everything went well but the problem comes when i want the program to pick every single tree and traverse through the set of generated edges to create the children of a tree.What it does at the moment for each tree is returning the a duplication of the parent node as the child nodes and that is a problem.Can anyone related with this problem help.Your help will be appreciated.
    The code
    TreeNode class
    package SPO;
    import java.util.*;
    public class TreeNode
            Edge edge;
            TreeNode node;
         Vector childrens = new Vector();
            public TreeNode(Edge edge)
                    this.edge = edge;
            public synchronized  void insert(Edge edge)
                    if(edge.fromNode == this.edge.toNode)
                            if(node == null )
                                    node = new TreeNode(edge);
                                    childrens.add(node);
                            else
                        node.insert(edge);
                                    childrens.add(node);
    Tree class
    package SPO;
    import java.util.*;
    public class Tree
            TreeNode rootNode;
         public Tree()
                    rootNode = null;
            public Tree[]  createTrees(Vector initTrees,Vector edges)
                   Tree [] trees =  new Tree[initTrees.size()];
                   for(int c = 0;c < trees.length;c++)
                      trees[c] = (Tree)initTrees.elementAt(c);     
                   for(int i = 0;i < trees.length;i++)
                            for(int x = 0;x < edges.size();x++)
                                    Vector temp = (Vector)edges.elementAt(x);
                                    for(int y = 0;y < temp.size();y++)
                                           trees.insertNode((Edge)temp.elementAt(y));
    return trees;
    public void printTree(Tree tree)
    System.out.print("("+tree.rootNode.edge.fromNode.getObjName()+","+tree.rootNode.edge.toNode.getObjName()+")");
    Vector siblings = tree.rootNode.childrens;
    for(int i = 0; i < siblings.size();i++)
    TreeNode node = (TreeNode)siblings.elementAt(i);
    System.out.print("("+node.edge.fromNode.getObjName()+","+node.edge.toNode.getObjName()+")");
    System.out.println();
    public Vector initializeTrees(Vector edges)
    Vector trees = new Vector();
    for(int i = 0;i < edges.size();i++)
    Vector temp = (Vector)edges.elementAt(i);
    for(int j = 0;j < temp.size();j++)
    Tree tree = new Tree();
    tree.insertNode((Edge)temp.elementAt(j));
    trees.add(tree);
    return trees;
    public synchronized void insertNode(Edge edge)
    if(rootNode == null)
    rootNode = new TreeNode(edge);
    else
    rootNode.insert(edge);
    EdgeGenerator class
    package SPO;
    import java.util.*;
    import k_means.*;
    public class EdgeGenerator
         public EdgeGenerator()
    public Vector createEdges(Vector dataPoints)
    //OrderPair orderPair = new OrderPair();
    Vector edges = new Vector();
    for(int i = 0;i < dataPoints.size()-1 ;i++)
    Vector temp = new Vector();
    for(int j = i+1;j < dataPoints.size();j++)
    //Create an order of edges
    Edge edge = new Edge((DataPoint)dataPoints.elementAt(i),(DataPoint)dataPoints.elementAt(j));
    temp.add(edge);
    edges.add(temp);
    return edges;
    Edge class
    package SPO;
    import k_means.*;
    public class Edge
    public DataPoint toNode;
    public DataPoint fromNode;
    public Edge(DataPoint x,DataPoint y)
    if (x.getX() > y.getX())
    this.fromNode = x;
    this.toNode = y;
    else
    this.fromNode=y;
    this.toNode = x;
    Entry Point
    package SPO;
    import java.util.*;
    import k_means.*;
    public class Tester {
         public static void main(String[] args)
              Vector dataPoints = new Vector();
              dataPoints.add(new DataPoint(140, "Orange"));
              dataPoints.add(new DataPoint(114.2, "Lemmon"));
              dataPoints.add(new DataPoint(111.5, "Coke"));
              dataPoints.add(new DataPoint(104.6, "Pine apple"));
              dataPoints.add(new DataPoint(94.1, "W grape"));
              dataPoints.add(new DataPoint(85.2, "Appletizer"));
              dataPoints.add(new DataPoint(84.8, "R Grape"));
              dataPoints.add(new DataPoint(74.2, "Sprite"));
              dataPoints.add(new DataPoint(69.2, "Granadilla"));
              dataPoints.add(new DataPoint(59, "Strawbery"));
              dataPoints.add(new DataPoint(45.5, "Stone"));
              dataPoints.add(new DataPoint(36.3, "Yam"));
              dataPoints.add(new DataPoint(27, "Cocoa"));
              dataPoints.add(new DataPoint(13.8, "Pawpaw"));
    EdgeGenerator eg = new EdgeGenerator();
    Vector edges = eg.createEdges(dataPoints);
    Tree treeMaker = new Tree();
    Vector partialTrees = treeMaker.initializeTrees(edges);
    Tree [] trees = treeMaker.createTrees(partialTrees,edges);
    for(int i = 0;i < trees.length;i++)
    treeMaker.printTree(trees[i]);
    The program output
    Each and every "@" symbol represents the start of a tree
    @(Orange,Lemmon)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)(Lemmon,Coke)
    @(Orange,Coke)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)
    @(Orange,Pine apple)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)
    @(Orange,W grape)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)
    @(Orange,Appletizer)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)
    @(Orange,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
    @(Orange,Sprite)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)
    @(Orange,Granadilla)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)
    @(Orange,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
    @(Orange,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
    @(Orange,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(Orange,Cocoa)(Cocoa,Pawpaw)
    @(Orange,Pawpaw)
    @(Lemmon,Coke)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)(Coke,Pine apple)
    @(Lemmon,Pine apple)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)
    @(Lemmon,W grape)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)
    @(Lemmon,Appletizer)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)
    @(Lemmon,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
    @(Lemmon,Sprite)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)
    @(Lemmon,Granadilla)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)
    @(Lemmon,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
    @(Lemmon,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
    @(Lemmon,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(Lemmon,Cocoa)(Cocoa,Pawpaw)
    @(Lemmon,Pawpaw)
    @(Coke,Pine apple)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)(Pine apple,W grape)
    @(Coke,W grape)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)
    @(Coke,Appletizer)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)
    @(Coke,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
    @(Coke,Sprite)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)
    @(Coke,Granadilla)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)
    @(Coke,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
    @(Coke,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
    @(Coke,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(Coke,Cocoa)(Cocoa,Pawpaw)
    @(Coke,Pawpaw)
    @(Pine apple,W grape)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)(W grape,Appletizer)
    @(Pine apple,Appletizer)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)
    @(Pine apple,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
    @(Pine apple,Sprite)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)
    @(Pine apple,Granadilla)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)
    @(Pine apple,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
    @(Pine apple,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
    @(Pine apple,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(Pine apple,Cocoa)(Cocoa,Pawpaw)
    @(Pine apple,Pawpaw)
    @(W grape,Appletizer)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)(Appletizer,R Grape)
    @(W grape,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
    @(W grape,Sprite)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)
    @(W grape,Granadilla)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)
    @(W grape,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
    @(W grape,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
    @(W grape,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(W grape,Cocoa)(Cocoa,Pawpaw)
    @(W grape,Pawpaw)
    @(Appletizer,R Grape)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)(R Grape,Sprite)
    @(Appletizer,Sprite)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)
    @(Appletizer,Granadilla)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)
    @(Appletizer,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
    @(Appletizer,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
    @(Appletizer,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(Appletizer,Cocoa)(Cocoa,Pawpaw)
    @(Appletizer,Pawpaw)
    @(R Grape,Sprite)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)(Sprite,Granadilla)
    @(R Grape,Granadilla)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)
    @(R Grape,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
    @(R Grape,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
    @(R Grape,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(R Grape,Cocoa)(Cocoa,Pawpaw)
    @(R Grape,Pawpaw)
    @(Sprite,Granadilla)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)(Granadilla,Strawbery)
    @(Sprite,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
    @(Sprite,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
    @(Sprite,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(Sprite,Cocoa)(Cocoa,Pawpaw)
    @(Sprite,Pawpaw)
    @(Granadilla,Strawbery)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)(Strawbery,Stone)
    @(Granadilla,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
    @(Granadilla,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(Granadilla,Cocoa)(Cocoa,Pawpaw)
    @(Granadilla,Pawpaw)
    @(Strawbery,Stone)(Stone,Yam)(Stone,Yam)(Stone,Yam)
    @(Strawbery,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(Strawbery,Cocoa)(Cocoa,Pawpaw)
    @(Strawbery,Pawpaw)
    @(Stone,Yam)(Yam,Cocoa)(Yam,Cocoa)
    @(Stone,Cocoa)(Cocoa,Pawpaw)
    @(Stone,Pawpaw)
    @(Yam,Cocoa)(Cocoa,Pawpaw)
    @(Yam,Pawpaw)
    @(Cocoa,Pawpaw)

    Your program description makes no sense. What exactly is it supposed to do?
    Your errors make no sense. What is it doing wrong?
    Your program output makes no sense. Look up pre-order, in-order, and post-order notation for representing trees. Pick one of those that you think would be best. I would go with pre-order. Because what you are doing isn't understandable.
    By the way, I think your concept of a tree is flawed. A node in a tree has 3 things. it has a reference to its parent, it has references to any of its children, and it has some key value that represents the node (if each node were represented by numbers, the value would be an integer or something). In the case of the root, its reference to its parent is null. I don't know what you are doing with your tree, but it is highly confusing.

  • Hiding parent row in a tree

    Hello to all the Apex champs out there, can you please help me with the following problem:
    I have a table, and in its simplified version, it has the following rows:
    Id  Pid       Description
    1    NULL   Id 1, Parent Id NULL
    2    1         Id 2, Parent Id 1
    3    2         Id 3, Parent Id 2
    4    1         Id 4, Parent Id 1
    5    4         Id 5, Parent Id 4
    When these rows are displayed in a tree, the output is:
    Id 1, Parent Id NULL
       Id 2, Parent Id 1
          Id 3, Parent Id 2
       Id 4, Parent Id 1
          Id 5, Parent Id 4
    I am on a form page that already shows the record with id as 1 (and the tree root id as 1), and I need to display only the children for 1, i.e.
    Id 2, Parent Id 1
       Id 3, Parent Id 2
    Id 4, Parent Id 1
       Id 5, Parent Id 4
    Is there a way by which I can suppress the first Parent Id record as I am already viewing the record on the page?
    Many thanks in advance.
    Regards,
    Dhruva

    Hi,
    Your tree must contain a root node - that is, the top parent in the tree.
    You can, however, hide this by replacing the contents of the tree's Parent Node Template with &amp;nbsp; (you have to put something in the setting otherwise Apex will reset it to the default contents).
    Andy

Maybe you are looking for