查看: 1106|回复: 6
|
(求助) Java project 的问题, 请各位大大帮帮忙。
[复制链接]
|
|
我是一位java新手, 希望大家可以帮帮忙。
我的 Greating.java 可以 compile, 没出error了。
但不可以execute,出了以下的东东:
Exception in thread "main" java.lang.StackOverflowError
以下是我的Greating.java sourcecode.
//=======================================================
/*
*/
import java.sql.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.lang.String.*;
public class Greating extends JPanel
{
public Greating(){
JPanel mp = new JPanel();
//String ccnn;
//ccnn = "xxxxxx";
String ccnn = null;
ccnn = new Greating().openConnection();
JLabel t1 = new JLabel( "HELLO"+ ccnn +"!!! \n WELCOME TO Hilton Hotel.." );
mp.add( t1, BorderLayout.CENTER );
add( mp );
}
public String openConnection( ) {
String cust_n = null;
try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection( "jdbc:odbc:hotel_service" );
//makes the resultset scrollable and updatable
Statement sn = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "Select CUST_NAME from CUSTOMER where ROOM_NUMBER ='0107' ;";
ResultSet rn = sn.executeQuery( sql );
// supose used the real computer name
//在这里可以放我的computer name (system name) 吗?
//好象where ROOM_NUMBER = computer name
//可以给我一个正确的SQL吗??
//String sql = "Select CUST_NAME from CUSTOMER where ROOM_NUMBER =" + computer name ";
cust_n = rn.getString(0);
sn.close();
con.close();
}
catch (Exception ex)
{
//String nn;
//nn = "No Name";
//return nn;
}
return cust_n;
}
}
//======================================================
以下是我的 main java application ==>CardDeck.java
//======================================================
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class CardDeck extends JFrame
implements ActionListener {
private CardLayout cardManager;
private JPanel deck;
private JButton controls[];
private String names[] = { "<<<<", "<-",
"->", ">>>>" };
public CardDeck()
{
super( "CardLayout " );
Container c = getContentPane();
// create the JPanel with CardLayout
deck = new JPanel();
cardManager = new CardLayout();
deck.setLayout( cardManager );
// set up card1 and add it to JPanel deck
JLabel label1 =
new JLabel( "card one", SwingConstants.CENTER );
JPanel card1 = new JPanel();
card1.setLayout ( new GridLayout (2,1) );
JPanel topmenu1 = new JPanel();
topmenu1.setLayout( new FlowLayout() );
topmenu1.add(new JLabel ("Greating || "));
topmenu1.add(new JLabel ("Morning Call weak up call || "));
topmenu1.add(new JLabel ("House Keeping || "));
topmenu1.add(new JLabel ("Food Order || "));
topmenu1.add(new JLabel ("Short Message || "));
topmenu1.add(new JLabel ("Game"));
JPanel c1 = new JPanel();
c1.add( new Greating() );
//c1.add( new GuestBook02() );
card1.add( topmenu1 );
card1.add( c1 );
deck.add( card1, label1.getText() ); // add card to deck
// set up card2 and add it to JPanel deck
JLabel label2 =
new JLabel( "card two", SwingConstants.CENTER );
JPanel card2 = new JPanel();
card2.setLayout ( new GridLayout (2,1) );
JPanel topmenu2 = new JPanel();
topmenu2.setLayout( new FlowLayout() );
topmenu2.add(new JLabel ("Greating || "));
topmenu2.add(new JLabel ("Morning Call weak up call || "));
topmenu2.add(new JLabel ("House Keeping || "));
topmenu2.add(new JLabel ("Food Order || "));
topmenu2.add(new JLabel ("Short Message || "));
topmenu2.add(new JLabel ("Game"));
JPanel c2 = new JPanel();
c2.add( new MorningCall() );
card2.add( topmenu2 );
card2.add( c2 );
deck.add( card2, label2.getText() ); // add card to deck
// set up card3 and add it to JPanel deck
JPanel card3 = new JPanel();
card3.setLayout( new GridLayout(2,1) );
JLabel label3 = new JLabel( "card three" );
JPanel topmenu3 = new JPanel();
topmenu3.setLayout( new FlowLayout() );
topmenu3.add(new JLabel ("Greating || "));
topmenu3.add(new JLabel ("Morning Call weak up call || "));
topmenu3.add(new JLabel ("House Keeping || "));
topmenu3.add(new JLabel ("Food Order || "));
topmenu3.add(new JLabel ("Short Message || "));
topmenu3.add(new JLabel ("Game"));
JPanel t3 = new JPanel();
t3.add ( new FoodOrder() );
/*
JPanel t2 = new JPanel();
t2.setLayout( new BorderLayout());
t2.add( new JButton( "North" ), BorderLayout.NORTH );
t2.add( new JButton( "West" ), BorderLayout.WEST );
t2.add( new JButton( "East" ), BorderLayout.EAST );
t2.add( new JButton( "South" ), BorderLayout.SOUTH );
JLabel label3 = new JLabel( "card three" );
t2.add( label3, BorderLayout.CENTER );
*/
card3.add( topmenu3 );
card3.add( t3 );
deck.add( card3, label3.getText() ); // add card to deck
// set up card4 and add it to JPanel deck
JLabel label4 =
new JLabel( "card four", SwingConstants.CENTER );
JPanel card4 = new JPanel();
card4.add( label4 );
deck.add( card4, label4.getText() ); // add card to deck
// create and layout buttons that will control deck
JPanel buttons = new JPanel();
buttons.setLayout( new GridLayout( 1, 4 ) );
controls = new JButton[ names.length ];
for ( int i = 0; i < controls.length; i++ ) {
controls[ i ] = new JButton( names[ i ] );
controls[ i ].addActionListener( this );
buttons.add( controls[ i ] );
}
// add JPanel deck and JPanel buttons to the applet
c.add( buttons, BorderLayout.NORTH );
c.add( new Label("=================================="), BorderLayout.CENTER );
c.add( deck, BorderLayout.SOUTH );
pack();
// set up card5 and add it to JPanel deck
JLabel label5 =
new JLabel( "card FIVE", SwingConstants.CENTER );
JPanel card5 = new JPanel();
card5.add( label5 );
deck.add( card5, label5.getText() ); // add card to deck
setLocation(100,110);
setSize( 800, 600 );
show();
}
public void actionPerformed( ActionEvent e )
{
if ( e.getSource() == controls[ 0 ] )
cardManager.first( deck ); // show first card
else if ( e.getSource() == controls[ 2 ] )
cardManager.next( deck ); // show next card
else if ( e.getSource() == controls[ 1 ] )
cardManager.previous( deck ); // show previous card
else if ( e.getSource() == controls[ 3 ] )
cardManager.last( deck ); // show last card
}
public static void main( String args[] )
{
CardDeck cardDeckDemo = new CardDeck();
cardDeckDemo.addWindowListener
(
new WindowAdapter()
{
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
//==========================================================
urgent....
谢谢大家帮忙 |
|
|
|
|
|
|
|
楼主 |
发表于 11-6-2005 08:51 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 12-6-2005 04:52 PM
|
显示全部楼层
bakagm 于 11-6-2005 08:51 PM 说 :
没人可以帮我忙吗???
可以寄源代码去本人电邮吗?很乱。 |
|
|
|
|
|
|
|
楼主 |
发表于 12-6-2005 09:12 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 7-6-2006 05:50 PM
|
显示全部楼层
因为你没有hotel_service的database吗?
注意:your database connection method,make sure u have the right way |
|
|
|
|
|
|
|
发表于 7-6-2006 05:51 PM
|
显示全部楼层
我comment了://ccnn = new Greating().openConnection(); in Greating.java就有output了 |
|
|
|
|
|
|
|
发表于 28-11-2006 03:48 PM
|
显示全部楼层
Normally stack over flow exception caused by unstoppable looping till JVM use up the memory. JVM will detect the error early but not until use up all the memory.
One of the example,
You got 2 methods,
Method A and Method B and they are calling each other within the method.
public class Test {
public void methodA() {
methodB();
}
public void methodB() {
methodA();
}
public static void main(String args[]) {
new Test().methodB();
}
}
Hope I've given you some idea.... |
|
|
|
|
|
|
| |
本周最热论坛帖子
|