why it highlights new Integer(value), new Integer(newValue)); as an error -
-
import java.beans.*;
-
import java.io.Serializable;
-
-
i
-
-
abstract class Constrained implements Serializable {
-
-
protected PropertyChangeSupport chg = new PropertyChangeSupport(this);
-
protected VetoableChangeSupport veto = new VetoableChangeSupport(this);
-
-
public void addPropertyChangeListener(PropertyChangeListener pcl) {
-
chg.addPropertyChangeListener(pcl);
-
}
-
-
public void removePropertyChangeListener(PropertyChangeListener pcl) {
-
chg.addPropertyChangeListener(pcl);
-
}
-
-
public synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
-
veto.addVetoableChangeListener(listener);
-
}
-
public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
-
veto.removeVetoableChangeListener(listener);
-
}
-
-
-
-
class BoundedProperty<T> {
-
private String name;
-
private T value;
-
-
public BoundedProperty(String name) {
-
this.name = name;
-
}
-
-
public T getValue() { return value; }
-
-
public void setValue(T newValue) throws PropertyVetoException {
-
try {
-
-
veto.fireVetoableChange(
-
"value", new Integer(value), new Integer(newValue));
-
value = newValue;
-
-
} catch (PropertyVetoException e) {
-
throw e;
-
//System.out.println(e.getMessage());
-
}
-
}
-
}
-
-
public static void main(String[] args) throws PropertyVetoException{
-
BoundedProperty bp=new BoundedProperty("allaa");
-
bp.setValue(10);
-
-
-
}
-
}
-
-
15 1927
This is just a guess, but perhaps it is looking for the integer data type rather than the Integer object. Try using - veto.fireVetoableCharge("value", value, newvalue);
instead of - veto.fireVetoableCharge("value", new Integer(value), new Integer(newvalue));
This is just a guess, but perhaps it is looking for the integer data type rather than the Integer object. Try using - veto.fireVetoableCharge("value", value, newvalue);
instead of - veto.fireVetoableCharge("value", new Integer(value), new Integer(newvalue));
It wouldn't be that because 1.5 unboxes the wrapper types where neccessary (autoboxing).
You are passing objects of type T to the constructor of Integer and yet T may not be a compatible argument. The Integer constructor takes either a String or an int. Now T could be a String but the compiler doesn't know that. For that to work T has to have been specified to be a either a tpye that extends from String or a type that can be auto unboxed to int.
but what shd i change in code to make it work
but what shd i change in code to make it work
It depends on where that code is coming from and what you want to do with it. You could try to call toString on the objects being passed to the Integer constructor to make them Strings
-
package zad12;
-
-
import java.beans.*;
-
import java.io.Serializable;
-
-
-
abstract class Constrained implements Serializable {
-
-
protected PropertyChangeSupport chg = new PropertyChangeSupport(this);
-
protected VetoableChangeSupport veto = new VetoableChangeSupport(this);
-
-
public void addPropertyChangeListener(PropertyChangeListener pcl) {
-
chg.addPropertyChangeListener(pcl);
-
}
-
-
public void removePropertyChangeListener(PropertyChangeListener pcl) {
-
chg.addPropertyChangeListener(pcl);
-
}
-
-
public synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
-
veto.addVetoableChangeListener(listener);
-
}
-
public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
-
veto.removeVetoableChangeListener(listener);
-
}
-
-
// Opis właściwości ograniczanej
-
-
class BoundedProperty<T> {
-
private String name;
-
private T value;
-
-
public BoundedProperty(String name) {
-
this.name = name;
-
}
-
-
public T getValue() { return value; }
-
-
public void setValue(T newValue) throws PropertyVetoException {
-
T old = value;
-
veto.fireVetoableChange( "value", old, value );
-
-
value = newValue;
-
chg.firePropertyChange(name, old, value);
-
}
-
}
-
-
public static void main(String[] args) throws PropertyVetoException{
-
-
BoundedProperty bp=new BoundedProperty("ala");
-
-
}
-
}
-
-
-
now it highlights new BoundedProperty("ala"); as an error
i need to write a javabean with constrained properties
-
package zad12;
-
-
import java.beans.*;
-
import java.io.Serializable;
-
-
-
abstract class Constrained implements Serializable {
-
-
protected PropertyChangeSupport chg = new PropertyChangeSupport(this);
-
protected VetoableChangeSupport veto = new VetoableChangeSupport(this);
-
-
public void addPropertyChangeListener(PropertyChangeListener pcl) {
-
chg.addPropertyChangeListener(pcl);
-
}
-
-
public void removePropertyChangeListener(PropertyChangeListener pcl) {
-
chg.addPropertyChangeListener(pcl);
-
}
-
-
public synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
-
veto.addVetoableChangeListener(listener);
-
}
-
public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
-
veto.removeVetoableChangeListener(listener);
-
}
-
-
// Opis właściwości ograniczanej
-
-
class BoundedProperty<T> {
-
private String name;
-
private T value;
-
-
public BoundedProperty(String name) {
-
this.name = name;
-
}
-
-
public T getValue() { return value; }
-
-
public void setValue(T newValue) throws PropertyVetoException {
-
T old = value;
-
veto.fireVetoableChange( "value", old, value );
-
-
value = newValue;
-
chg.firePropertyChange(name, old, value);
-
}
-
}
-
-
public static void main(String[] args) throws PropertyVetoException{
-
-
BoundedProperty bp=new BoundedProperty("ala");
-
-
}
-
}
-
-
-
now it highlights new BoundedProperty("ala"); as an error
i need to write a javabean with constrained properties
You have to check what error it's reporting and try to make sense out of it we can't tell because we don't have all your code.
What error did you get?
the error i get is
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type Constrained is accessible. Must qualify the allocation with an enclosing instance of type Constrained (e.g. x.new A() where x is an instance of Constrained).
at zad12.Constrained.main(Constrained.java)
the error i get is
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type Constrained is accessible. Must qualify the allocation with an enclosing instance of type Constrained (e.g. x.new A() where x is an instance of Constrained).
at zad12.Constrained.main(Constrained.java)
Which line is reported for that error?
it didnt say what line i copied u the whole error it returns
it didnt say what line i copied u the whole error it returns
Why did you make the Constrained class abstract?
i asked myself the same question cos this code is a piece of code i took from my lectures i changed it from abstract
i asked myself the same question cos this code is a piece of code i took from my lectures i changed it from abstract
Is it working now?
What were the lectures about?
no it's not working now it highlights BoundedProperty<T> bp=new BoundedProperty<T>(s); as an error - package zad12;
-
-
import java.beans.*;
-
import java.io.Serializable;
-
-
-
class Constrained implements Serializable {
-
-
protected PropertyChangeSupport chg = new PropertyChangeSupport(this);
-
protected VetoableChangeSupport veto = new VetoableChangeSupport(this);
-
-
private void addPropertyChangeListener(PropertyChangeListener pcl) {
-
chg.addPropertyChangeListener(pcl);
-
}
-
-
private void removePropertyChangeListener(PropertyChangeListener pcl) {
-
chg.addPropertyChangeListener(pcl);
-
}
-
-
private synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
-
veto.addVetoableChangeListener(listener);
-
}
-
private synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
-
veto.removeVetoableChangeListener(listener);
-
}
-
-
-
-
class BoundedProperty<T> {
-
private String name;
-
private T value;
-
-
public BoundedProperty(String name) {
-
this.name = name;
-
}
-
-
public T getValue() { return value; }
-
-
public void setValue(T newValue) throws PropertyVetoException {
-
T old = value;
-
veto.fireVetoableChange( "value", old, value );
-
-
value = newValue;
-
chg.firePropertyChange(name, old, value);
-
}
-
}
-
-
public static void main(String[] args) throws PropertyVetoException{
-
String s="ala";
-
BoundedProperty<T> bp=new BoundedProperty<T>(s);
-
-
}
-
}
-
-
-
the lecture was about generics
no it's not working now it highlights BoundedProperty<T> bp=new BoundedProperty<T>(s); as an error - package zad12;
-
-
import java.beans.*;
-
import java.io.Serializable;
-
-
-
class Constrained implements Serializable {
-
-
protected PropertyChangeSupport chg = new PropertyChangeSupport(this);
-
protected VetoableChangeSupport veto = new VetoableChangeSupport(this);
-
-
private void addPropertyChangeListener(PropertyChangeListener pcl) {
-
chg.addPropertyChangeListener(pcl);
-
}
-
-
private void removePropertyChangeListener(PropertyChangeListener pcl) {
-
chg.addPropertyChangeListener(pcl);
-
}
-
-
private synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
-
veto.addVetoableChangeListener(listener);
-
}
-
private synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
-
veto.removeVetoableChangeListener(listener);
-
}
-
-
-
-
class BoundedProperty<T> {
-
private String name;
-
private T value;
-
-
public BoundedProperty(String name) {
-
this.name = name;
-
}
-
-
public T getValue() { return value; }
-
-
public void setValue(T newValue) throws PropertyVetoException {
-
T old = value;
-
veto.fireVetoableChange( "value", old, value );
-
-
value = newValue;
-
chg.firePropertyChange(name, old, value);
-
}
-
}
-
-
public static void main(String[] args) throws PropertyVetoException{
-
String s="ala";
-
BoundedProperty<T> bp=new BoundedProperty<T>(s);
-
-
}
-
}
-
-
-
Whenever it highlights an error try to get the error message first and try to understand before posting. What did it say was the error?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tushar |
last post by:
Hello,
I am working on a client server application involving TOMCAT as Web
server, MySQl as the DB and combination of JSP, Servlet, and JavaBeans
to access and write Data back.
There is...
|
by: f |
last post by:
I am writing a java code generation tool. The tool will take a java
class description written in xml and translate it to java code using
xslt. I am looking for samples of xml files that describe...
|
by: donnet |
last post by:
To those familiar with Java beans, question on how to do with ASP.NET:
I come from J2EE and starting to learn ASP.NET and C#.
I want to find a way to display a web form filled with data taken...
|
by: Stephen H. |
last post by:
Hi,
I have an existing web application with java beans that I wanne migrate to
ASP.NET using C#.
The existing web application has some jsp files that use java beans as
follows:
....
<%@...
|
by: Christian Wilhelm |
last post by:
Hi!
I'm trying to call a Java WebService out of a .net Client. There are two
Methods, one Method requires one Parameter of type Parameter, the other
Method requires one Parameter of type...
|
by: robert maas, see http://tinyurl.com/uh3t |
last post by:
I'm working on examples of programming in several languages, all
(except PHP) running under CGI so that I can show both the source
files and the actually running of the examples online. The first...
|
by: kavyak |
last post by:
This is not a mere error. because,whatever input i give from jsp, its getting updated in mysql but the page is showing some internal error.The error looks like this.Plz tell me if someone knows the...
|
by: jeffbroodwar |
last post by:
Hi Guys,
I just want to hear your understanding of Java Beans. I mean it doesn't just expose properties (for parameters) right? Java beans must be able to do what variables can't. i need...
|
by: Laxmikumar |
last post by:
Iam new to web services, Iam using net beans-5.5.1 IDE
whlie deploying the web service application the following error is occured.
can anyone help me..??? please.
init:
deps-module-jar:...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |