473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

new Integer gets highligthed as error by java beans in my code

oll3i
679 512MB
why it highlights new Integer(value), new Integer(newValue)); as an error


Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.beans.*;
  3. import java.io.Serializable;
  4.  
  5. i
  6.  
  7. abstract class Constrained implements Serializable {
  8.  
  9.       protected PropertyChangeSupport chg = new PropertyChangeSupport(this);
  10.       protected VetoableChangeSupport veto = new VetoableChangeSupport(this);
  11.  
  12.       public void addPropertyChangeListener(PropertyChangeListener pcl) {
  13.         chg.addPropertyChangeListener(pcl);
  14.       }
  15.  
  16.       public void removePropertyChangeListener(PropertyChangeListener pcl) {
  17.         chg.addPropertyChangeListener(pcl);
  18.       }
  19.  
  20.       public synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
  21.             veto.addVetoableChangeListener(listener);
  22.       }
  23.      public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
  24.             veto.removeVetoableChangeListener(listener);
  25.      }
  26.  
  27.  
  28.  
  29.       class BoundedProperty<T>  {
  30.         private String name;
  31.         private T value;
  32.  
  33.         public BoundedProperty(String name) {
  34.           this.name = name;
  35.         }
  36.  
  37.         public T getValue() { return value; }
  38.  
  39.         public void setValue(T newValue) throws PropertyVetoException {
  40.             try {
  41.  
  42.                 veto.fireVetoableChange(
  43.                     "value", new Integer(value), new Integer(newValue));
  44.                 value = newValue;
  45.  
  46.               } catch (PropertyVetoException e) {
  47.                 throw e;
  48.                 //System.out.println(e.getMessage()); 
  49.             }
  50.         }
  51.       }
  52.  
  53.       public static void main(String[] args) throws PropertyVetoException{
  54.           BoundedProperty bp=new BoundedProperty("allaa");
  55.           bp.setValue(10);
  56.  
  57.  
  58.           }
  59.     }
  60.  
  61.  
Mar 19 '07 #1
15 1927
Ganon11
3,652 Expert 2GB
This is just a guess, but perhaps it is looking for the integer data type rather than the Integer object. Try using

Expand|Select|Wrap|Line Numbers
  1. veto.fireVetoableCharge("value", value, newvalue);
instead of

Expand|Select|Wrap|Line Numbers
  1. veto.fireVetoableCharge("value", new Integer(value), new Integer(newvalue));
Mar 20 '07 #2
r035198x
13,262 8TB
This is just a guess, but perhaps it is looking for the integer data type rather than the Integer object. Try using

Expand|Select|Wrap|Line Numbers
  1. veto.fireVetoableCharge("value", value, newvalue);
instead of

Expand|Select|Wrap|Line Numbers
  1. 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.
Mar 20 '07 #3
oll3i
679 512MB
but what shd i change in code to make it work
Mar 20 '07 #4
r035198x
13,262 8TB
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
Mar 20 '07 #5
oll3i
679 512MB
Expand|Select|Wrap|Line Numbers
  1. package zad12;
  2.  
  3. import java.beans.*;
  4. import java.io.Serializable;
  5.  
  6.  
  7. abstract class Constrained implements Serializable {
  8.  
  9.       protected PropertyChangeSupport chg = new PropertyChangeSupport(this);
  10.       protected VetoableChangeSupport veto = new VetoableChangeSupport(this);
  11.  
  12.       public void addPropertyChangeListener(PropertyChangeListener pcl) {
  13.         chg.addPropertyChangeListener(pcl);
  14.       }
  15.  
  16.       public void removePropertyChangeListener(PropertyChangeListener pcl) {
  17.         chg.addPropertyChangeListener(pcl);
  18.       }
  19.  
  20.       public synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
  21.             veto.addVetoableChangeListener(listener);
  22.       }
  23.      public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
  24.             veto.removeVetoableChangeListener(listener);
  25.      }
  26.  
  27.       // Opis właściwości ograniczanej
  28.  
  29.       class BoundedProperty<T>  {
  30.         private String name;
  31.         private T value;
  32.  
  33.         public BoundedProperty(String name) {
  34.           this.name = name;
  35.         }
  36.  
  37.         public T getValue() { return value; }
  38.  
  39.         public void setValue(T newValue) throws PropertyVetoException {
  40.           T  old = value;
  41.           veto.fireVetoableChange( "value", old, value );
  42.  
  43.           value = newValue;
  44.           chg.firePropertyChange(name, old, value);
  45.         }
  46.       }
  47.  
  48.       public static void main(String[] args) throws PropertyVetoException{
  49.  
  50.           BoundedProperty bp=new BoundedProperty("ala");
  51.  
  52.           }
  53.     }
  54.  
  55.  
  56.  
now it highlights new BoundedProperty("ala"); as an error
i need to write a javabean with constrained properties
Mar 20 '07 #6
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. package zad12;
  2.  
  3. import java.beans.*;
  4. import java.io.Serializable;
  5.  
  6.  
  7. abstract class Constrained implements Serializable {
  8.  
  9.      protected PropertyChangeSupport chg = new PropertyChangeSupport(this);
  10.      protected VetoableChangeSupport veto = new VetoableChangeSupport(this);
  11.  
  12.      public void addPropertyChangeListener(PropertyChangeListener pcl) {
  13.      chg.addPropertyChangeListener(pcl);
  14.      }
  15.  
  16.      public void removePropertyChangeListener(PropertyChangeListener pcl) {
  17.      chg.addPropertyChangeListener(pcl);
  18.      }
  19.  
  20.      public synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
  21.          veto.addVetoableChangeListener(listener);
  22.      }
  23.      public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
  24.          veto.removeVetoableChangeListener(listener);
  25.      }
  26.  
  27.      // Opis właściwości ograniczanej
  28.  
  29.      class BoundedProperty<T> {
  30.      private String name;
  31.      private T value;
  32.  
  33.      public BoundedProperty(String name) {
  34.      this.name = name;
  35.      }
  36.  
  37.      public T getValue() { return value; }
  38.  
  39.      public void setValue(T newValue) throws PropertyVetoException {
  40.      T old = value;
  41.      veto.fireVetoableChange( "value", old, value );
  42.  
  43.      value = newValue;
  44.      chg.firePropertyChange(name, old, value);
  45.      }
  46.      }
  47.  
  48.      public static void main(String[] args) throws PropertyVetoException{
  49.  
  50.          BoundedProperty bp=new BoundedProperty("ala");
  51.  
  52.          }
  53.     }
  54.  
  55.  
  56.  
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?
Mar 20 '07 #7
oll3i
679 512MB
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)
Mar 20 '07 #8
r035198x
13,262 8TB
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?
Mar 20 '07 #9
oll3i
679 512MB
it didnt say what line i copied u the whole error it returns
Mar 20 '07 #10
r035198x
13,262 8TB
it didnt say what line i copied u the whole error it returns
Why did you make the Constrained class abstract?
Mar 20 '07 #11
oll3i
679 512MB
i asked myself the same question cos this code is a piece of code i took from my lectures i changed it from abstract
Mar 20 '07 #12
r035198x
13,262 8TB
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?
Mar 20 '07 #13
oll3i
679 512MB
no it's not working now it highlights BoundedProperty<T> bp=new BoundedProperty<T>(s); as an error

Expand|Select|Wrap|Line Numbers
  1. package zad12;
  2.  
  3. import java.beans.*;
  4. import java.io.Serializable;
  5.  
  6.  
  7. class Constrained implements Serializable {
  8.  
  9.       protected PropertyChangeSupport chg = new PropertyChangeSupport(this);
  10.       protected VetoableChangeSupport veto = new VetoableChangeSupport(this);
  11.  
  12.      private void addPropertyChangeListener(PropertyChangeListener pcl) {
  13.         chg.addPropertyChangeListener(pcl);
  14.       }
  15.  
  16.      private void removePropertyChangeListener(PropertyChangeListener pcl) {
  17.         chg.addPropertyChangeListener(pcl);
  18.       }
  19.  
  20.      private synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
  21.             veto.addVetoableChangeListener(listener);
  22.       }
  23.      private synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
  24.             veto.removeVetoableChangeListener(listener);
  25.      }
  26.  
  27.  
  28.  
  29.       class BoundedProperty<T>  {
  30.         private String name;
  31.         private T value;
  32.  
  33.         public BoundedProperty(String name) {
  34.           this.name = name;
  35.         }
  36.  
  37.         public T getValue() { return value; }
  38.  
  39.         public void setValue(T newValue) throws PropertyVetoException {
  40.           T  old = value;
  41.           veto.fireVetoableChange( "value", old, value );
  42.  
  43.           value = newValue;
  44.           chg.firePropertyChange(name, old, value);
  45.         }
  46.       }
  47.  
  48.       public static void main(String[] args) throws PropertyVetoException{
  49.           String s="ala";
  50.           BoundedProperty<T> bp=new BoundedProperty<T>(s);
  51.  
  52.           }
  53.     }
  54.  
  55.  
  56.  
Mar 20 '07 #14
oll3i
679 512MB
the lecture was about generics
Mar 20 '07 #15
r035198x
13,262 8TB
no it's not working now it highlights BoundedProperty<T> bp=new BoundedProperty<T>(s); as an error

Expand|Select|Wrap|Line Numbers
  1. package zad12;
  2.  
  3. import java.beans.*;
  4. import java.io.Serializable;
  5.  
  6.  
  7. class Constrained implements Serializable {
  8.  
  9.      protected PropertyChangeSupport chg = new PropertyChangeSupport(this);
  10.      protected VetoableChangeSupport veto = new VetoableChangeSupport(this);
  11.  
  12.      private void addPropertyChangeListener(PropertyChangeListener pcl) {
  13.      chg.addPropertyChangeListener(pcl);
  14.      }
  15.  
  16.      private void removePropertyChangeListener(PropertyChangeListener pcl) {
  17.      chg.addPropertyChangeListener(pcl);
  18.      }
  19.  
  20.      private synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
  21.          veto.addVetoableChangeListener(listener);
  22.      }
  23.      private synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
  24.          veto.removeVetoableChangeListener(listener);
  25.      }
  26.  
  27.  
  28.  
  29.      class BoundedProperty<T> {
  30.      private String name;
  31.      private T value;
  32.  
  33.      public BoundedProperty(String name) {
  34.      this.name = name;
  35.      }
  36.  
  37.      public T getValue() { return value; }
  38.  
  39.      public void setValue(T newValue) throws PropertyVetoException {
  40.      T old = value;
  41.      veto.fireVetoableChange( "value", old, value );
  42.  
  43.      value = newValue;
  44.      chg.firePropertyChange(name, old, value);
  45.      }
  46.      }
  47.  
  48.      public static void main(String[] args) throws PropertyVetoException{
  49.          String s="ala";
  50.          BoundedProperty<T> bp=new BoundedProperty<T>(s);
  51.  
  52.          }
  53.     }
  54.  
  55.  
  56.  
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?
Mar 21 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
4
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...
0
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...
9
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: .... <%@...
7
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...
232
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...
2
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...
4
jeffbroodwar
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...
0
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:...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
jinu1996
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...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.