Меню

Cannot instantiate the type ошибка

When I try to run this code:

import java.io.*;
import java.util.*;

public class TwoColor
{
    public static void main(String[] args) 
    {
         Queue<Edge> theQueue = new Queue<Edge>();
    }

    public class Edge
    {
        //u and v are the vertices that make up this edge.
        private int u;
        private int v;

        //Constructor method
        public Edge(int newu, int newv)
        {
            u = newu;
            v = newv;
        }
    }
}

I get this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Cannot instantiate the type Queue
    at TwoColor.main(TwoColor.java:8)

I don’t understand why I can’t instantiate the class… It seems right to me…

asked Apr 28, 2011 at 4:40

StickFigs's user avatar

1

java.util.Queue is an interface so you cannot instantiate it directly. You can instantiate a concrete subclass, such as LinkedList:

Queue<T> q = new LinkedList<T>;

answered Apr 28, 2011 at 4:44

Cameron Skinner's user avatar

Cameron SkinnerCameron Skinner

50.3k2 gold badges65 silver badges83 bronze badges

0

Queue is an Interface so you can not initiate it directly. Initiate it by one of its implementing classes.

From the docs all known implementing classes:

  • AbstractQueue
  • ArrayBlockingQueue
  • ArrayDeque
  • ConcurrentLinkedQueue
  • DelayQueue
  • LinkedBlockingDeque
  • LinkedBlockingQueue
  • LinkedList
  • PriorityBlockingQueue
  • PriorityQueue
  • SynchronousQueue

You can use any of above based on your requirement to initiate a Queue object.

answered Apr 28, 2011 at 4:46

Harry Joy's user avatar

Harry JoyHarry Joy

58.1k30 gold badges159 silver badges207 bronze badges

Queue is an Interface not a class.

answered Apr 28, 2011 at 4:44

Andrew Lazarus's user avatar

Andrew LazarusAndrew Lazarus

17.4k2 gold badges33 silver badges51 bronze badges

You are trying to instantiate an interface, you need to give the concrete class that you want to use i.e. Queue<Edge> theQueue = new LinkedBlockingQueue<Edge>();.

answered Apr 28, 2011 at 4:47

Jugal Shah's user avatar

Jugal ShahJugal Shah

3,5511 gold badge23 silver badges35 bronze badges

You can use

Queue thequeue = new linkedlist();

or

Queue thequeue = new Priorityqueue();

Reason: Queue is an interface. So you can instantiate only its concrete subclass.

Robin Ellerkmann's user avatar

answered Oct 21, 2014 at 12:08

Amit Anand's user avatar

I had the very same issue, not being able to instantiate the type of a class which I was absolutely sure was not abstract. Turns out I was implementing an abstract class from Java.util instead of implementing my own class.

So if the previous answers did not help you, please check that you import the class you actually wanted to import, and not something else with the same name that you IDE might have hinted you.

For example, if you were trying to instantiate the class Queue from the package myCollections which you coded yourself :

import java.util.*; // replace this line
import myCollections.Queue; // by this line

     Queue<Edge> theQueue = new Queue<Edge>();

answered Dec 23, 2020 at 15:33

Badda's user avatar

BaddaBadda

1,2992 gold badges13 silver badges36 bronze badges

Fix Java Cannot Instantiate the Type Error

Today, we will learn how to fix the error cannot instantiate the type error in Java.

This type of error occurs when you try to make an instance of an abstract class. Let’s learn a bit about abstract classes in Java.

Fix cannot instantiate the type Error in Java

We usually use an abstract class when we need to provide some common functionalities among all its components. You’ll be able to implement your class partially.

You will be able to generate functionalities that all subclasses will be able to override or implement. However, you cannot instantiate the abstract class.

Look at the following code:

abstract class Account 
{ // abstract class Cannot Be initiated...
  private int amount;
  Account() 
  {
    //constructor............
  }
  public void withDraw(int amount) 
  {

    this.amount = this.amount - amount;
  }
}

The above abstract class Account cannot be instantiated. Meaning you cannot write the following code.

Account acc = new Account(); // Abstract Cannot Intialized......

So, what’s the solution? You can create a concrete/child class of this abstract class and make an instance of that.

For instance, there are so many types of accounts. They could be savings, business, debit, and much more.

However, all of them are actual accounts, and that is something that they have in common. That’s why we use abstract methods and classes.

Take a look at the following code.

class BusinessAccount extends Account 
{
  private int Bonus;
  public void AwardBonus(int amount) 
  {
    this.Bonus = Bonus + amount;
  }
}

BusinessAccount class is a concrete and child class of the abstract Account class. You can make an instance of this class and get your work done.

BusinessAccount bb = new BusinessAccount(); 
    //Bussiness Account Can Be intiated Because there is concreate defination..........

So, the conclusion is that you cannot instantiate the abstract class; instead, you can create its child class and instantiate it for the same functionality.

The following is a complete code that you can run on your computer.

abstract class Account 
{ // abstract class Cannot Be intiated...
  private int amount;
  Account() 
  {
    //constructor............
  }
  public void withDraw(int amount) 
  {

    this.amount = this.amount - amount;
  }
}
class BusinessAccount extends Account 
{
  private int Bonus;
  public void AwardBonus(int amount) 
  {
    this.Bonus = Bonus + amount;
  }
}
public class Main {
  public static void main(String[] args) 
  {
    //Account acc = new Account(); // Abstract Cannot Intialized......
    BusinessAccount bb = new BusinessAccount(); 
    //Bussiness Account Can Be intiated Because there is concreate defination..........
  }
}

To learn more about Abstract Class, click here.

Contents

  • 1 What is java.lang.InstantiationException?
  • 2 When the Type is Non-instantiable
    • 2.1 When you attempt to instantiate abstract class
    • 2.2 When you attempt to instantiate interface type
  • 3 When the Type doesn’t have a Nullary Constructor
    • 3.1 How to fix java.lang.InstantiationException caused by nullary constructor

A java.lang.InstantiationException is thrown when JVM cannot instantiate a type at runtime.

To make this definition more elaborate. A java.lang.InstantiationException can be thrown when you try to create an instance of a non-instantiable type or a legit concrete class without having nullary constructor, dynamically during runtime using Class.newInstance() method.

To be more specific, you get java.lang.InstantiationException under below circumstances.

  • Passing the fully qualified name of abstract class name or interface to Class.forName as a String while creating instance of Class
  • Creating Class instance using abstract class or interface or array or primitive type by using their “.class” attribute
  • Passing the name of Interface to Class.forName

In Java, you can create an instance of a class at runtime using Class type, provided that the given class is a concrete class.

Creating an instance using Class.newInstance of a known class

Class<Animal> c = String.class;
String str = c.newInstance();

Creating an instance using Class.newInstance of an unknown class loaded with Class.forName

Class c = Class.forName("java.lang.String");
String str = (String) c.newInstance();

These are the two ways of instantiating and we generally use either of one. But we may get java.lang.InstantiationException when we are instantiating in this way. Java enforce you to declare or handle java.lang.InstantiationException when you are using Class.newInstance() method to create instances. So, let’s discuss why do we get java.lang.InstantiationException with this style of coding.

When the Type is Non-instantiable

There are few types which we cannot instantiate. We cannot instantiate an abstract class, an interface, an Array or any Java primitive type using new keyword. Java compiler will throw error immediately if we are attempting that. However, we can also write code to create an instance of type using Class.newInstance. While loading the class we provide the class name withing double quotes to Class.forName() method or use the “.class” attribute the type which returns a Class object as shown above.

In this approach, there is a possibility that you can provide a class name which can’t be instantiated, and Java Compiler ignores them during compilation time. However, at runtime when JVM tries create an instance of that type, it realizes that it can’t be instantiated and throws java.lang.InstantiationException.

So, you need to go back and check if you are creating in this style, you are making sure that you are using concrete Java class only.

Below are few examples, in which java.lang.InstantiationException is thrown.

When you attempt to instantiate abstract class

package com.techstackjournal;

import java.lang.reflect.InvocationTargetException;

abstract class Alpha {

}

public class InitializationExceptionDemo {

	public static void main(String[] args)
			throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
			NoSuchMethodException, SecurityException, ClassNotFoundException {
		Class c = Class.forName("com.techstackjournal.Alpha");

 // Can also be written as, Class c = Alpha.class;
		Alpha a = (Alpha) c.newInstance();
	}

}
Exception in thread "main" java.lang.InstantiationException
	at java.base/jdk.internal.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
	at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)
	at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:350)
	at java.base/java.lang.Class.newInstance(Class.java:645)
	at com.techstackjournal.InitializationExceptionDemo.main(InitializationExceptionDemo.java:15)

When you attempt to instantiate interface type

package com.techstackjournal;

import java.lang.reflect.InvocationTargetException;

interface Alpha {

}

public class InitializationExceptionDemo {

	public static void main(String[] args)
			throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
			NoSuchMethodException, SecurityException, ClassNotFoundException {
		Class c = Class.forName("com.techstackjournal.Alpha");

 // Can also be written as, Class c = Alpha.class;
		Alpha a = (Alpha) c.newInstance();
	}

}
Exception in thread "main" java.lang.InstantiationException: com.techstackjournal.Alpha
	at java.base/java.lang.Class.newInstance(Class.java:639)
	at com.techstackjournal.InitializationExceptionDemo.main(InitializationExceptionDemo.java:16)
Caused by: java.lang.NoSuchMethodException: com.techstackjournal.Alpha.<init>()
	at java.base/java.lang.Class.getConstructor0(Class.java:3508)
	at java.base/java.lang.Class.newInstance(Class.java:626)
	... 1 more

When the Type doesn’t have a Nullary Constructor

If the class that you are instantiating doesn’t contain a nullary constructor and you are attempting to create an instance of that class using Class.forName method, java.lang.InstantiationException will be thrown.

A nullary constructor is a constructor without any arguments.

So, when we try to instantiate a class using Class.newInstance() as below, it tries to create an instance using empty constructor (or nullary constructor). Since our code doesn’t have a nullary constructor JVM throws java.lang.InstantiationException. Look below to this code snippet on how we can resolve this kind of issues.

package com.techstackjournal;

import java.lang.reflect.InvocationTargetException;

class Alpha {

	public Alpha(String arg1) {

	}

}

public class InitializationExceptionDemo {

	public static void main(String[] args)
			throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
			NoSuchMethodException, SecurityException, ClassNotFoundException {
		Class c = Class.forName("com.techstackjournal.Alpha");

 // Can also be written as, Class c = Alpha.class;
		Alpha a = (Alpha) c.newInstance();

	}

}
Exception in thread "main" java.lang.InstantiationException: com.techstackjournal.Alpha
	at java.base/java.lang.Class.newInstance(Class.java:639)
	at com.techstackjournal.InitializationExceptionDemo.main(InitializationExceptionDemo.java:20)
Caused by: java.lang.NoSuchMethodException: com.techstackjournal.Alpha.<init>()
	at java.base/java.lang.Class.getConstructor0(Class.java:3508)
	at java.base/java.lang.Class.newInstance(Class.java:626)
	... 1 more

How to fix java.lang.InstantiationException caused by nullary constructor

There are 2 solutions to fix this issue.

  1. First obvious solution is to add a constructor to the class without arguments. But sometimes it is possible that the class being used is within a jar file is not accessible to make changes to it, where our 2nd solution comes into the picture.
  2. If the above solution is not possible, may be due to the fact that the class is within a jar file, you can use the existing constructor explicitly while creating the instance using Class.getDeclaredConstructor(Class).newInstance(arguments)

Fixing java.lang.InstantiationException by Adding Nullary Constructor

package com.techstackjournal;

import java.lang.reflect.InvocationTargetException;

class Alpha {

	public Alpha(String arg1) {
		// do something
	}

}

public class InitializationExceptionDemo {

	public static void main(String[] args)
			throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
			NoSuchMethodException, SecurityException, ClassNotFoundException {
		Class c = Alpha.class;
		Alpha a = (Alpha) c.newInstance();

	}

}

You may have the code as given in the above code snippet which is causing java.lang.InstantiationException. I can fix that issue just by adding a nullary method or no-argument constructor as below.

package com.techstackjournal;

import java.lang.reflect.InvocationTargetException;

class Alpha {
	
	public Alpha() {
		System.out.println("Success");
	}

	public Alpha(String arg1) {
		// do something
	}

}

public class InitializationExceptionDemo {

	public static void main(String[] args)
			throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
			NoSuchMethodException, SecurityException, ClassNotFoundException {
		Class c = Alpha.class;
		Alpha a = (Alpha) c.newInstance();

	}

}

Fixing java.lang.InstantiationException by Calling Specific Constructor

As mentioned above, we can call a specific constructor while creating instance using newInstance method with the help of Class.getDeclaredConstructor method. The Class.getDeclaredConstructor method takes one or more arguments of type Class, which tells the JVM to look for constructors with that signature. For example, if I pass List.class and String.class as arguments, we are telling the JVM to look for a constructor that has its first argument as List and second argument as String. Then JVM will make use of that specific constructor to create the instance instead of searching for the default nullary constructor.

package com.techstackjournal;

import java.lang.reflect.InvocationTargetException;

class Alpha {

	public Alpha(String arg1) {
		System.out.println(arg1);
	}

}

public class InitializationExceptionDemo {

	public static void main(String[] args)
			throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
			NoSuchMethodException, SecurityException, ClassNotFoundException {
		Class c = Alpha.class;
		Alpha a = (Alpha) c.getDeclaredConstructor(String.class).newInstance("test");

	}

}

The InstantiationException is a runtime exception in Java that occurs when an application attempts to create an instance of a class using the Class.newInstance() method, but the specified class object cannot be instantiated.

Since the InstantiationException is an unchecked exception, it does not need to be declared in the throws clause of a method or constructor.

What Causes InstantiationException

The InstantiationException is thrown when the JVM cannot instantiate a type at runtime. This can happen for a variety of reasons, including the following:

  • The class object represents an abstract class, interface, array class, primitive or void.
  • The class has no nullary constructor. Such a constructor is required when a parameterized constructor is defined for the class.

InstantiationException Example

Here is an example of an InstantiationException thrown when the Class.newInstance() method is used to create an instance of a boolean:

public class InstantiationExceptionExample {
    public static void main(String[] args) {
        try {
            Class<Boolean> clazz = boolean.class; 
            clazz.newInstance();
        } catch (InstantiationException ie) {
            ie.printStackTrace();
        } catch (IllegalAccessException iae) {
            iae.printStackTrace();
        }
    }
}

Since boolean is a primitive data type, a new instance of it cannot be created using the Class.newInstance() method, which can only construct objects for concrete classes. Running the above code throws the following exception:

java.lang.InstantiationException: boolean
    at java.base/java.lang.Class.newInstance(Class.java:598)
    at InstantiationExceptionExample.main(InstantiationExceptionExample.java:5)
Caused by: java.lang.NoSuchMethodException: boolean.<init>()
    at java.base/java.lang.Class.getConstructor0(Class.java:3427)
    at java.base/java.lang.Class.newInstance(Class.java:585)
    ... 1 more

How to Resolve InstantiationException

To avoid the InstantiationException, it should be ensured that the instance of the class that is attempted to be created at runtime using Class.newInstance() is a concrete class and not an abstract class, interface, array class, primitive or void.

If it is a concrete class, it should be ensured that the class has a nullary constructor (in case it contains a parameterized constructor). If this is not possible, the Constructor objects can be reflectively looked up and used to construct a new instance of the class using Constructor.newInstance(args) with arguments that pass the actual constructor argument values.

Track, Analyze and Manage Errors With Rollbar

Rollbar in action

Managing errors and exceptions in your code is challenging. It can make deploying production code an unnerving experience. Being able to track, analyze, and manage errors in real-time can help you to proceed with more confidence. Rollbar automates error monitoring and triaging, making fixing Java errors easier than ever.

Sign Up Today!

Я пытаюсь создать свою версию HashMap с помощью некоторых служебных методов.

Foo.java:

import java.util.HashMap;

public class Foo<String, Parameter> extends HashMap<String, Parameter> {

    public Foo() {
      super();
    }

    public Parameter Add(String key, MyType type) {
        return put(key, new Parameter(type)); // -> This line causes compilation error
    }
  }

Следующая строка:

new Parameter(type);

производит Cannot instantiate the type Foo.

Я проверил Parameter класс, и это не абстрактный класс / интерфейс, почему я получаю эту ошибку?

РЕДАКТИРОВАТЬ
Изменение объявления класса следующим образом решило проблему:

public class Foo extends HashMap<String, Parameter> {

2 ответы

Это не абстрактный класс — это параметр типа на данный момент, как и String! Ваш класс является универсальным, с двумя параметрами типа. Я полагаю, вы имели в виду:

public class Foo extends HashMap<String, Parameter> {

Теперь это неуниверсальный класс.

Создан 06 сен.

Объявление вашего класса должно быть

public class Foo extends HashMap<String, Parameter> {

Но почти всегда продлевать HashMap, Вам следует использование a Map вместо этого внутри вашего класса. Кроме того, в Java методы всегда должны начинаться со строчной буквы.

Создан 06 сен.

Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками

java
android

or задайте свой вопрос.

Categories

  • 385.5K All Categories
  • 5.1K Data
  • 2.5K Big Data Appliance
  • 2.5K Data Science
  • 453.4K Databases
  • 223.2K General Database Discussions
  • 3.8K Java and JavaScript in the Database
  • 47 Multilingual Engine
  • 606 MySQL Community Space
  • 486 NoSQL Database
  • 7.9K Oracle Database Express Edition (XE)
  • 3.2K ORDS, SODA & JSON in the Database
  • 585 SQLcl
  • 4K SQL Developer Data Modeler
  • 188K SQL & PL/SQL
  • 21.5K SQL Developer
  • 46 Data Integration
  • 46 GoldenGate
  • 298.4K Development
  • 4 Application Development
  • 20 Developer Projects
  • 166 Programming Languages
  • 295K Development Tools
  • 150 DevOps
  • 3.1K QA/Testing
  • 646.7K Java
  • 37 Java Learning Subscription
  • 37.1K Database Connectivity
  • 201 Java Community Process
  • 108 Java 25
  • 8.1K Embedded Technologies
  • 22.2K Java APIs
  • 138.3K Java Development Tools
  • 165.4K Java EE (Java Enterprise Edition)
  • 22 Java Essentials
  • 176 Java 8 Questions
  • 86K Java Programming
  • 82 Java Puzzle Ball
  • 65.1K New To Java
  • 1.7K Training / Learning / Certification
  • 13.8K Java HotSpot Virtual Machine
  • 94.3K Java SE
  • 13.8K Java Security
  • 208 Java User Groups
  • 25 JavaScript — Nashorn
  • Programs
  • 667 LiveLabs
  • 41 Workshops
  • 10.3K Software
  • 6.7K Berkeley DB Family
  • 3.6K JHeadstart
  • 6K Other Languages
  • 2.3K Chinese
  • 207 Deutsche Oracle Community
  • 1.1K Español
  • 1.9K Japanese
  • 474 Portuguese

807599

I have a class(arrayList) and an Interface(ListInterface) and I’m making a new class(Set)

I’m stuck on the constructor

	public class Set {

	private ListInterface data;   // The ADTList to hold the set elements. 
	
	/**
	 * Initializes an empty set.
	 */
	public Set() 
	{
		data = new ListInterface;
	}

this gives the error that it cannot instantiate the type ListInterface, and it doesn’t work without the parentheses either.

I dont know what to do, any help?

Comments

  • 3004


    3004


    Member Posts: 204,171 Green Ribbon

    You cannot instantiate interfaces or abstract classes. You have to provide a concrete implementation class.

  • 807599

    so I would have to write data = new arrayList?

    but then I would lose abstraction…

  • 3004


    3004


    Member Posts: 204,171 Green Ribbon

    ListInterface data = new ConcreteListInerfaceImplementation();

    And no, you don’t lose abstraction that way.

  • 807599

    now it just says
    ConcreteListInerfaceImplementation() cannot be resolved to a type.
    :(

  • 3004


    3004


    Member Posts: 204,171 Green Ribbon

    now it just says
    ConcreteListInerfaceImplementation() cannot be
    resolved to a type.
    :(

    Don’t just copy and paste. Read and try to understand. That was simply an example. You’d obviously have to provide the name of a real class the implements that interface.

    And don’t post the same question multiple times. It wastes people’s time.

  • 807599

    now it just says
    ConcreteListInerfaceImplementation() cannot be
    resolved to a type.
    :(

    Funniest thing I’ve heard all day. Cheered me up quite nicely.

    Now, you cannot instantiate interfaces. Take the interface List for example.

    if you use the code:

    List myList = new List();

    You’ll receive an error.

    Now look, in the API. There are quite a few classes that implement List.
    A few are: ArrayList, Vector, LinkedList

    So any class that implements List, you can use those legally.
    Example:

    List myList1 = new ArrayList();
    List myList2 = new Vector();

This discussion has been closed.

I have the following code

containerBuilder.RegisterModule(new QuartzAutofacFactoryModule());
containerBuilder.RegisterModule(new QuartzAutofacJobsModule(typeof(CalculatorJob).Assembly));

public class CalculatorJob : IJob
    {
        private readonly ICalculator calculator;

        public CalculatorJob(ICalculator calculator)
        {
            this.calculator = calculator;
        }

        public void Execute(IJobExecutionContext context)
        {
            calculator.PerformCalculator();
        }
    }

and I get following error

  - FirstChance Exception  -- Cannot instantiate type which has no empty constructor
Parameter name: CalculatorJob
System.ArgumentException: Cannot instantiate type which has no empty constructor
Parameter name: CalculatorJob
   at Quartz.Util.ObjectUtils.InstantiateType[T](Type type) in c:projectsquartznet-6fcn8srcQuartzUtilObjectUtils.cs:line 107
Exception thrown: 'Quartz.SchedulerException' in Quartz.dll
SchedulerTest1.Service.Program: FATAL 2017-12-11 12:21:26,442 [DefaultQuartzScheduler_QuartzSchedulerThread] SchedulerTest1.Service.Program           - FirstChance Exception  -- Problem instantiating class 'SchedulerTest1.Infrastracture.Jobs.CalculatorJob'
Quartz.SchedulerException: Problem instantiating class 'SchedulerTest1.Infrastracture.Jobs.CalculatorJob' ---> System.ArgumentException: Cannot instantiate type which has no empty constructor
Parameter name: CalculatorJob
   at Quartz.Util.ObjectUtils.InstantiateType[T](Type type) in c:projectsquartznet-6fcn8srcQuartzUtilObjectUtils.cs:line 107
   at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler) in c:projectsquartznet-6fcn8srcQuartzSimplSimpleJobFactory.cs:line 68
   --- End of inner exception stack trace ---
   at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler) in c:projectsquartznet-6fcn8srcQuartzSimplSimpleJobFactory.cs:line 76 [See nested exception: System.ArgumentException: Cannot instantiate type which has no empty constructor
Parameter name: CalculatorJob
   at Quartz.Util.ObjectUtils.InstantiateType[T](Type type) in c:projectsquartznet-6fcn8srcQuartzUtilObjectUtils.cs:line 107
   at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler) in c:projectsquartznet-6fcn8srcQuartzSimplSimpleJobFactory.cs:line 68]
Exception thrown: 'Quartz.SchedulerException' in Quartz.dll
SchedulerTest1.Service.Program: FATAL 2017-12-11 12:21:26,457 [DefaultQuartzScheduler_QuartzSchedulerThread] SchedulerTest1.Service.Program           - FirstChance Exception  -- Problem instantiating class 'SchedulerTest1.Infrastracture.Jobs.CalculatorJob'
Quartz.SchedulerException: Problem instantiating class 'SchedulerTest1.Infrastracture.Jobs.CalculatorJob' ---> System.ArgumentException: Cannot instantiate type which has no empty constructor
Parameter name: CalculatorJob
   at Quartz.Util.ObjectUtils.InstantiateType[T](Type type) in c:projectsquartznet-6fcn8srcQuartzUtilObjectUtils.cs:line 107
   at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler) in c:projectsquartznet-6fcn8srcQuartzSimplSimpleJobFactory.cs:line 68
   --- End of inner exception stack trace ---
   at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler) in c:projectsquartznet-6fcn8srcQuartzSimplSimpleJobFactory.cs:line 76
   at Quartz.Simpl.PropertySettingJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler) in c:projectsquartznet-6fcn8srcQuartzSimplPropertySettingJobFactory.cs:line 95
   at Quartz.Core.JobRunShell.Initialize(QuartzScheduler sched) in c:projectsquartznet-6fcn8srcQuartzCoreJobRunShell.cs:line 96 [See nested exception: System.ArgumentException: Cannot instantiate type which has no empty constructor
Parameter name: CalculatorJob
   at Quartz.Util.ObjectUtils.InstantiateType[T](Type type) in c:projectsquartznet-6fcn8srcQuartzUtilObjectUtils.cs:line 107
   at Quartz.Simpl.SimpleJobFactory.NewJob(TriggerFiredBundle bundle, IScheduler scheduler) in c:projectsquartznet-6fcn8srcQuartzSimplSimpleJobFactory.cs:line 68]

There is probably some data structure that I could be using that would be better than this, but nothing is coming to mind. But anyway, I’m getting this error: «Cannot instantiate the type Map<String,LinkedList<String>>» and I’m not sure why.

package main;
import java.util.LinkedList;
import java.util.Map;

public class Main {
	private Map<String, LinkedList<String>> a;
	private int MAX_SIZE;
	public void main(String[] args) {
		a=new Map<String, LinkedList<String>>();

...
...
bla bla bla

The abominatin of a data structure that I have created is being used to store a combination of both Strings and Doubles in a hash table that needs to be able to store the Doubles in order at each key along with an identifier for that value (each one has an identifier). For example, I might store «AX» and the value 1.42 at hash key «A» as «AX1.42» along with «2.999» and «MD6.705». The MD would need to be inserted before the AX, as it is a larger value.

———————Configuration: error maker — Win32 Debug———————Compiling…error maker.cppLinking…error maker.exe — 1 error(s), 0 warning(s)

Map is an interface, not a class. It describes how mappings behave, but is not itself an implementation of a mapping. It sounds like you might want a HashMap.

Yep. That’s what it was. Thanks!

———————Configuration: error maker — Win32 Debug———————Compiling…error maker.cppLinking…error maker.exe — 1 error(s), 0 warning(s)

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Canon 3010 ошибка e301
  • Canon 3010 ошибка e25