My generic array creation problem.

I'm getting a "generic array creation" error on lines 6 and 14. I've googled it and I'm still having a hard time. Most things I find on it are pretty complicated and as you can see mine's not, I'm in a beginners course. I'm basically writing a class with methods for dealing with a file of donors.
Here's my code:
public class DonorList <dlist>
    //Create empty list
    public DonorList()
        storage = new dlist [MAX];
        count = 0;
    //Capacity as specified
    public DonorList (int cap)
        MAX = cap;
        storage = new dlist [MAX];
        count = 0;
    public boolean isEmpty()
        return count == 0;
    public void clear()
        count = 0;
    //Returns number of elements
    public int size()
        return count;
    //Item at position k, position starts at zero
    public dlist get (int k)
        if (k >= 0 && k < count)
            return storage [k];
        return null;
    // e becomes item at position k
    public dlist set (int k, dlist e)
        dlist old = null;
        if (k > 0 && k < count)
                old = storage [k];
                storage [k] = e;
        return false;
    //Returns the position of e or -1 if not found.
    public int indexOf (dlist e)
        int k;
        for (k = 0; k < count; k++)
            if (e.equals(storage[k]))
                return k;
        return -1;
    //Appends e at the end of the list. Returns false on failure.
    public boolean append (dlist e)
        if (count < MAX)
            storage [count] = e;
            count ++;
            return true;
        return false;
    //Adds e at position k. Returns false on failure.
    public boolean add (int k, dlist e)
        int j;
        if (count == MAX || k < 0 || k > count)
            return false;
        for ( j = count; j > k; j--)
                storage [j] = storage [j-1];
                storage [k] = e;
                count ++;
                return true;
        return false;
    private int MAX = 100;
    private dlist [] storage;
    private int count;
}Any help as to why I am getting these errors is very much appreciated. Thanks.

You cannot create an array of a generic, instead you need to create an array of the class the generic extends (in this case Object)
You then have to cast the array to the generic type which will give you an unchecked warning which you can turn off with @SuppressWarning("unchecked") on the class.
Generics and arrays don't always play nicely together and this is one case. ;-)

Similar Messages

  • Generic Datasource creation problem..Please Help

    There is a problem in creating a generic datasource.It doesnt permit us to create a DS on table EKBE
    .(error states that solution is create a view or DDIC).
    We created a view on four tables ( including all tables EKBE is referencing).EKBE has only 842 records.But the view created has 23400 recs.
    The table names are
    EKPO
    EKKO
    EKBE(references the other tables mentioned)
    T001
    .How do we solve this problem?Help needed .
    Edited by: Prathibha Pillai on Apr 11, 2008 6:17 AM

    Greetings,
    hi
    I am getting an javax.naming.InvalidNaming exception
    I am using the expression java:comp/env/jdbc/myAtmDBThe 'lookup name' "jdbc/myAtmDB" is not set in your bean's environment. This should be set as the res-ref-name in your deployment descriptor...
    i have set jdbc/Cloudscape as the jndi name in the
    propertyThis, presumably, is the JNDI binding name by which your application server knows to find the resource. This, however, must be linked to your bean's "resource reference lookup name" (above). How to make the "link" is vendor specific so read your vendor docs.
    please can anyone tell me how to go about it.
    thanks
    swaroopRegards,
    Tony "Vee Schade" Cook

  • Error: Generic Error Creation

    Hi All,
    Following in the line which is giving error "Generic Error Creation" on compile:
    Line:
    public static Queue<String>[] mqPrcLst = new LinkedList<String>[BankerAndFifo.miNoOfPrc];
    Result:
    FIFO.java:12: generic array creation
    public static Queue<String>[] mqPrcLst = new LinkedList<String>[BankerAndFifo.miNoOfPrc];
    Here is what I am trying to do:
    Create an array of Queue objects where each process will have its own queue containing a set of instructions pertaining to that process.
    I am a novice in this field[Collections].
    Kindly guide me.
    Regards,
    java_learner_s

    jverd wrote:
    java_learner_s wrote:
    @jverd
    What would you have me do? Either use a List instead of an array, or don't use generics here. Those are your only real options.Or fake it:
       public static void main(String[] args) {
          List<String>[] x = createGenericArray(10);
          x[0] = new LinkedList<String>();
       @SuppressWarnings("unchecked")
       public static <T> T[] createGenericArray(int length) {
          return (T[]) new Object[length];
       }Use at your own risk (though, to be honest, I don't see anything unsafe about it. Except the ClassCastException...give me a sec to fix).
    Edit Here we go.
       public static void main(String[] args) {
          List<String>[] x = createGenericArray(List.class, 10);
          x[0] = new LinkedList<String>();
          x[1] = new ArrayList<String>();
    //      x[2] = new LinkedList<Integer>(); // doesn't compile
       @SuppressWarnings("unchecked")
       public static <U, T extends U> T[] createGenericArray(Class<U> type, int length) {
          return (T[]) Array.newInstance(type, length);
       }I don't like it and would probably never use it, but is it unsafe?
    Edited by: endasil on 12-Nov-2009 2:28 PM

  • Automatic array creation

    Hi,
    I am trying to build an array automatically by use of boolean array. I use for loop in the VI but when the boolean array false it assigned "0" into the array. I do not want to assign "0", instead of, I want to pass this step and assign when the boolean array element true. How could I do it?
    Egemen
    Solved!
    Go to Solution.
    Attachments:
    automatic array creation.vi ‏9 KB
    array assign.png ‏26 KB

    Use the Build Array in the TRUE case!
    Also, create an array constant and wire that into the shift register in order to initialize it.
    If you are this lost, you really should go through the LabVIEW 101 tutorials.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Conditional Build Array.png ‏15 KB

  • Generic arrays

    I want to make an array of LinkedLists of Doubles. I tried:
    LinkedList<Double> buckets = new LinkedList<Double>[n];which gave me an error because I'm creating a generic array. On the other hand, if I do
    LinkedList<Double> buckets = new LinkedList[n];I get a warning suggesting that the compiler was looking for the first version!
    How do I do this?

    McNepp wrote:
    It seems to be a common misconception that one has to
    resort to Reflection in order to create arrays
    of generic types.It is not a misconception. On the contrary. It depends on what the library writer is trying to achieve. If I understand Neal Gafter in his blog http://www.gafter.com/~neal dated from September 23rd titled Puzzling Through Erasure: answer section correctly - currently his site is unavailable but you could still find cached page through Google -, that it should be fine to use reflection. Using reflection is perfectly legal if the library writer wants to design the API in such way that the type parameters are not erased. Type parameters are stored inside of the class using class literals. He says that in this case "you can instantiate using reflection (tClass.newInstance()), create arrays (Array.newInstance), cast (Class.cast), and do instanceof tests (Class.isInstance), though with a slightly different syntax than you might prefer".
    I'm still learning generics and I might be wrong.
    Best regards,
    Andrej

  • Generic Data Source Creation Problem....URGENT!!!!!!!!!!!!!

    Hello BW Experts...!
    I need to create a Generic Data Source out of a table called VBSEGK... I was trying in the usual way with RSO2 , but when I press save button after entering the Table name the following error is coming:
    " Invalid Extract Stucture Template VBSEGK of Data Source ZPARK_01"
    and when I click on the error message its showing
    Diagnosis
    You tried to generate an extract structure with the template structure VBSEGK. This operation failed, because the template structure quantity fields or currency fields, for example, field DMBTR refer to a different table.
    Procedure
    Use the template structure to create a view or DDIC structure that does not contain the inadmissable fields.
      VBSEGK is a standard table , so I cant change the Table structure. Can any one give me some idea of how to create Data source with this table ASAP ASAP please....
         Please ask me questions if you didnt get this...
    thanks

    Hi Harish,
    Please check OSS note 335342.
    Symptom
    The creation of a generic DataSource which is extracted from a DDIC view or a transparent table terminates with error message R8359:Invalid extract structure template &2 of Datasource &1
    Other terms
    OLTP, DataSource, extractor, data extraction, generic extractor
    Reason and Prerequisites
    The problem is caused by a program error.
    Solution
    The table or view used for extraction must have currency and unit fields within the field list of the table/view for all currency and quantity key figures.Otherwise the consistency of the extracted data cannot be ensured.To make the generation possible, check whether all key figures of your table refer to unit fields that are within the field list.If this is not the case, there are two possibilities:
    1. A table is used for extraction.
    Create a view in which you have a currency / unit field contained in the view for each key figure. The currency / unit field from the table must be included in the view to which the key figure actually refers.
    Example:
    Field WKGBTR of table COEP refers to the unit field WAERS of table TKA01. In a view that contains field COEP-WKGBTR, table TKA01 and field WAERS must be included in the field list.
    If the currency or the unit a key figure refers to is not located in a table but in a structure, the key figure has to be removed from the view and read via a customer exit (see below). Structures cannot be included in a view.
    ATTENTION!! Often the key of the table in which the referenced unit is located, does not agree with the key in the table with the corresponding key figure. In this case, the join condition of both tables is not unique in the view definition, that means for each key line of the table with the key figure, several lines of the table with the unit may be read: the result is a multiplying of the number of lines in the view by a factor corresponding to the number of lines that fit the key figure, in the unit table. To be able to deliver consistent data to a BW system, check whether the unit of the key figure in question should always have a fixed value. If yes then you can determine that in the view definition via 'GoTo -> Selection conditions'. If no, then you must proceed as follows:
    a) Remove the key figure from the view
    b) Define the DataSource
    c) Enhance the extract structure by key figure and unit for each append (Transaction RSA6)
    d) Add the key figure and the unit in a customer exit
    2. A view is already used for the extraction
    If it is not possible to obtain a unit of measure from a table on which the view is based, the unit field must be deleted from the field list.
    A note in relation to the upward compatibility of BW-BCT InfoSources: BW-BCT 1.2B was not yet able to check units and currency fields. For this reason, it is possible that InfoSources which were defined in the source system as of BW-BCT 1.2B must be redefined as of 2000.1 in the manner described above. However, checks are absolutely essential for the consistency of the extracted data.
    Regards,
    Praveen

  • ARRAY object creation problem in Java

    Hi I am encountring when trying to create ARRAY in one case
    while the same code works perfectly in other case.
    The following code works fine:
    Connection con=getConnection();
    String[][] elements = new String[1][2];
    elements[0][0] =new Long(1111).toString();
    elements[0][1] =new Long(2222).toString();
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TYPE1",con);
    toReturn = new ARRAY(desc,con,elements);
    The following CODE GIVES ERROR :
    Connection con=getConnection();
    String[] elements = new String[1];
    elements[0] =new Long(1111).toString();
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TYPE2",con);
    toReturn = new ARRAY(desc,con,elements);
    Please help.
    FYI :
    type TYPE1 is table of OBJECT : (ID NUMBER, Name VARCHAR2(50));
    type TYPE2 is table of OBJECT : (ID NUMBER);
    I tried to pass array of long ,int etc in case of TYPE2 but with no advantage.

    Hi Lawrence,
    I have checked the system in the correct path only. I am checking in the following path
      System Admnistration -->System Landscape-->then Portal content (on the left hand side)
    What do you mean by consistancy problem ??? Mean while i will check with basis guys Apart from consulting them , As a Ep consultant do i need to check anything???
    please correct me if i am wrong.....

  • Detla Infopackage Creation problem at Generic data source

    Hi Experts..
    In 7.0 BI I'm loading data in infoCube through generic data source ( type Table View). I have loaded the data first time ie Full mode. Now I would like to change update mode full to Delta. i have tried to create new infoPackage with DELTA Update MODE but this option is not available. as i have used Transformation and DTP to fetch the data in Info cube. in data souce Generic Delta is enabled at Numeric pointer.
    your help will highly appreciable.
    Regards
    kamal
    INDIA

    >
    kspurohit wrote:
    > Delta specif field kept blank with option Numeric Pointer...
    You have to fill in the Delta-Specific Field Name for any of the options.  Numeric pointer is usually a document number that is guaranteed to increment with every change.  This would not be a good choice for documents that can be changed after initial creation, or for number ranges that are buffered across application servers (unless you can set the safety limits to compensate).
    After that, create and run an init InfoPackage, then you will be able to create a delta InfoPackage.

  • Array creation in generic method.

    I have next class.
    public class Data implements Comparable<Data>
        private int val;
        public Data(int val)
            this.val = val;
        public int getVal()
            return val;
       public void setVal(int val)
            this.val = val;
        @Override
        public int compareTo(Data o)
            return val - o.val;
    And I need create a duplicated array of Data object in a method which is a template with variable type
    public class CopyClass
        public static int[] duplicate ( int[] data)
            int array[] = new int [data.length * 2];
            for (int i = 0; i < data.length; i++)
                array[2*i] = data[i];
                array[2*i+1] = data[i];
            return array;
        public static<T extends Comparable<? super T>> T[] duplicate ( T[] data)
            T array[] = (T[])new Object [data.length * 2];
            for (int i = 0; i < data.length; i++)
                array[2*i] = data[i];
                array[2*i+1] = data[i];
            return array;
        public static void logg ( int[] data)
            String msg = "{";
            for (int d : data)
                msg += " " + d;
            msg += "}";
            System.out.println(msg);
        public static void main (String []args)
            int [] val = { 7, 14, 2};
            int [] vals = duplicate(val);
            logg(val);
            logg(vals);
            Data[] data = {new Data(7), new Data(14), new Data(2)};
            Data[] datas = duplicate(data);
    Firts duplicate method works fine because it has a integer array as parameter an return an array whom values are duplicated.
    Second duplicate methos don't works.
    { 7 14 2}
    { 7 7 14 14 2 2}
    Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Comparable;
      at analisis.utilidades.CopyClass.duplicate(CopyClass.java:30)
      at analisis.utilidades.CopyClass.main(CopyClass.java:60)
    Java Result: 1
    Who I can create this kind of objects arrays?

    T array[] = (T[])Array.newInstance(data.getClass().getComponentType(), data.length * 2);

  • RAID creation problem (-200001)

    I have a newly installed Xserve RAID connected to two Xserves. When I try to create a RAID array on either controller, I immediately get an error "RAID Set 1 Creation Complete (-200001)".
    The RAID admin tool then tells me that "RAID Creation Started" but the "Arrays & Drives" tab tells me that all drives belong to an unknown array and they aren't visible in Disk Utility on either machine.
    Any suggestions as to what might be causing this problem?
    James

    Ah, so everything is happening in RAID Admin?
    I haven't seen the error you're getting before. You have deleted the RAID sets first and then try and create it by selecting drives with checkboxes?
    What firmware version are you using? If you just have a bunch of spare drives with no data to date, try updating to 1.5. If that fails, you may want to try calling AppleCare, as that's an error I haven't seen before.

  • Tree creation problem

    Hi,
    I wrote the following code to create the tree in hierarchical manner.
    The following code creates three tree nodes, where each node stores
    the information(con, Meas, Child and Next). When i print the nodes using
    print function, it was printed all 4's as contents of 'Meas' array in all nodes.
    Why it was printed only 4's as contents of 'Meas' array in all nodes? I initallized 1's and 2's as contents of 'Meas' array in first two nodes. Can any one help me in fixing the problem?
    Thanks in advance
    by
    sudhakar
    public class Tree {
    private Tnode root;
    class Tnode {
    String Con;
    float [][]Meas;
    Tnode Child;
    Tnode Next;
    Tnode(String cword, float [][]parameters) {
    Meas = new float[6][5];
         Meas = parameters;
         Con = cword;
    Child = null;
    Next = null;
    public void Tree() {
    root = null;
    public void insert(String data, float [][]meas) {
    root = insert(root, data, meas);
    private Tnode insert(Tnode node, String Con, float [][]meas){
    if (node==null) node = new Tnode(Con,meas);
    else if (Con.indexOf(node.Con)==0)
    node.Child = insert(node.Child, Con,meas);
    else node.Next = insert(node.Next, Con,meas);
    return node;
    public void print()
         if(root!=null) print(root);     
    public void print(Tnode node)
    if(node!=null)
         if(node.Con!=null) System.out.println("Con ->" + node.Con);
    show(node.Meas);
    if(node.Next!=null) print(node.Next);
         if(node.Child!=null) print(node.Child);                    
    void show( float [][]Meas)
    for(int i=0;i<6;i++)
    for(int j=0;j<5;j++)
    System.out.println("N.Meas["+i+"]"+"["+j+"]="+ Meas[i][j]);
    public float[][] sum(float[][]s, float [][]N)
    for(int i=0;i<6;i++)
         for(int j=0;j<5;j++)
    s[i][j] = s[i][j] + N[i][j];
    return s;                    
    public static void main(String []v)
    Tree T = new Tree();     
    String str[]={"Comp/Int", "Comp/Int/Inf", "Comp/Int/Inf/Wpaper"};
    float [][]s = new float[6][5];
    for(int i=0;i<6;i++)
    for(int j=0;j<5;j++)
         s[i][j] = (float)1.0;
    T.insert(str[0], s); // s contains all 1's
    s = T.sum(s,s);
    T.insert(str[1], s); // s contains all 2's
    s = T.sum(s,s);
    T.insert(str[2], s); //s contains all 4's
    T.print(); //displays tree
    }

    Thanks for reply. But i was stored the contents of float[][] array (s ,
    which was passed from main method) in three seperate nodes. In
    node creation process, i allocated memory for new float[][] array
    (Meas) in constructor. Why all the float[][] arrays are pointing to s? Yes you did allocate a new float[][] but you don't use it:Tnode(String cword, float [][]parameters) {
    Meas = new float[6][5];
    Meas = parameters;kind regards,
    Jos

  • Database creation problem on Windows XP

    Hello Readers
    I have installed ORACLE Database Engine on windows XP.
    I am facing problem in database creation.
    I have tryed wizard as well as mannual method.
    in wizard at 90% it gives an error "END-OF-FILE ON COMMUNICATION CHANNEL"
    although CD drive is in CR Rom drive.
    Please help me ....
    Rashid Masood Ashraf
    email: [email protected]

    After going to the properties as you suggested:
    Right now the Obtain an IP address automatically is checked
    I need to check the Use the following IP address:
    What should I enter for
    IP address:
    Subnet mask:
    Default gateway:
    Please help.
    Edited by: Nel Marcus on Dec 2, 2008 3:49 PM

  • Associative Array (Object) problems

    Here is the function i'm dealing with
    i'm reading in a delimited string and using indexed arrays to
    break them up and assign the keys and values to an associative
    array in a loop.
    i'm using variables in the loop and the array loads as
    expected in the loop
    but outside the loop, the only key is the variable name and
    the value is undefined
    this is true using dot or array notation, as well as literal
    strings for the keys
    any help is appreciated
    watchSuspendData = function (id, oldval, newval):String {
    //the incoming suspendData string is delimited by the
    semicolon;
    //newval is: firstValue=Yes;captivateKey=1
    var listSuspendData:Array = newval.split(";"); // convert it
    to a list of key/value pairs
    if (listSuspendData.length > 0){
    //line 123: listSuspendData.length is: 2
    for (i=0; i < listSuspendData.length; i++){ //for each
    key/value pair
    var keyValArray:Array = new Array();
    var myNameValue:String = listSuspendData
    //line 127: listSuspendData is: firstValue=Yes
    keyValArray = myNameValue.split("="); // split 'em on the
    equal sign
    var myKey:String = keyValArray[0];
    var myVal:String = keyValArray[1];
    //keyValArray[0] is: firstValue
    //keyValArray[1] is: Yes
    // store the key and the value in associative array
    suspendDataArray.myKey = myVal;
    trace("line 134: suspendDataArray is: " +
    suspendDataArray.myKey);
    // trace is line 134: suspendDataArray is: Yes on the first
    pass and 1 on the second
    //the below loop always returns one array key: myKey and the
    value as undefined
    for(x in suspendDataArray){
    trace("x is: " + x); //x is: myKey
    trace("the val is: " + suspendDataArray.x); //the val is:
    undefined
    } //end for
    return newval;

    on lines 12-13 i assign the key=value pair to string
    variables
    then on lines 17-18 i assign those values to the associative
    array using dot notation
    the trace seems to work there
    the problem is that when the procedure exits the for loop,
    the associative array only has one key (myKey) and no value
    (undefined)
    all the documentation i've read shows using these types of
    arrays with either non-quoted property names like:
    myAssocArray.myKey = "somevalue";
    or
    myAssocArray[myKey] = "somevalue";
    i tried assigning the key/value pairs directly from the
    indexed arrays, but the result was always undefined
    like this:
    suspendDataArray.keyValArray[0] = keyValArray[1]
    or
    suspendDataArray[keyValArray[0]] = keyValArray[1]
    i even tried building a string in the loop and trying to
    assign all the pairs at once using the curly brace
    this is pretty wierd behavior for actionscript or i'm missing
    something basic here
    thanks for looking

  • Remittance challan creation problem in Cross company code scenario.

    I made to Advance  payment to Cross comany code while posting time we deduct the TDS amount. at the time remiottance challan creation  i got bellow error.please help to me
    No unpaid tax lines exist for the given selection criteria.
    Message no. 8I702
    Diagnosis
    The corresponding withholding tax line  &1& is not present in WITH_ITEM table.
    System Response
    For withholding tax recovered from the vendor, tax line is present in table BSIS, but the corresponding entry is missing in table WITH_ITEM , which is necessary for challan updation. Check the entries.
    Procedure
    check entries in table WITH_ITEM for the open tax items chosen for clearing.
    Edited by: TEEGALA SATISH on Jun 15, 2010 5:43 PM

    Hi ...Actually i am getting same problem in challan creation.. Did you get any solution? ...

  • Process order creation problem

    I am creating a process order . while creating the process order system is throwing error as Auto batch numbering not set up for material type XXXX in plant xxxx . System is not allowing to create process order.
    How to resolve the issue.

    Check in CORW   and switch off batch creation  to isolate the problem if needed.   Also see whether you have any batch managed compoents   for which you have set master data for automatic batch determination.
    There is no setting for material types and plant for batch.  May be the error message is not correct.  What is the message number?

Maybe you are looking for

  • Additional charges?

    Hi, Last September I have cancelled my contract and paid cancellation fee. In the last two days mone has been taken from my account and it appears as: LNK BT PHONE, BRIG CD 7315 09JAN14ATM OWNER FEE 1.45   11.45£ LNK BT PHONE, BRIG CD 7315 10JAN14ATM

  • Where do I put the .jar file for the database connection?

    I am trying to connect to an Oracle 11g database. I see under the coldfusion settings summary that the java version is 1.7.0_55. So I downloaded the ojdbc7.jar file from Abode.com. Now the question is where do I put it so that coldfusion can access i

  • Fonts in creative cloud

    this is more of a feature request i suppose. but i love typekit in the adobe CC desktop app, however, it displays all your fonts, in the same font, so i cannot see what they look like. which is, annoying. so i was wondering if the functionality could

  • Q 10 became extremely slow in responding after update to 10.2.1.537 - battery draining very fast since, too

    Hi, my Q10 now got very slow after the  update to 10.2.1.537  It takes ages for switching from e.g. text to E-Mail Inboxes, from Hub to oriority Hub view or just to opening an email or an app.  Also, it s draining the batterry very fast. Down to 20%

  • Deltas problem(deltas set till 31.12.2007 only)

    Hi we have a data source called 0HR_PY_PP_1 which is feeding data to a ODS called 0PY_PP_C1.Currently deltas are running through process chains..But i have observed to day that deltas are set throuh selections( 0TRANSDATE=20040101-20071231;).I don't