Problem with adding objects to a collection
Hi
Been using this forum for a couple of years now to help me with my code, but it's the first time that I've had a problem which I couldn't find the answer for!
I'm trying to create two classes one called Reminder and one called Engagement. The Reminder class needs to hold a list of Engagement objects, but whenever I add a new Engagement object to the ArrayList I have created in Reminder and try to retreive it I get a null value.
If anyone can give me an idea of where I have gone wrong that would be most helpful,
Thank you in advance,
Steve
Code:
package reminder;
import java.util.*;
public class Reminder{
private GregorianCalendar date = null;
private String reason = null;
private Engagement engagement = null;
private List<Engagement> appointments;
private int year = 0;
private int month = 0;
private int day = 0;
public Reminder() { //the constructor
appointments = new ArrayList<Engagement>();
} //end constructor
public void add(int d, int m, int y, String r){ //this method takes an engagement object and adds it to the list
//public void add(Engagement engagement){
day = d;
month = m;
year = y;
reason = r;
appointments.add(new Engagement (new GregorianCalendar(y,m,d), reason));
System.out.println(day + "-" + month + "-" + year);//(new Engagement (date, reason));
appointments.add(new Engagement(new GregorianCalendar(2008,4,2), "My first appointment"));
System.out.println("\nThere are this number of items in the list: " + appointments.size()); //this was to check the item was added
public void getAppointments(){
//private int arrayPosition = 0;
//Iterator it = appointments.iterator();
for (Iterator it = appointments.iterator(); it.hasNext();){
System.out.println(it.next());//.appointments.toString());
//it.next();
package reminder;
import java.util.*;
import reminder.*;
public class Engagement{
private GregorianCalendar date = null;
private String reason = null;
/** Creates a new instance of Engagement */
public Engagement(GregorianCalendar d, String r) {
date = d;
reason = r;
public String getReason() {
System.out.println(reason);
return null;
public class Main { //main class to test the other classes
/** Creates a new instance of Main */
* @param args the command line arguments
public static void main(String[] args) {
Reminder reminderList = new Reminder(); //create an instance of Reminder
reminderList.add(2,4,2008, "My first appointment");
reminderList.add(6,10,2009, "My second appointment");
reminderList.add(2,4,2007, "My third appointment");
reminderList.getAppointments();
}
Hi Guys
Just wanted to let you know that I have realised where I went wrong, if you look in the Engagement class there is a method called toString(); which just has a return value of null, that is why I was getting the null values!
Sorry for wasting your time, it took me three hours to realise why it wasn't working before I contacted you and about an hour after I posted I realised what the problem was.
One other thing... why is reminderList bad naming? I was going to call the instance reminder but because the class holds a list of objects I thought I'd call it reminderList..
Thanks
Steve
Similar Messages
-
Problem with EnumKey "Object Not a Collection"
The purpose of this script was to allow me to quickly change the WSUS intranet server (I'm not fully done with it yet), instead of using the local Group Policy. Sometimes the WindowsUpdate key does not exist. Rather than guessing and writing a new one, I'd
rather check if it exists, and only write if it doesn't. The problem I've had is I get "Object is not a collection" when I use EnumKey. From what I know, null values are causing the error, but I don't know how to resolve it.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows"
Wscript.Echo "This program serves to connect you to your intranet WSUS server. It will create or modify the registry."
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
bFound = (lcase(subkey) = lcase(regkey))
if bFound then exit for
Next
if bFound then
Wscript.echo "'WindowsUpdate' exists."
'Continue script without creating a key named WindowsUpdate.
Else
'Since key did not exist, create key and then continue.
The problem code is underlined (Line 10 for me).EnumKey has a return value, and you're currently ignoring it. You can only assume that arrSubKeys has been set to an array if EnumKey returns 0. If it returns something other than 0, it's a Win32 error code which will give you more information about what
went wrong (for example, a return value of 2 is ERROR_FILE_NOT_FOUND, or "The system cannot find the file specified.")
Here's a brief example of how you might modify your code to check the return value:
intResult = objReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys)
If intResult <> 0 Then
WScript.Echo "Error code from EnumKey: " & intResult
Else
For Each subkey In arrSubKeys
If LCase(subkey) = LCase(regkey) Then
bFound = True
Exit For
End If
Next
If bFound Then Wscript.Echo "'WindowsUpdate' exists."
End If -
Problem with inherited Objects
Hi,
I have a problem with inherited objects inside Flex using
wsdl as the source of the object. The AS-classes are generated
inside Flex Builder 3.
Inside the wsdl I have 2 complex types:
<complexType abstract="true" name="PersistentObject">
<sequence>
<element name="id" nillable="true" type="xsd:string"/>
<element name="insertTimeStamp" nillable="true"
type="xsd:dateTime"/>
<element name="insertUsername" nillable="true"
type="xsd:string"/>
<element name="updateTimeStamp" nillable="true"
type="xsd:dateTime"/>
<element name="updateUsername" nillable="true"
type="xsd:string"/>
</sequence>
</complexType>
and
<complexType name="Contact">
<complexContent>
<extension base="tns3:PersistentObject">
<sequence>
<element name="birthday" nillable="true"
type="xsd:dateTime"/>
<element name="firstName" nillable="true"
type="xsd:string"/>
<element name="lastName" nillable="true"
type="xsd:string"/>
<element name="middleName" nillable="true"
type="xsd:string"/>
<element name="newPassword" nillable="true"
type="xsd:string"/>
<element name="password" nillable="true"
type="xsd:string"/>
<element name="title" nillable="true"
type="xsd:string"/>
<element name="username" nillable="true"
type="xsd:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
The classes in actionscript seem plausable:
public class PersistentObject
* Constructor, initializes the type class
public function PersistentObject() {}
public var id:String;
public var insertTimeStamp:Date;
public var insertUsername:String;
public var updateTimeStamp:Date;
public var updateUsername:String;
and
public class Contact extends PersistentObject
* Constructor, initializes the type class
public function Contact() {}
public var birthday:Date;
public var firstName:String;
public var lastName:String;
public var middleName:String;
public var newPassword:String;
public var password:String;
public var title:String;
public var username:String;
When I want to retreive an object of type Contact, it seems
that only a couple of entries are filled. While debugging the flex
XMLDecoder, I noticed something strange. It seems, like the decoder
is expecting the result xml data to be in alphabetical order:
birthday, firstname, lastname, etc. But since the object is
inherited, the data that is actually received contains elements
from the parent class: birthday, firstname, id, inserttimestamp,
The resulting object has just birthday and firstname filled,
which is somehow wrong. This seems to be a problem inside the
parser itself. What can I do?I am having a problem with an extended class as well.
When I step through the code, everything is going fine and the decoder (mx.rpc.xml::XMLDecoder) sees that the class is an extension and wants to get the values for the superclass first. When it gets into getApplicableValues(), it's looking for the values to be in the order of the definition which would be ok if the values collection didn't include the values from the subclass as well! It goes through the whole definition and doesn't find anything for the superclass because the values aren't where it expects them. When it pops back up to the subclass and starts to decode those values, it finds them because the definition order and values order match.
Is this a known issue? Or, am I misunderstanding something?
Thanks,
Chuck -
Hi,
I have a problem with adding a latest JSF 1.2 RI from Sun (https://javaserverfaces.dev.java.net/files/documents/1866/44998/jsf-1_2_03.zip) to JDeveloper as a new library.
I created a new User library and added into it jsf-impl.jar and jsf-api.jar from JSF 1.2 RI.
Then I try to create two new JSP Tag libraries based from .tld files.
When a .tld file is placed in "TLD File:" field there is no information below about Library Version and Required JSP Version. If I check "Execute Tags in JSP Visual Editor" and click "Customize" button - list of tags in "Customize Tag Library" window is empty.
I have errors when I try to use JSF Tags from this new library in JSP page like :
"Can't create tag instance: f:view (class: null). Make sure, that the tag class or a library contained this class is available in this application"
(free translation to English)
Is this possible to add JSF RI v1.2 as another library in Jdeveloper 10.1.3.1 ?
thanks for help
koliHi,
This solution is not exactly for Jdeveloper 10.1.3.x I think.
- "Create a JSF system library." section, point 2. - there is not possible to add library in folder other than User I see, so I added it in User folder.
- "Register the JSF JSP tag libraries." section, point 5. - in JD 10.1.3 there is no dialog box, I checked checkbox "Show Tag Library in Palette". A new library was added to User folder but there is no new libraries in component Palette.
Even as I use "Edit tag libraries .." from Component Palette context menu and add manually new tag libraries to selected, there is no libraries in Component Palette after it.
I feel so problem is with different .tld files format, not with adding libraries method.
Sun RI tld file (from version 1.2_03) fragment:
<taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<!-- ========== Tag Library Description Elements ========================= -->
<description>
The core JavaServer Faces custom actions that are independent of
any particular RenderKit.
</description>
<tlib-version>1.2</tlib-version>
<short-name>f</short-name>
<uri>http://java.sun.com/jsf/core</uri>
tld included in JD:
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<!-- ========== Tag Library Description Elements ========================= -->
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>f</short-name>
<uri>http://java.sun.com/jsf/core</uri>
<description>
The core JavaServer Faces custom actions that are independent of
any particular RenderKit.
</description>
Did JDeveloper 10.1.3.x maintain with taglib version 1.2 ?
Regards
koli -
[SOLVED] Problem with adding a SSH connection to startup
Hi guys. I have a problem with adding ssh connection to startup. i want this command to run before kde login screen and keep running all time.
ssh -D 9292 remoteuser@remotehost
but it doesnt connect. Thanks for help!
Last edited by alperenel (2011-03-11 00:10:27)cactus wrote:
ssh -fN -D 9292 remoteuser@remotehost
you need -f, which sends ssh to the background, and -N which does not execute a remote command.
If you need it to run as a user other than root, then you probably need to utilize su as well.
it didnt work either. i am putting it in rc.local but doesnt work. -
Problem with adding new field to the mass change screen in FBL5N
Hi,
We have a problem with adding the field XREF3 to the mass change screen. We followed steps described in the SAP Note 640908, but the result is that when we try to mass change some documents in FBL5N and enter some values in the mass change screen, a message appears: "Please enter at least one new value" and nothing is changed.
If you have faced with such a problem, we would be grateful if you give us some tips.
Regards,
Miłosz WłodarczykThe problem has been resolved: we didn't activate a code in SE80.
-
Problems with adding Library for a MySQL JDBC driver
Good day,
I am new with the JDeveloper package, so the following could be a user fault.
I found the following:
- I downloaded and installed Oracle JDeveloper 10.1.2.1.10 (latest version).
- I downloaded the latest JDBC drivers for MySQL. ( mysql-connector-java-3.1.10 )
Now, I did the following steps extracted from the link http://www.oracle.com/technology/products/jdev/tips/duff/mysql_and_oc4j3.html it should be quite easy to add the JDBC Drivers to the project.
I did the steps with the following results:
When I Edit the Project properties, follow Profiles -> Development -> Libraries
When I do ' New' , fill in at JS2E the value 'MySQL' and fill in the Class Path (in my case 'C:\javaInstalls\mysql-connector-java-3.1.10\mysql-connector-java-3.1.10-bin.jar').
In that case the [OK] is disabled. I should expect the [OK] button was enabled!
My question: Is this a bug? When not, what am I doing wrong!
Regards,
MikeI tried it on an other system and had no problems with adding the libraries. It still is a problem on that particular system using the Dutch version of XP. The problem is that the Ok button stays disabled !
Could it bw a version problem with Java? How ever no changes are made to the original configuration, so it should pick up as default the java version of JDeveloper self. -
Hi,
I have problem with embedded objects which contained embedded objects.
When I create an Object in the persistent memory and commit this object I get the following error:
ORA-22805: cannot insert NULL object into object tables or nested tables
In the constructor of my persisten object I create the embedded members in the transient memory:
ATestPersObj::ATestPersObj() : m_count(0), m_lang(NULL), m_cost(NULL) {
m_lang = new AEnumLanguage_OraType();
m_cost = new AAmount_OraType();
}Or when I dereference a reference I get this error:
ORA-00600: internal error code, arguments: [kokeicadd2], [16], [5], [], [], [], [], []
Can somebody give me a hint?
I've defined the following Type:
CREATE OR REPLACE TYPE AENUM_ORATYPE AS OBJECT (
VALUE NUMBER(10,0)
) NOT FINAL ;
CREATE OR REPLACE TYPE AENUMLANGUAGE_ORATYPE UNDER AENUM_ORATYPE (
) FINAL " );
CREATE OR REPLACE TYPE ACURRENCY_ORATYPE AS OBJECT (
ISONR NUMBER(5,0)
) FINAL ;
CREATE OR REPLACE TYPE AAMOUNT_ORATYPE AS OBJECT (
CCY ACURRENCY_ORATYPE,
LO32BITS NUMBER(10,0),
HI32BITS NUMBER(10,0)
) NOT FINAL ;
CREATE OR REPLACE TYPE ATESTPERSOBJ AS OBJECT (
COUNT NUMBER(4),
LANG AENUMLANGUAGE_ORATYPE,
COST AAMOUNT_ORATYPE
) FINAL ;
oracle::occi::Ref<ATestPersObj> pObjR = new(c.getConnPtr(), "TTESTPERSOBJ") ATestPersObj();
pObjR->setCount(i+2001);
pObjR->setLang(AEnumLanguage(i+1));
pObjR->setCost(AAmount(ACurrency(), 2.5));
c.commit();
c.execQueryRefs("SELECT REF(a) FROM TTESTPERSOBJ a", persObjListR);
len = persObjListR.size();
{for (int i = 0; i < len; i++) {
oracle::occi::Ref<ATestPersObj> pObjR = persObjListR;
pObjR->getCount();
pObjR->getLang();
c.commit();
With kind regards
Daniel
Message was edited by:
DanielF
Message was edited by:
DanielFHi,
I have problem with embedded objects which contained embedded objects.
When I create an Object in the persistent memory and commit this object I get the following error:
ORA-22805: cannot insert NULL object into object tables or nested tables
In the constructor of my persisten object I create the embedded members in the transient memory:
ATestPersObj::ATestPersObj() : m_count(0), m_lang(NULL), m_cost(NULL) {
m_lang = new AEnumLanguage_OraType();
m_cost = new AAmount_OraType();
}Or when I dereference a reference I get this error:
ORA-00600: internal error code, arguments: [kokeicadd2], [16], [5], [], [], [], [], []
Can somebody give me a hint?
I've defined the following Type:
CREATE OR REPLACE TYPE AENUM_ORATYPE AS OBJECT (
VALUE NUMBER(10,0)
) NOT FINAL ;
CREATE OR REPLACE TYPE AENUMLANGUAGE_ORATYPE UNDER AENUM_ORATYPE (
) FINAL " );
CREATE OR REPLACE TYPE ACURRENCY_ORATYPE AS OBJECT (
ISONR NUMBER(5,0)
) FINAL ;
CREATE OR REPLACE TYPE AAMOUNT_ORATYPE AS OBJECT (
CCY ACURRENCY_ORATYPE,
LO32BITS NUMBER(10,0),
HI32BITS NUMBER(10,0)
) NOT FINAL ;
CREATE OR REPLACE TYPE ATESTPERSOBJ AS OBJECT (
COUNT NUMBER(4),
LANG AENUMLANGUAGE_ORATYPE,
COST AAMOUNT_ORATYPE
) FINAL ;
oracle::occi::Ref<ATestPersObj> pObjR = new(c.getConnPtr(), "TTESTPERSOBJ") ATestPersObj();
pObjR->setCount(i+2001);
pObjR->setLang(AEnumLanguage(i+1));
pObjR->setCost(AAmount(ACurrency(), 2.5));
c.commit();
c.execQueryRefs("SELECT REF(a) FROM TTESTPERSOBJ a", persObjListR);
len = persObjListR.size();
{for (int i = 0; i < len; i++) {
oracle::occi::Ref<ATestPersObj> pObjR = persObjListR;
pObjR->getCount();
pObjR->getLang();
c.commit();
With kind regards
Daniel
Message was edited by:
DanielF
Message was edited by:
DanielF -
Problem with shared objects synchoronization.
I encountered a small problem with shared objects.
I'm working on a program that creates chat rooms of a fixed
size of 30 users. When the 31th user comes, a new room is created.
The idea is that the client first connects to the first room
and checks if it's full by connecting to shared objects. If it is
full, connection is closed and process is reapeated on a new
instance of the application.
I use a function to connect to an instance, which takes as a
parameter a number (1 for instance room_1, 2 for room_2, etc). The
function itself creates the necessary Netconnection and
sharedObject objects.
If a room is full, Netconnections and sharedObjects are
closed and function is called again with another number.
I have no problem for connecting to the first room, but after
closing the first connection and connecting to the new room, there
seem to be some problems with the shared objects (especially,
OnSync doesn't seem to execute again after the connection to the
shared objects of the new instance).
I was wondering if you had any ideas what could cause this.
Is it the use of the same variable names for connecting at two
different shared objects?
Here is the function :
function initStreams(room) {
client_nc = new NetConnection();
client_nc.connect("rtmp://192.168.0.4/Elearning/room_"+room);
in_ns = new NetStream(client_nc);
in_ns2 = new NetStream(client_nc);
Replay_video.attachVideo(in_ns);
out_ns = new NetStream(client_nc);
out_ns2 = new NetStream(client_nc);
in_ns.play("my_recorded_stream");
users_name = SharedObject.getRemote("users_name",
_root.client_nc.uri, false);
users_name.connect(_root.client_nc);
users_language = SharedObject.getRemote("users_language",
_root.client_nc.uri, false);
users_language.connect(_root.client_nc);
users_picture = SharedObject.getRemote("users_picture",
_root.client_nc.uri, false);
users_picture.connect(_root.client_nc);
users_finger = SharedObject.getRemote("users_finger",
_root.client_nc.uri, false);
users_finger.connect(_root.client_nc);
I you need more info, I can post more of the code on the
forum.
Any help would be really appreciatedI don't see any onStatus events in the code you posted above.
If you're defining the onstatus event outside the function, that's
the problem. When you define the shared object, you also need to
define it's onStatus event handler.
Also, you really should wait for the onStatus event of the
netConnection before you connect your sharedObjects. If you try to
connect the SO before the netConnection is established, the SO will
never connect. -
hi all,
i am having a problem with activeX objects.
my activeX ( Tree View) is wrking fine with windows2000
but when i am trying the same code with XP its saying dll missing.
do these activeX depends on OS also..
plz help me.hey Vishwas!
did you register the .dll?
do you work with vb.net?
which ServicePack do you have in Windows XP?
greetz
Matthias -
What is the problem with converting objects with gradients to gradient mesh?
What is the problem with converting objects with gradients to gradient mesh?
slange,
There may arise some smaller corruption states that may be cured by what you did, as you can see in the list. Sometimes, restarting thrice is needed.
The following is a general list of things you may try when the issue is not in a specific file (you may have tried/done some of them already); 1) and 2) are the easy ones for temporary strangenesses, and 3) and 4) are specifically aimed at possibly corrupt preferences); 5) is a list in itself, and 6) is the last resort.
If possible/applicable, you should save curent artwork first, of course.
1) Close down Illy and open again;
2) Restart the computer (you may do that up to 3 times);
3) Close down Illy and press Ctrl+Alt+Shift/Cmd+Option+Shift during startup (easy but irreversible);
4) Move the folder (follow the link with that name) with Illy closed (more tedious but also more thorough and reversible);
5) Look through and try out the relevant among the Other options (follow the link with that name, Item 7) is a list of usual suspects among other applications that may disturb and confuse Illy, Item 15) applies to CC, CS6, and maybe CS5);
Even more seriously, you may:
6) Uninstall, run the Cleaner Tool (if you have CS3/CS4/CS5/CS6/CC), and reinstall.
http://www.adobe.com/support/contact/cscleanertool.html -
I have too many problems with UserKeyMD Object
Hi everybody!!!......
I've too many problems with UserKeyMD object, this don't work, I have a Application which create the DataBase structure, but when try it for create the user key on "x" field in "ABC" table (x field is present on table, is db_Alpha with 8 chars, subtype is st_None) is raised the problem.
I try to create this way the key (VB example):
Dim oUserKeysMD As SAPbobsCOM.UserKeysMD
Set oUserKeysMD = oCompany.GetBusinessObject(oUserKeys)
oUserKeysMD.TableName = sTableName
oUserKeysMD.KeyName = sKeyName
oUserKeysMD.Unique = BoYesNoEnum.tYES
oUserKeysMD.Elements.ColumnAlias = sFieldName
oUserKeysMD.Add '<- here problem is raised
System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserKeysMD)
I'm work in Delphi .Net and translate the source code of my function to VB.
P.D.:this source code at least work 2 times, but does not use it until today, I do not know because no longer it works now but.
excuse my ingles is very bad
thanks
regards
Francisco Troncoso
Chile.
Message was edited by: Francisco TroncosoHi, I using this names for my tables, fields and keys.
the table name is:
AOTI
the fields names are:
codigo alpha editsize 8
decrip alpha editsize 40
tipo alpha editsize 1 - valid values W, C - Default Value C
grupo1 alpha editsize 1 - valid values Y, N - Default Value N
grupo2 alpha editsize 1 - valid values Y, N - Default Value N
grupo3 alpha editsize 1 - valid values Y, N - Default Value N
grupo4 alpha editsize 1 - valid values Y, N - Default Value N
grupo5 alpha editsize 1 - valid values Y, N - Default Value N
grupo6 alpha editsize 1 - valid values Y, N - Default Value N
grupo7 alpha editsize 1 - valid values Y, N - Default Value N
grupo8 alpha editsize 1 - valid values Y, N - Default Value N
all fields have subtype none and the key name is :
AOPK1
ColumnAlias is codigo, when I try to create the table, fields and key with MetaDataOperatios example I have not problems but I try to create with my application I have the error.
Regards,
Franciso. -
Hey guys , I have a problem with adding funds in my PSN account with my debit card . I have used the same card in the past with no problems at all but now for some reason it keeps on saying that the card number is invalid every single time ! Please help me , is there any solution ? Does it maybe has to do with Capital Control ( I live in Greece )
Thanks I use this
2.) You can make one of your buttons the default
button of the frame:
this.getRootPane().setDefaultButton(confirm);
well, did you implement the first suggestion of quitte?
here is an idea that might work!
JTextField username;
JPasswordField password;
JButton confirmButton;
username.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
password.requestFocus();
ActionListener l = new ActionListener(){
public void actionPerformed(ActionEvent ae){
//optional check for username and password length>0
//process logon.
password.addActionListener(l);
confirmButton.addActionListener(l); -
Problem with adding a new row in JTable
Hi,
I've created a JTable using DefaultTableModel with DefaultTableModel(Object[][] obj,Object[] col) constructor.I've written actionListener for a JButton which should add new row to the tablemodel.Now, the listener adds the row to the model.But its throwing an ArrayOutofBoundsException and the added row is not visible unless I click on any column of the table.
Kindly help me to resolve this problem
TIA
Regards
GopiThanks a lot for the reply. Here is the complete code
TableImpl.java
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
import java.util.Vector;
public class TableImpl extends JFrame {
DefaultTableModel dataModel; // TableModel Variable
/* Constructor to add table and button to the frame */
TableImpl() {
getContentPane().setLayout(null);
setSize(800,600);
myModel();
final JTable table = new JTable(dataModel);
JScrollPane scrollpane = new JScrollPane(table);
getContentPane().add(scrollpane);
scrollpane.setBounds(10,10,700,300);
TableColumn tcCol = table.getColumnModel().getColumn(1);
/* Adding ComboBox to the CellEditor of Column 2 of table */
JComboBox jcbComboBox = new JComboBox();
final ReturnVector vctDBAccess = new ReturnVector();
jcbComboBox.addItem(vctDBAccess.vctGetOidList().elementAt(0).toString());
jcbComboBox.addItem(vctDBAccess.vctGetOidList().elementAt(2).toString());
jcbComboBox.addItem(vctDBAccess.vctGetOidList().elementAt(4).toString());
tcCol.setCellEditor(new DefaultCellEditor(jcbComboBox));
/* Adding Listener for Table */
dataModel.addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
/* Columns Manipulation */
if(dataModel.getColumnName(e.getColumn()).equals("Second")) {
int iRow = e.getFirstRow();
int iColumn = e.getColumn();
String strColName = dataModel.getColumnName(iColumn);
String strData = (String)dataModel.getValueAt(iRow,iColumn);
String strNextColumn = dataModel.getColumnName(iColumn+1);
dataModel.setValueAt(vctDBAccess.vctGetOidList().elementAt(vctDBAccess.iGetIndex(strData)+1),iRow,iColumn+1);
/* Adding button to Frame */
JButton jbInsert = new JButton("Insert");
/* Adding new row to the Tablemodel -- Probelm is here */
jbInsert.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try {
Object[] nrow = {"what", "ever", "you"};
dataModel.addRow(nrow);
}catch(Exception ex) {
System.out.println("Exception at adding row = " + ex);
getContentPane().add(jbInsert);
jbInsert.setBounds(100,350,100,20);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
/* Method to initialise new tablemodel */
public void myModel() {
Object[][] data = { {new Integer(10),"two","three"},
{new Integer(5),"two","three"},
{new Integer(4),"two","three"},
String[] col = { "First", "Second", "Third"};
dataModel = new DefaultTableModel(data,col);
public static void main(String arg[]) {
TableImpl ct = new TableImpl();
ct.setVisible(true);
/* Class that returns a Vector of String for populating ComboBox entries and
for getting the index of a particular element of the vector */
class ReturnVector {
Vector vctOidName=null;
ReturnVector() {
this.vctOidName = new Vector();
vAddOidList();
public void vAddOidList() {
String[] dbResult = { "system", "1.3.6.1.2.1.1" ,
"interface", "1.3.6.1.2.1.2" ,
"snmp", "1.3.6.1.2.1.3" };
for(int i=0;i<dbResult.length;i++) {
System.out.println("Value = " + dbResult);
vctOidName.addElement(dbResult[i]);
public Vector vctGetOidList() {
return vctOidName;
public int iGetIndex(String strData) {
System.out.println("Index = " + vctOidName.indexOf(strData));
return vctOidName.indexOf(strData); -
Problem with SQL connection and a Collection
hi all,
I have two problems with sql...
1. how can I assign the values of a resultset to a collection?
2. how can I close the sql connection, because when I close the statement and connection error shows me in the resultset
thanks!Hello Pablo,
RetrivingResults In Collection:
1) use getObject method, and assign it to collection.
Collection c_obj=new ArrayList();
while(rs.next())
c_obj.add(rs.getInt(Project_ID), rs.getString(Project_Name));
Closing ResultSet
2) The close() methos of ResultSet closes the ResultSet object, like bellow
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
rs.close(); //Closes the result set
Maybe you are looking for
-
How do you make photos into a GIF????
I'm on the edge of pulling my hair out. What program will work with Mac to make Gif's. Do I need to download something to do it?
-
PO item should not be change in case of change PO if ASN has created
Hello Experts, We have implemented MM-SUS. We are facing a problem, A PO consist of 2 items on different delivery date, Vendor has created a ASN For first item. Now the ASN is pending for 2nd item on require delivery date. In between, Purchase change
-
After Mac OS X 10.6.3 upgrade can't access Yahoo mail and repeatedly get message ""Sorry, we are over capacity. Please wait a moment and try again." Help, please.
-
Problem testing report builder report
When I test my report it while in report builder, it looks great on the screen. When I try to actually print a page so I can see how it looks on paper using the forms, all I get is the background/ CF Developer message. What am I missing here? I sh
-
Forgot Account Password and Username
I forgot my account username and password for my computer because of this I can't update or download anything. Please help me find a solution