0

I kinda need help. Im trying to create an Hash Table using an array of Elements but I keep getting this error, can someone help me? (This array really needs to be an array of Elements).

This is my Element class

public class Element<T>{
  T element;
  boolean state;

  public Element(){
    element=null;
    state=false;
  }


  public Element(T elemento){
    element=elemento;
    state=false;
  }

this is my HashTable class

public class HashTable<T>{
  int maxSize;
  int size;
  float factorCarga;
  private Element<T>[] hash;

  public HashTable(int x){
    this.maxSize=x;
    this.size=0;
    hash =(Element<T>[]) new Object[x];
    factorCarga=0;
  }

This is my Test class

public class Test{


  public static void main(String args[]){
  HashTable<Element<Integer>> hash = new HashTable<Element<Integer>>(35);
  }

}

when i try to run the program i always get this error:

  • java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to[LElement;
    at HashTable.(HashTable.java:11) at Teste.main(Teste.java:5) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:267)

0 Answers0