| imcompatible type when converting a List to array |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- Accessing the name of the CLASS/JAR file invokedHello,
I am trying to pack all my files into a JAR - this includes CLASS
files and other textual files such as help, std configs, etc.
I would like to be able to extract them from the Java app straight out
of the JAR - and for this I need to know what the name of the JAR file
invoked was (it might have been renamed for X reasons)
Is there any sure way to do this? (the alternative is to have an
external file to contain said data, but I want to know if a way to
have everything self-contained exists, first)
Thanks,
Andrew
- 2
- DOM tree questionHi all,
For code sample domEcho02.java, every element node will have an empty text
node like below. looks like there is no direct method in the treemodel impl
or in the adaptor class that I can control this. how can I get rid of it?
// sample xml node
<pnode attr1='0'>
<cnode1 att1='attr'><value>blah</value></cnode1>
</pnode>
// will be translated in tree nodes
element: pnode
text: (empty, unnecessary)
element: cnode1
text: (empty, unnecessary)
element: value
text: blah
//should be
element: pnode
element: cnode1
element: value
text: blah
TIA
-d
- 2
- grabbing text from non-edit java windowHow do I get the text (in a java program) from a java window that is not an
edit window (ie, cannot hilight the text with a mouse)? ie, is there
something similar to in functionality to Windows API GetWindowText()?
- 2
- Date ArithmeticArg,
So I know I use the Calendar abstract class. And I am betting that I use
the Add method.
Could I see a example of some date arithmetic, e.g. number of days from
today since 01/01/1964.
Must I work out the differences by year, month, day individually, convert to
a common unit of time, add them, then convert to a displayable unit of time?
Struggling...
- 2
- a cuestionHello
Which is the utility of declaring a interface without methods in Java?
thanks
- 6
- Weird Problem w/ DecimalFormatThe following code snippet:
static DecimalFormat nf=new DecimalFormat("#####.00");
System.out.println(nf.format(1000.10));
sometimes stops working properly and instead of seeing 1000.10 I see 1000,10
(note the comma). I can't for the life of me figure out what is going on...
I'm using Java 1.3.1 on a Sun workstation.
Any ideas?
Cliff
- 8
- JSpinner causes trouble to JB 2005 designer...X-No-Archive: yes
Hi.
I try to build a GUI with the JB 2005 designer (JB 2005
Enterprise-Trial/Fondation version).
Basically it works until I want to add a JSpinner component. Then this
error happens: "null processing BeanInfo class
javax.swing.JSpinnerBeanInfo"
The component is not added. So I add it manually. But the rest of the
GUI components (following the JSpinner member variable) is mixed up
then.
Is there a workaround to this? Thanks.
-ric
- 9
- Serial Port CommunicationsI have a java application that I wrote that collects data from a
serial port on a laptop from a data collection device. Program works
well.
My bosses would like certain conditions to draw more attention than
just using the laptop's monitor. They would like two lights and a horn
to be controlled as well.
Tackling the serial input device was pretty easy, but I am not sure
where to start with this request.
1) I only have one serial port on the Laptop, but they want to control
4 devices (horn, light 1, light 2, data collection device). So how
do I handle that?
2) Where would I go to buy the other devices and what device would I
have my java program talk to in order to control them?
Thanks,
Larry
- 11
- Is Java really faster than Obj-C ? Should Apple dump Obj-C and go with Java?The old notion that Java on desktops is slow might have to go out the
window if more studies show this:
http://homepage.mac.com/spullara/rants/C1464297901/E775622191/index.html
Again, this points out the fact that there will probably be a
renaissance of Java on desktops as it percolates on Linux and Macs and
Windows desktops. We use Mac OS X iMacs at work and Java apps as
MoneyDance (a personal finance software that runs on all 3 desktops,
although it looks sorta crappy in windows) are very good looking and
extremely fast.
Now, if only IBM's open source eclipse made better looking SWT apps on
Mac and Linux...
- 14
- Socket error Windows getInputStreamHello,
Java version is 1.5.0_09. I am trying to connect from a Windows
machine to another Windows machine using sockets . Getting a socket
error for the following line. and throws EOFException
Socket s = null;
ObjectInputStream sin = null;
ObjectOutputStream sout = null;
s = new Socket( host, port );
sout = new ObjectOutputStream( s.getOutputStream() );
//write data to socket
sout.writeObject( req );
sout.flush();
InputStream is = s.getInputStream() );
sin = new ObjectInputStream( is ); // This line gives error
If I step into ObjectInputStream, I see:
public ObjectInputStream(InputStream in) throws IOException {
verifySubclass();
bin = new BlockDataInputStream(in);
handles = new HandleTable(10);
vlist = new ValidationList();
enableOverride = false;
readStreamHeader(); // This line gives error
bin.setBlockDataMode(true);
}
However, the same code works when I try to connect from Linux(Red Hat
Enterprise Linux WS release 4 (Nahant Update 5)) to Windows. Turned
off Windows firewall but no luck.
On the Windows Server I am trying to connect to a server agent waiting
on port 2002 that helps me connect to Citrix running on that machine.
The agent runs as a Windows service.
What could be wrong here?
Stack Trace
java.io.EOFException
at java.io.ObjectInputStream
$PeekInputStream.readFully(ObjectInputStream.java:2228)
at java.io.ObjectInputStream
$BlockDataInputStream.readShort(ObjectInputStream.java:2694)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:
761)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:277)
...
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
202)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
213)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
178)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
126)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
105)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
107)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
148)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
869)
at org.apache.coyote.http11.Http11BaseProtocol
$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:
664)
at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:
527)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:
80)
at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
- 14
- BPEL Products(Business prcess execution Language 4 webservices)Hi,
I had a few questions about BPEL products
1) Can you let me know the BPEL Servers available in the market. Do
these need to be integrated with J2EE appservers or can they run as is
if all I want to do is integrate a few Java applications and
webservices to the flow.
2) How powerful are Weblogic Integration suite and Websphere MQSeries
Integrator for integrating Webservices using BPEL. Also how easy is it
to develop this kind of flow. Collaxa has a more pure BPEL product
that seems easier for the above task.
Thanks in Advance,
Regards,
Rahul
- 14
- Java Web Start from CDRoedy Green wrote:
> On Sun, 19 Oct 2003 04:10:19 +0100, "Mike"
> <email***@***.com> wrote or quoted :
>
>>I don't recall having to do that once JWS is installed on the client. The
>>only thing that springs to mind is setting the mime type on a web server:
>
> I got friend to do a JRE install on a Java virgin machine, and lo to
> my delight, it set up the association.
>
> I now how have a self installing Java Web Start CD. I am 99% there. I
> think the problem has to do when you use trailing / and when you
> don't.
>
> You just put it in, and up comes the familiar dialog box about "do you
> Trust this Roedy Green fellah with this certificate."
>
> The key is this little C: program that autorun.inf
> kicks off.. It is crude but simple. It depends on 26 variants of the
> JNLP file being automatically generated.
In a platform-portable language, this is unbelievable. You've prevented use
of your product on anything but Windows.
--
Paul Lutus
http://www.arachnoid.com
- 14
- newbie with compilingHi
I am new to Java world, I download java version j2sdk1.4.1_01 to my
computer, and install it
when I try to compile program from command line type javac tst.java, I got
the following error
"Exception in thread "main" java.lang.NoClassDefFoundError:
com/sun/tools/javac/Main"
however, I can use textPad to compile it, when I try to run from textPad, I
got same error:
Thanks advance
Libin
- 14
- System clock monitoringwe have a java applet game that relies on a thread that ticks at 10n
miliseconds. Our problem is that we use the system clock time to see
the interval of ticks, and if a user manipulates the clock setting,
then we get erronous tick times.
Is there a way we can avoid this, or use the hardware clock , or some
solution where the user inteferenece will not disrupt the game ?
Thanks for all your suggestions,
-Vidhi.
- 15
- has anyone gotten this exception using SkinLF?I get the following exception when loading certain skins with SkinLF
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at
com.l2fprod.gui.plaf.skin.impl.gtk.GtkSeparator.getPreferredSize(GtkSeparator.java:92)
at
com.l2fprod.gui.plaf.skin.CompoundSkin$CompoundSeparator.getPreferredSize(CompoundSkin.java:961)
at
com.l2fprod.gui.plaf.skin.SkinSeparatorUI.getPreferredSize(SkinSeparatorUI.java:84)
It only happens when i try and load certain dialogs, and I'm not sure
which dialogs it happens it. I can try and come up with a small example
if no one has seen this before. (An example of a skin this occurs with
is: b0sumiErgothemepack.zip)
thanks!
|
| Author |
Message |
thufir

|
Posted: 2008-6-19 22:43:00 |
Top |
java-programmer, imcompatible type when converting a List to array
I have an ArrayList<Guest> which I want to convert to an Array, but I'm
getting:
init:
deps-jar:
Compiling 2 source files to /home/thufir/JavaProject28/build/classes
/home/thufir/bcit-comp2611-project2/src/a00720398/view/Tabs.java:15:
incompatible types
found : java.lang.Object[]
required: a00720398.data.Guest[]
Guest some_guests[] = FileUtil.getGuests().toArray();
1 error
BUILD FAILED (total time: 6 seconds)
If I change it to:
Object some_guests[] = FileUtil.getGuests().toArray();
then it works fine, but that's rather absurd because I know that the type
is Guest so I don't see why it would have to be an array of Object.
Surely I don't have to cast to Guest?
thanks,
Thufir
|
| |
|
| |
 |
Nigel Wade

|
Posted: 2008-6-19 23:49:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
thufir wrote:
> I have an ArrayList<Guest> which I want to convert to an Array, but I'm
> getting:
>
>
> init:
> deps-jar:
> Compiling 2 source files to /home/thufir/JavaProject28/build/classes
> /home/thufir/bcit-comp2611-project2/src/a00720398/view/Tabs.java:15:
> incompatible types
> found : java.lang.Object[]
> required: a00720398.data.Guest[]
> Guest some_guests[] = FileUtil.getGuests().toArray();
> 1 error
> BUILD FAILED (total time: 6 seconds)
>
>
> If I change it to:
>
> Object some_guests[] = FileUtil.getGuests().toArray();
>
> then it works fine, but that's rather absurd because I know that the type
> is Guest so I don't see why it would have to be an array of Object.
>
>
> Surely I don't have to cast to Guest?
>
>
> thanks,
>
> Thufir
There's another method which does what you want. It's a bit of a "hack", but it
does allow you to get an array of the correct type.
ArrayList implements Collection, and Collection has two toArray() methods. The
second method:
<T> T[] toArray(T[] a);
allows you to pass an array of type T as parameter, and it will return an array
of the same type. If the array passed is large enough it will put the contents
into that array, otherwise it creates a new array sufficient to hold the
contents. The "hack" is to pass an array of size 0:
Guest some_guests[] = FileUtil.getGuests().toArray(new Guest[0]);
--
Nigel Wade
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-20 1:58:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
thufir wrote:
> I have an ArrayList<Guest> which I want to convert to an Array, but I'm
> getting:
> init:
> deps-jar:
> Compiling 2 source files to /home/thufir/JavaProject28/build/classes
> /home/thufir/bcit-comp2611-project2/src/a00720398/view/Tabs.java:15:
> incompatible types
> found ?: java.lang.Object[]
> required: a00720398.data.Guest[]
> ?燝uest some_guests[] = FileUtil.getGuests().toArray();
The idiom
Guest [] someGuests = ...
is superior, both because the notation "Guest []" is a closer analog
to the English version, "array of Guest", and because the variable
name no longer violates the Java coding conventions.
<http://java.sun.com/docs/codeconv/index.html>
The other way would be pronounced, Yoda-like, as "Guest some_guests an
array of is, hmm", which is awkward.
> 1 error
> BUILD FAILED (total time: 6 seconds)
>
> If I change it to:
>
> Object some_guests[] = FileUtil.getGuests().toArray();
>
> then it works fine, but that's rather absurd because I know that the type
> is Guest so I don't see why it would have to be an array of Object.
>
> Surely I don't have to cast to Guest?
Surely you do!
Were you to read the Javadocs for List#toArray()
<http://java.sun.com/javase/6/docs/api/java/util/List.html#toArray()>
something you should *always* do for API methods that don't behave the
way you expect, and frequently for those that do, you would discover
that the return type of the method is Object []. So yeah, if you want
to do a narrowing conversion to Guest [] then you must cast. Only
widening conversions don't require a cast.
Reading the Javadocs is the first line of attack to understand bugs.
It's incredibly useful.
As a side benefit, were you to read the Javadocs for List#toArray()
you likely would also notice the Javadocs for the overload
List#toArray(T[] a).
<http://java.sun.com/javase/6/docs/api/java/util/
List.html#toArray(T[])>
Once again the Javadocs can rescue you, leading you to the idiom
Guest [] someGuests = FileUtil.getGuests().toArray( new Guest
[0] );
Always read the Javadocs. Always read the Javadocs. Always read the
Javadocs.
Lew
|
| |
|
| |
 |
thufir

|
Posted: 2008-6-20 3:14:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
On Thu, 19 Jun 2008 10:57:30 -0700, Lew wrote:
> As a side benefit, were you to read the Javadocs for List#toArray() you
> likely would also notice the Javadocs for the overload List#toArray(T[]
> a).
> <http://java.sun.com/javase/6/docs/api/java/util/
> List.html#toArray(T[])>
> Once again the Javadocs can rescue you, leading you to the idiom
>
> Guest [] someGuests = FileUtil.getGuests().toArray( new Guest
> [0] );
Thanks. This isn't the first time I've run across that idiom (?) of the
zero length array anonymous reference, but I can't recall where else it
was...
I read the API and was aware of the overloaded method, just didn't know
if it was what I was after.
-Thufir
|
| |
|
| |
 |
thufir

|
Posted: 2008-6-20 3:38:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
On Thu, 19 Jun 2008 14:43:15 +0000, thufir wrote:
> I have an ArrayList<Guest> which I want to convert to an Array
Ok, I have JList which holds an array of Guests. My plan was to have the
JList reference a Collection elsewhere, but now that there's an array of
Guests, then I might as well continue to work from the array directly.
For instance, create a listener so that when an element of the array is
clicked the Guest is displayed and available for CRUD type operations.
On the one hand, I want to separate the data (the model, the array of
Guests) from the view (the GUI). Yes?
On the other hand, I just want to get it done.
It seems kinda awkward to have the array within the applications GUI
interface. Any pointers?
thanks,
Thufir
|
| |
|
| |
 |
Mark Space

|
Posted: 2008-6-20 5:35:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
thufir wrote:
> It seems kinda awkward to have the array within the applications GUI
> interface. Any pointers?
It does, but it's also OK. You're making the connection at runtime,
which is loose enough to still have good separation between the model
and the view. As long as the model and view are communicating through
public access methods, you likely have plenty of separation between the two.
There's a quick object you can use for an arbitrary interface between
the view proper and the model, AbstractListModel. That's a special
model that already know how to talk to a JList, you just supply the
actual data.
"Just getting it done" is OK, just at least know that ALM is available.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2008-6-20 8:10:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
On Thu, 19 Jun 2008 14:43:15 GMT, thufir <email***@***.com>
wrote, quoted or indirectly quoted someone who said :
>Object some_guests[] = FileUtil.getGuests().toArray();
Don't use the lazy form of toArray. When you use the long form you
get an array of the proper type and size created without reflection.
You won't need any casts.
You are violating conventions. Put the [] next to the type. The old
C form just confuses people.
variables must begin with a lower case letter.
so that would become something like this::
Collection<Guest> guests = fileUtility.getGuests();
Guest[] someGuests = guests.toArray ( new Guest[ guests.size() ]);
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
|
| |
|
| |
 |
Daniel Pitts

|
Posted: 2008-6-20 8:46:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
thufir wrote:
> I have an ArrayList<Guest> which I want to convert to an Array, but I'm
> getting:
>
>
> init:
> deps-jar:
> Compiling 2 source files to /home/thufir/JavaProject28/build/classes
> /home/thufir/bcit-comp2611-project2/src/a00720398/view/Tabs.java:15:
> incompatible types
> found : java.lang.Object[]
> required: a00720398.data.Guest[]
> Guest some_guests[] = FileUtil.getGuests().toArray();
> 1 error
> BUILD FAILED (total time: 6 seconds)
>
>
> If I change it to:
>
> Object some_guests[] = FileUtil.getGuests().toArray();
Just a note, c++ programmers use "Foo foos[];" Java programmers use
"Foo[] foos;" Not a big deal, but it will throw/put some people off.
>
> then it works fine, but that's rather absurd because I know that the type
> is Guest so I don't see why it would have to be an array of Object.
>
>
> Surely I don't have to cast to Guest?
>
>
> thanks,
>
> Thufir
Why use an array at all, instead of using the List<Guest> returned by
FileUtil directly? Arrays are /almost/ always the wrong abstraction to
hold Objects.
If you insist on using a Guest array, you can use
Guest[] some_guests = FileUtil.getGuests().toArray(new Guest[0]);
Hope this helps,
Daniel.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
|
| |
|
| |
 |
Thufir

|
Posted: 2008-6-20 10:37:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
On Jun 19, 5:45 pm, Daniel Pitts
[...]
> Why use an array at all, instead of using the List<Guest> returned by
> FileUtil directly? Arrays are /almost/ always the wrong abstraction to
> hold Objects.
>
> If you insist on using a Guest array, you can use
> Guest[] some_guests = FileUtil.getGuests().toArray(new Guest[0]);
[...]
Yes, absolutely I concur, but I'm just not sure how because the JList
seems to want an array...I'll RTFM on that.
If it's possible to use the List<Guest> returned by FileUtil, then I
can perform my CRUD operations through FileUtil :)
-Thufir
|
| |
|
| |
 |
Daniel Pitts

|
Posted: 2008-6-20 12:01:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
Thufir wrote:
> On Jun 19, 5:45 pm, Daniel Pitts
> [...]
>> Why use an array at all, instead of using the List<Guest> returned by
>> FileUtil directly? Arrays are /almost/ always the wrong abstraction to
>> hold Objects.
>>
>> If you insist on using a Guest array, you can use
>> Guest[] some_guests = FileUtil.getGuests().toArray(new Guest[0]);
> [...]
>
> Yes, absolutely I concur, but I'm just not sure how because the JList
> seems to want an array...I'll RTFM on that.
>
> If it's possible to use the List<Guest> returned by FileUtil, then I
> can perform my CRUD operations through FileUtil :)
>
>
> -Thufir
Think about creating your own ListModel implementation that wraps your
List<Guest> object.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
|
| |
|
| |
 |
Thufir

|
Posted: 2008-6-20 15:51:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
On Jun 19, 9:01 pm, Daniel Pitts
<email***@***.com> wrote:
> Thufir wrote:
> > On Jun 19, 5:45 pm, Daniel Pitts
> > [...]
> >> Why use an array at all, instead of using the List<Guest> returned by
> >> FileUtil directly? Arrays are /almost/ always the wrong abstraction to
> >> hold Objects.
>
> >> If you insist on using a Guest array, you can use
> >> Guest[] some_guests = FileUtil.getGuests().toArray(new Guest[0]);
> > [...]
>
> > Yes, absolutely I concur, but I'm just not sure how because the JList
> > seems to want an array...I'll RTFM on that.
>
> > If it's possible to use the List<Guest> returned by FileUtil, then I
> > can perform my CRUD operations through FileUtil :)
>
> > -Thufir
>
> Think about creating your own ListModel implementation that wraps your
> List<Guest> object.
>
> --
> Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
What I have so far is the static method FileUtils.loadGuests() returns
a DefaultListModel, which seems sufficient for my needs, and then I'm
thinking that if there's a change to then pass the DefaultListModel
back to, for instance, FileUtils.writeGuests(DefaultListModel guests)
to write to disc.
Then, I suppose the GUI should call FileUtils.loadGuests() again to
sync it.
seems a bit odd, but I guess that's reasonable.
-Thufir
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-20 21:50:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
Thufir wrote:
> What I have so far is the static method FileUtils.loadGuests() returns
> a DefaultListModel, which seems sufficient for my needs, and then I'm
That breaks the separation between model and view.
Better is to have a custom ListModel as Daniel suggested.
class GuestListModel extends DefaultListModel
{
private List<Guest> modelData;
...
}
Now FileUtils need know nothing about how its results will be displayed.
Otherwise, what if you decide you don't like Swing any more, or want to port
to JSF or GWT? You would have to rewrite FileUtils. Yecch.
Have FileUtils deal only with List<Guest>. ListModel is the canonical
differential gear between model and view.
ListModel listModel = new GuestListModel( FileUtil.getGuests() );
Now we have clean separation and decoupled communication between model and view.
--
Lew
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-20 22:12:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
Thufir wrote:
> What I have so far is the static method FileUtils.loadGuests()
> ... FileUtils.writeGuests(DefaultListModel guests)
> ... FileUtils.loadGuests()
Rely far, far less on static methods. The burden of proof is on staticness to
justify itself, otherwise the bias should be to instanceness.
--
Lew
|
| |
|
| |
 |
Thufir

|
Posted: 2008-6-21 11:14:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
On Jun 20, 6:50燼m, Lew <email***@***.com> wrote:
[...]
> Now FileUtils need know nothing about how its results will be displayed.
> Otherwise, what if you decide you don't like Swing any more, or want to port
> to JSF or GWT? 燳ou would have to rewrite FileUtils. 燳ecch.
>
> Have FileUtils deal only with List<Guest>. 燣istModel is the canonical
> differential gear between model and view.
>
> ListModel listModel = new GuestListModel( FileUtil.getGuests() );
>
> Now we have clean separation and decoupled communication between model and view.
pardon, but I'm stuck in the details regarding GUI. How would this be
updated?
guestList.setModel(FileUtil.getGuests() /* kludge which returns a
DefaultListModel */); //guestList is a JList
If I'm going to do that, then I would also want to make ListModel a
singleton along the lines of:
public class GuestListModel extends DefaultListModel
{
private static final GuestListModel INSTANCE = new DataList();
private List<Guest> guests; // = FileUtil.getGuests();
private GuestListModel()
{
guests = FileUtil.getGuests();
}
public static GuestListModel getInstance()
{return INSTANCE;}
}
thanks,
Thufir
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-21 11:25:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
Lew wrote:
>> ListModel listModel = new GuestListModel( FileUtil.getGuests() );
>>
>> Now we have clean separation and decoupled communication between model and view.
Thufir wrote:
> pardon, but I'm stuck in the details regarding GUI. How would this be
> updated?
Of which "this" do you speak? If you mean the GuestListModel, that would
depend on how you implement the class. One way would be to keep a reference
to the ListModel and update it.
> guestList.setModel(FileUtil.getGuests() /* kludge which returns a
> DefaultListModel */); //guestList is a JList
Is this the "this" of which you spoke? But the snippet still has
FileUtil.getGuests() returning a ListModel, which breaks model-view
separation, i.e., it overlaps the two domains improperly.
> If I'm going to do that, then I would also want to make ListModel a
> singleton
Why?
--
Lew
|
| |
|
| |
 |
thufir

|
Posted: 2008-6-28 19:48:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
On Tue, 24 Jun 2008 12:08:52 -0700, Lew wrote:
> I really want to know. What are the advantages you see to making it a
> singleton, and disadvantages otherwise?
Ignoring the use of DefaultListModel for the purposes of this thread,
here's the model:
thufir@arrakis:~/bcit-comp2611-project2$
thufir@arrakis:~/bcit-comp2611-project2$ cat src/a00720398/data/
GuestsModel.java
package a00720398.data;
import javax.swing.*;
import a00720398.util.*;
@SuppressWarnings({"unchecked", "serial"})
public class GuestsModel extends DefaultListModel {
private static final GuestsModel INSTANCE = new GuestsModel();
private GuestsModel() {
java.util.List<Guest> Guests = FileUtil.readGuests();
for (Guest guest : Guests) {
addElement(guest);
}
}
public static GuestsModel getInstance() {
return INSTANCE;
}
}
thufir@arrakis:~/bcit-comp2611-project2$
By making it a Singleton it's impossible to accidentally have two "guest
lists" hanging around, by the definition of Singleton. You wouldn't want
to accidentally have duplicate db tables, would you? Plus, it was extra
points for making it a Singleton ;)
You couldn't accidentally re-read guests and wipe out the data, you'll
just get back INSTANCE. Allegedly, the idea is to modify, in this case,
GuestsModel, and then any changes are supposed to be reflected in the
view.
Had I known x days ago that you could just call addElement() from the
constructor and ?implicitly? add objects to the instance, I would've
saved myself a huge headache. Anyhow, now I know.
Out of curiosity, and on a tangent, if the model extends DefaultListModel
then what would the controller look like? I have:
thufir@arrakis:~/bcit-comp2611-project2$
thufir@arrakis:~/bcit-comp2611-project2$ cat src/a00720398/data/
GuestsController.java
package a00720398.data;
import java.util.*;
import javax.swing.event.*;
public class GuestsController implements ListSelectionListener,
Observer {
public void update(Observable arg0, Object arg1) {
// TODO Auto-generated method stub
}
public void valueChanged(ListSelectionEvent event) {
//Object obj = guestsView.getSelectedValue();
//Guest guest = (Guest) obj;
//displayGuest(guest);
}
}thufir@arrakis:~/bcit-comp2611-project2$
thufir@arrakis:~/bcit-comp2611-project2$
The purpose of GuestsController is to sync the view with the model?
Controller
Processes and responds to events, typically user actions, and may
invoke changes on the model.
http://en.wikipedia.org/wiki/Model-view-controller
-Thufir
|
| |
|
| |
 |
thufir

|
Posted: 2008-7-3 16:44:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
On Fri, 20 Jun 2008 09:50:09 -0400, Lew wrote:
> That breaks the separation between model and view.
>
> Better is to have a custom ListModel as Daniel suggested.
>
> class GuestListModel extends DefaultListModel {
> private List<Guest> modelData;
> ...
> }
Why do you have a List in there?
public class GuestsModel extends DefaultListModel{
private static final GuestsModel INSTANCE = new GuestsModel();
private GuestsModel() {
java.util.List<Guest> guests = FileUtil.deserializeList();
for (Guest guest : guests) {
addElement(guest);
}
//addAll(0,guests);
}
public static GuestsModel getInstance() {
return INSTANCE;
}
}
thanks,
Thufir
|
| |
|
| |
 |
Roedy Green

|
Posted: 2008-7-4 6:12:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
On Thu, 19 Jun 2008 14:43:15 GMT, thufir <email***@***.com>
wrote, quoted or indirectly quoted someone who said :
>Object some_guests[] = FileUtil.getGuests().toArray();
this looks familiar. I think I explained this before.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
|
| |
|
| |
 |
Roedy Green

|
Posted: 2008-7-4 6:12:00 |
Top |
java-programmer >> imcompatible type when converting a List to array
On Thu, 19 Jun 2008 14:43:15 GMT, thufir <email***@***.com>
wrote, quoted or indirectly quoted someone who said :
>.toArray();
the short answer is toArray ( new specific[ size ] )
instead.
see http://mindprod.com/jgloss/arraylist.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Import Map.class wrong version errorHi There....
I'm running into these import problems....
I'm trying to import the java.util.Map and java.util.HashMap Class on a
IBM AIX server running java 1.4.2.
Could anyone please help me in identifying what is that I am doing
wrong....
I have core.jar that has these files in the Lib dir...but still I get
the error...notably it says it is Wrong version 48 expecting 45....
I have no idea of this error could b....
Appreciate your response
/u/sharadch> $CLASSPATH
ksh:
/usr/java14/jre/lib/core.jar:/adw/adwinsp1/sqllib/java/db2java.zip:/adw/adwinsp1/sqllib/java/db2jcc.jar:/adw/adwinsp1/sqllib/java/sqlj.zip:/adw/adwinsp1/sqllib/function:/adw/adwinsp1/sqllib/java/db2jcc_license_cisuz.jar:/adw/adwinsp1/sqllib/java/db2jcc_license_cu.jar:.:
not found.
/u/sharadch> $PATH
ksh:
/usr/java14/jre/bin:/opt/oracle/product/9.2.0/bin:/usr/bin:/usr/ucb:/etc:/usr/dt/bin:/usr/bin:/usr/ucb:/etc:/usr/dt/bin:/usr/bin:/usr/ucb:/etc:/usr/dt/bin:/usr/bin:/usr/ucb:/etc:/usr/dt/bin:/usr/bin:/usr/ucb:/etc:/usr/dt/bin:/opt/openlink5/bin:/opt/openlink5/samples/ODBC:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java130/jre/bin:/usr/java130/bin:/usr/local/bin:/u/sharadch/bin:/opt/sas:/usr/local/bin:/opt/ks/bin:/opt/openlink5/bin:/opt/datamart/utilities:/usr/atria/bin:/adw/adwinsp1/sqllib/bin:/adw/adwinsp1/sqllib/adm:/adw/adwinsp1/sqllib/misc:/usr/bin:/etc:/usr/sbin:/usr/ucb:/u/sharadch/bin:/usr/bin/X11:/sbin:
not found.
/u/sharadch> cat HelloWorld.java
import java.util.Map;
import java.util.HashMap;
class HelloWorld {
public static void main(String args[]) {
System.out.print("Java Works !!!! ");
}
}/u/sharadch> javac HelloWorld.java
error: Invalid class file format:
/usr/java14/jre/lib/core.jar(java/util/Map.class), wrong version: 48,
expected 45
HelloWorld.java:1: Class java.util.Map not found in import.
import java.util.Map;
^
error: Invalid class file format:
/usr/java14/jre/lib/core.jar(java/util/HashMap.class), wrong version:
48, expected 45
HelloWorld.java:2: Class java.util.HashMap not found in import.
import java.util.HashMap;
^
error: Invalid class file format:
/usr/java14/jre/lib/core.jar(java/lang/Object.class), wrong version:
48, expected 45
HelloWorld.java:4: Superclass java.lang.Object of class HelloWorld not
found.
class HelloWorld {
^
6 errors
- 2
- Newbie Question: LayoutsI've been having the toughest time with this....
I want to have a JFrame with 3 containers in it.
The containers are laid out top to bottom.
Inside the first 2 containers I want 4 rows of a JLabel and
JTextField. Components are lined up in both containers so that the
labels end and textfields start at the same place on each line. These
two containers also have a titled borders, as does the third container
which is just a JTextArea. My questions are: what type should these
containers be? what type of layout should I use for them (and what
should the parameters to the method be if any)?
Thanks.
- 3
- Question About Scaling Virtual World to Real World..Hello,
i m developing one Java3D application, which takes real world
coordinates from database, e.g. (330020,22030 , its in MM(milimeter)).
So i have to place objects in My virtual world. but SimpleUniverse can
view upto 10 Meters ( i dont know How to extend this limit, if you
know then please tell me)... so i have to define Virtual Universe. And
actually i didnt got any simple code, which explain virtual universe
in Detail. So i need simple code which use Virtual Universe. or link.
Waiting for reply.
- 4
- Passing a method(reference) to an other method and calling the method.On Fri, 28 Mar 2008 02:58:17 -0700 (PDT), Erik <email***@***.com>
wrote, quoted or indirectly quoted someone who said :
>I have a staight forward question. Is is posible to pass a method as a
>parameter and call the passed
>method from within the other method?
see http://mindprod.com/jgloss/callback.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
- 5
- [Struts] ActionForm not displayed"Hamvil" <email***@***.com> wrote in message
news:email***@***.com...
> Basically i would like to fill a form with the data obtained from a
> database. Here follow a small part of the code:
>
> try {
> actionForm = registerManager.loadProfile(id);
> } catch (Exception e) {}
>
> basically actionForm is the one passed by the execute mathod.
>
> The method loadProfile returns an object RegisterBean (which extends
> ActionForm) that contain the user data loaded from the database.
I don't think you're supposed to construct your own form-- there's more to
it than the data. If you look at the API, you'll see some other attributes
that your own form is probably missing.
http://struts.apache.org/api/org/apache/struts/action/ActionForm.html
There is a way to ask the framework to make you a new form bean, but in this
case you don't really need that.
Instead of trying to replace the form bean with your own, try copying all of
the matching properties into it with:
BeanUtils.copyProperties( form, objectFromDatabase );
The Struts example webapp has an example of prepopulating a form. Using
forms as Data Transport Objects is generally frowned upon as it
unnecessarily couples your data access layer to Struts.
--
Wendy
- 6
- creating an ESRI shapefileI need to create an ESRI shapefile set (.shp, .shx, .dbf) from an
object. The object is drawn to the screen -- or any Graphics2D -- via
its draw() method, so a good starting point would be an implementation
of Graphics2D which writes to a shapefile instead of the screen.
Does anybody know of a good library to help with the creation of
shapefiles in Java?
- 7
- Graphics2D to ImageIcon problemI'm trying to do something that should be very simple.
I want to create an applet (or application, doesn't matter) to display a set
of drawn objects (drawn with a Graphics2D object). I want to be able to display
these objects in a pane by choosing them from a combo box. Two panes, one
on top with the combo box, one on the botton with the graphic.
I managed to get the images to be drawn in a simple panel stacked next to
each other but I really want to be able to select them and have them drawn
one at a time when selected in the combo box.
My program currently just instantiatest my classes that do the Graphics2D
drawing (the classes extend JPanel and just have a paint method in them)
and puts them in a grid layout.
REAL QUESTION: I would like to create an ImageIcon and just update it
with a new image when the combo box selection changes.
The problem is I can't seem to find a way to convert a
BufferedImage or a Graphics2D object into an ImageIcon.
Should I be doing this in a different way?
I don't work with JAVA everyday (though I love the language) and GUI and
graphics things just frustrate me to no end. I still haven't got the right
model in my head.
Any help would be very apprciated. Thanks,
James Kimble
--------------------------------------------------------------------------
Here's the code I have at the minute:
Main calling class:
//v 1.3
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.util.*;
import java.math.*;
import javax.swing.*;
import java.net.URL;
public class DSP1 implements ActionListener
{
final static int NUM_IMAGES = 8;
final static int START_INDEX = 3;
JLabel waveLabel = null;
JPanel mainPanel, noisePanel, sinePanel, noisesinePanel, stonPanel;
JPanel selectPanel, displayPanel, wavePanel;
JComboBox rateChoices = null;
JComboBox freqChoices = null;
JComboBox waveOption = null;
// Constructor
public DSP1()
{
// Create the main panel to contain the two sub panels.
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(2,1,5,5));
mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
selectPanel = new JPanel();
displayPanel = new JPanel();
waveLabel = new JLabel();
waveLabel.setHorizontalAlignment(JLabel.CENTER);
waveLabel.setVerticalAlignment(JLabel.CENTER);
waveLabel.setVerticalTextPosition(JLabel.CENTER);
waveLabel.setHorizontalTextPosition(JLabel.CENTER);
waveLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(),
BorderFactory.createEmptyBorder(5,5,5,5)));
waveLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(0,0,10,0),
waveLabel.getBorder()));
waveLabel.setText("");
String[] Wave = { "Sine", "Noise", "Sine + Noise", "Signal/Noise" };
waveOption = new JComboBox( Wave );
waveOption.setSelectedIndex ( 1 );
// Add border around the select panel.
selectPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Select Phase"),
BorderFactory.createEmptyBorder(5,5,5,5)));
// Add border around the display panel.
displayPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Display Phase"),
BorderFactory.createEmptyBorder(5,5,5,5)));
selectPanel.add(waveOption);
displayPanel.add(waveLabel);
mainPanel.add ( selectPanel );
mainPanel.add ( displayPanel );
waveOption.addActionListener(this);
}
// Implementation of ActionListener interface.
public void actionPerformed(ActionEvent event)
{
if ( "comboBoxChanged".equals(event.getActionCommand()) )
{
System.out.println ( "In action: " +
waveOption.getSelectedIndex() );
switch ( waveOption.getSelectedIndex() )
{
case 0: wavePanel = new SineWave();
displayPanel.add(wavePanel);
break;
case 1: wavePanel = new NoiseWave();
mainPanel.add(wavePanel);
break;
case 2: wavePanel = new NoiseSineWave();
mainPanel.add(wavePanel);
break;
case 3: wavePanel = new SignaltoNoise();
mainPanel.add(wavePanel);
break;
}
}
}
// main method
public static void main(String[] args)
{
// create a new instance of DSP1
DSP1 dsp_1 = new DSP1();
// Create a frame and container for the panels.
JFrame dsp1Frame = new JFrame("Lunar Phases");
// Set the look and feel.
try
{
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch(Exception e) {}
dsp1Frame.setContentPane(dsp_1.mainPanel);
dsp1Frame.setBounds(300,300,500,500);
// Exit when the window is closed.
dsp1Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Show the converter.
//dsp1Frame.pack();
dsp1Frame.setVisible(true);
}
}
Drawing class (they're all the same format):
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.event.*;
import java.util.*;
import java.math.*;
import javax.swing.*;
import java.net.URL;
class SineWave extends JPanel
{
static int rate;
public void paint (Graphics g)
{
Graphics2D g2D; // Get a Java 2D device context
super.paint(g);
g2D = (Graphics2D)g; // Get a Java 2D device context
g2D.drawString("Sine Wave", 250, 10); // Draw some text
g2D.drawString(" 100", 15, 95 ); // Draw some text
g2D.drawString(" 0", 15, 205); // Draw some text
g2D.drawString("-100", 15, 305); // Draw some text
g2D.drawLine ( 40, 200, 460, 200 );
int old_x = 50;
int old_y = 200;
int new_x = 50;
int new_y = 200;
for ( int i=1; i <= 100; i++ )
{
old_x = new_x;
old_y = new_y;
new_x += 4;
new_y = (int)(((Math.sin((6.2830/100.0)*i))*100)+200.0);
//System.out.println ( "From: " + old_x + ", " + old_y +
// " To: " + new_x + ", " + new_y );
g2D.drawLine ( old_x, old_y, new_x, new_y );
}
}
public static void setRate ( int r )
{
rate = r;
}
}
- 8
- inputting local filepathI am attempting to input a database location from a txt file located
within the build folder. However, I am having a bitchin time getting
it to work with relative file location. So far, I can only get
absolute file names to work, this is useless. Any help would be
appreciated. My code can be found below....
import java.sql.*;
import javax.swing.DefaultListModel;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class DataConnection {
public DataConnection(){
DataInputStream input;
String name = "";
File dBLocation = new File("C:\\Documents and
Settings\\Owner.JustinLaptop\\Desktop\\USC
Programs\\ConsultRequest\\build\\classes\\consultrequest\\testing\\dBURL.txt");
dBLocation = new File("..consultrequest\\testing\\dBURL.txt");
System.out.println(dBLocation.getParentFile());
System.out.println(dBLocation.exists());
try { // try to create an object representing the user-selected file
input = new DataInputStream( new FileInputStream(dBLocation) );
try { // try to read the file and create a string consisting of
its contents
char ch;
do { // read data from the file until end of file is reached
name = "";
ch = input.readChar();
while ( ch != ';' ) {
name = name + ch;
ch = input.readChar();
}
}
while ( true );
} catch ( Exception ex ) {
}
try { // try to close the file
input.close();
} catch ( Exception ex ) {
}
} catch ( Exception ex ) {
System.out.println("Database location cannot be found");
}
System.out.println(name);
}
public static void main(String[] args){
DataConnection data = new DataConnection();
}
}
- 9
- To smooth the movements of the mouseOn 19 jul, 07:45, Miss Elaine Eos <email***@***.com>
wrote:
> In article <email***@***.com>,
>
> email***@***.com wrote:
> > In my program, when I want to rotate or translate, movements abrupt.
> > How would you smooth the movements of the mouse?
>
> Abrupt in what way? Is it jerky? Smooth but too fast? Not able to do
> small movements?
>
> --
> Please take off your pants or I won't read your e-mail.
> I will not, no matter how "good" the deal, patronise any business which sends
> unsolicited commercial e-mail or that advertises in discussion newsgroups.
? ummm...It seems that you are dangerous...jijiji
Well, well. Movements, like the rotation, are too fast.If I move a
little the mouse, the scene is moved very fast.
I Can I make it slower?
(Sorry for my writing. I'm not english, and I'm beginning with the
English...^_^ )
Thanks
- 10
- too long filename? ? ?Hi
If i do the following, it will throw exception because the filename
is too long. How to fix it? I am using JBuilder X, JDK 1.4.2 and
windows XP.
try{
FileOutputStream f = new
FileOutputStream("projects\\os\\2004_03_04_JBuilderX\\2004_03_04_extras\\2004_03_04_BorlandXML\\2004_03_04_doc\\2004_03_04_api-doc\\2004_03_04_com\\2004_03_04_borland\\2004_03_04_xml\\2004_03_04_service\\2004_03_04_simpledb\\2004_03_04_jxinfo\\2004_03_04_ColumnName.html");
}catch (Exception ee){
ee.printStackTrace();
}
All the sub directory is exsit!!!
thanks
from Peter (email***@***.com)
- 11
- DSHOW filter graph displayed in a java object??I am getting ready to start looking at integrating a standalone DSHOW viewer
into a java2 applet that we use for control. I know that using JMF, you can
do a media player but I simply want a window that display the DSHOW output
as part of the applet running in IE under WinXP. I currently have a static
JPEG view but want to modify for motion video.
Thanks for any ideas.
Doug George
- 12
- String ExternalizationI know, generally, hard coding strings is not the best thing in the
world to do. However, if I am not planning on changing those strings
(especially if the application has already been written - and it's
big), is there any reason to incur the overhead (time to implement,
overhead of the use of Properties, etc) to convert an application so
it uses a .properties file.
Just curious what other developer opinions are.
Thanks.
- 13
- Secure access to database applicationHi All
Just looking for a bit of advice. I have an muti-user application
that I'm developing that talks to an Oracle database. What's the best
way (or at least a good way!) of securing user + password access to
the program? I've currently got a user table in the database and I
fetch whether the login credentials match what's in that table - but I
log in as an admin user to the DB in order to fetch the user table, so
admin password is coded into the application - this is obviously
bad.
Ideas? I presume there's a standard way of doing these kinds of
things :o)
- 14
- Overiding Static MethodsThis is a multi-part message in MIME format.
Hi,
When you override a non-static method, a call to that method from the super-class properly results in the sub-class version of that method being called. BUT, when you override a static method, it appears --to my frustration-- that a call to that method from the super-class results in the super-class version of the method being called!
Here is an example of what I mean. My intention is for the following to print out "Success" but it always prints out "Failure." instead.
It seems to ignore the fact that I have overrided method2( ) from ClassA with method2( ) from ClassB.
class ClassA
{ static void method1 () { method2(); }
static void method2 () { System.out.println("Failure."); }
}
class ClassB extends ClassA
{ public static void main (String[] args) { method1(); }
static void method2 () { System.out.println("Success."); }
}
I can get around the this problem by removing the static modifier, creating a third class, and instantiating a ClassB object. Like below. But I'd rather not have to create a third class, and instantiate an object if there is a way to to keep the code smaller,simpler,easier. Is there a way to fix the code above so that it prints "Success" instead? It just seems like there ought to be!
class ClassA
{ void method1 () { method2(); }
void method2 () { System.out.println("Failure."); }
}
class ClassB extends ClassA
{ void method2 () { System.out.println("Success."); }
}
class Start
{ public static void main (String[] args)
{ ClassB b = new ClassB();
b.Method1();
}
}
-Ken
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Hi, </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>When you override a non-static method, a call to
that method <EM>from the super-class </EM>properly results in the sub-class
version of that method being called. BUT, when you override a static
method, it appears --to my frustration-- that a call to that
method <EM>from the super-class </EM>results in the super-class version of
the method being called! </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Here is an example of what I mean. <STRONG>My
intention</STRONG> is for the following to print out "Success" but it
always prints out "Failure." instead. </FONT></DIV>
<DIV><FONT face=Arial size=2>It seems to ignore the fact that I have
overrided method2( ) from ClassA with method2( ) from ClassB.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>class ClassA <BR>{ static void
method1
() { method2(); }<BR>
static void method2
() { System.out.println("Failure.");
}<BR>}</FONT></DIV>
<DIV><FONT face=Courier size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>class ClassB extends ClassA </FONT></DIV>
<DIV><FONT face=Courier size=2>{ public static void main (String[]
args) {
method1(); }<BR> static
void method2
()
{ System.out.println("Success."); }<BR>}<BR></DIV></FONT>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I can get around the this problem by removing
the static modifier, creating a third class, and instantiating a
ClassB object. Like below. But I'd rather not have to create a third
class, and instantiate an object if there is a way to to keep the code
smaller,simpler,easier. Is there a way to fix the code above so that it
prints "Success" instead? It just seems like there ought to
be!</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>class ClassA </FONT></DIV>
<DIV><FONT face=Courier size=2>{ void method1 ()
{
method2();
}<BR> void method2 () {
System.out.println("Failure."); }<BR>}</FONT></DIV>
<DIV><FONT face=Courier></FONT> </DIV>
<DIV><FONT face=Courier size=2>class ClassB extends ClassA </FONT></DIV>
<DIV><FONT face=Courier size=2>{ void method2
() {
System.out.println("Success."); }<BR>}</FONT></DIV>
<DIV><FONT face=Courier></FONT> </DIV>
<DIV><FONT face=Arial size=2><FONT face=Courier>class Start </FONT></FONT></DIV>
<DIV><FONT face=Arial size=2><FONT face=Courier>{ public static void
main (String[] args) </FONT></FONT></DIV>
<DIV><FONT face=Arial size=2><FONT face=Courier> {
ClassB b = new ClassB();<BR>
b.Method1();<BR> }</FONT><BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>-Ken</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>
- 15
- Struts Eclipse JSTLHi,
I am an eclipse newbie. I need a free ide to develop struts with jstl.
I was wondering if anyone knew how to setup eclipse 3.2.1 with struts.
I was wonderng if any one could help me out. I cant seem to find any
good non commercial plugins for eclipse to do this
Thanks
:)
|
|
|