What is wrong in this java code?
Can someone please tell me what is wrong in this java code?
/* The program is intended to start animating text at the click of a button, pause it at another click and resume at the next click. It should continue like this */
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class TextAnime implements Runnable
JFrame frame;
boolean flag;
Thread animeThread;
JLabel label;
String[] textArray;
public TextAnime()
flag = false;
animeThread = new Thread(this);
frame = new JFrame("Animate Text");
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
frame.setLayout(gbl);
JButton button = new JButton("Start");
label = new JLabel("Stopped");
textArray = new String[5];
String textArray1[] = {"Programmer", "SportsMan", "Genius", "Friend", "Knowledgable"};
for(int ctr = 0; ctr<5 ; ctr++)
textArray[ctr] = textArray1[ctr];
gbc.weightx = 1;
gbc.gridx = 0;
gbl.setConstraints(button,gbc);
frame.getContentPane().add(button);
ButList bl = new ButList();
button.addActionListener(bl);
gbc.gridx = 1;
gbl.setConstraints(label,gbc);
frame.getContentPane().add(label);
frame.setSize(200,150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setVisible(true);
public class ButList implements ActionListener
public void actionPerformed(ActionEvent evt)
if(flag == false)
flag = true;
animeStart();
else
flag = false;
//animeStop();
public synchronized void animeStart()
animeThread.start();
Thread newThread;
newThread = Thread.currentThread();
newThread.notify();
public void animeStop()
animeThread.interrupt();
public void run()
int i = 0;
try
while(i == i)
if(i==5)
i=0;
label.setText(textArray);
animeThread.sleep(1000);
i++;
if (flag == false)
animeThread.wait();
catch(InterruptedException ie)
label.setText("Stopped");
public static void main(String args[])
TextAnime ta = new TextAnime();
Please tell me if this can be written in a more simpler manner. Also please correct this code. I am tired after trying many times.
When I fix your error, compile and run it, I get this exception:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException
at java.lang.Object.notify(Native Method)
at cruft.TextAnime.animeStart(TextAnime.java:81)
at cruft.TextAnime$ButList.actionPerformed(TextAnime.java:63)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
%
Similar Messages
-
What's wrong with this simple code?
What's wrong with this simple code? Complier points out that
1. a '{' is expected at line6;
2. Statement expected at the line which PI is declared;
3. Type expected at "System.out.println("Demostrating PI");"
However, I can't figure out them. Please help. Thanks.
Here is the code:
import java.util.*;
public class DebugTwo3
// This class demonstrates some math methods
public static void main(String args[])
public static final double PI = 3.14159;
double radius = 2.00;
double area;
double roundArea;
System.out.println("Demonstrating PI");
area = PI * radius * radius;
System.out.println("area is " + area);
roundArea = Math.round(area);
System.out.println("Rounded area is " + roundArea);Change your code to this:
import java.util.*;
public class DebugTwo3
public static final double PI = 3.14159;
public static void main(String args[])
double radius = 2.00;
double area;
double roundArea;
System.out.println("Demonstrating PI");
area = PI * radius * radius;
System.out.println("area is " + area);
roundArea = Math.round(area);
System.out.println("Rounded area is " + roundArea);
Klint -
Does anybody know what is wrong with my java code?
Does anybody know what is wrong with my java code?
--------------------Configuration: <Default>--------------------
stockApplet.java:47: cannot find symbol
symbol : variable M_pointThread
location: class StockApplet
if (M_pointThread==null)
^
stockApplet.java:49: cannot find symbol
symbol : variable M_pointThread
location: class StockApplet
M_pointThread=new Thread(this);
^
stockApplet.java:50: cannot find symbol
symbol : variable M_pointThread
location: class StockApplet
THE CODE:
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
public class StockApplet extends java.applet.Applet implements Runnable
int Move_Length=0,Move_Sum=0;
String FileName,Name_Str,Content_Date;
int SP[]=new int[2000];
int KP[]=new int[2000];
int JD[]=new int[2000];
int JG[]=new int[2000];
int Mid_Worth[]=new int[2000];
String myDate[]=new String[2000];
double CJL[]=new double[2000];
double MaxCJL,MidCJL;
Label label[]=new Label[10];
int MaxWorth,MinWorth;
int x_move0,x_move1,MaxLength=0;
int x0,y0,X,Y,Record_Num;
boolean Mouse_Move,Name_Change=true;
int JX_Five1,JX_Five2,JX_Ten1,JX_Ten2;
public void init()
TextField text1=new TextField();
Thread M_pointThread=null;
setLayout(null);
this.setBackground(Color.white);
this.setForeground(Color.black);
for(int i=1;i< 10;i++)
label=new Label();
this.add(label[i]);
label[i].reshape(i*80-65,10,50,15);
if(i==2){label[i].reshape(80,10,70,15);}
if(i==7){label[i].reshape(510,10,80,15);}
if(i >7){label[i].reshape((i-8)*490+45,380,70,15);}
FileName="six";
Name_Str="six";
this.add(text1);
text1.reshape(150,385,70,20);
text1.getText();
public void start()
if (M_pointThread==null)
M_pointThread=new Thread(this);
M_pointThread.start();Welcome to the forum. I think that George123 has your problem and its solution well in hand. Follow his good advice and you will have solved this problem. One other thing though just for future reference. If you post your code, here, you are going to want someone to be able to read it easily. Please use code tags when posting next time and your code will be much easier on the eye. You can find out about them here:
http://forum.java.sun.com/help.jspa?sec=formatting -
What's wrong with this mini-code? (Trying to draw graphics).
Could someone please help me fix what's wrong the following test-program?:
package project;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class GraphicsTester extends JPanel
JPanel thePanel = this;
public void GraphicsTester()
JFrame frame = new JFrame();
frame.setSize(600,600);
frame.add(thePanel);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
protected void paintComponent(Graphics g)
super.paintComponent(g);
g.drawRect(50, 50, 50, 50);
System.out.println("Sup fool");
public static void main(String[] args)
GraphicsTester gt = new GraphicsTester();
System.out.println("works2");
}Any help would be greatly appreciated!
Thanks in advance!Also, all Swing code should be called from the Event Dispatch Thread. It probably isn't hurting much in your case. But, in the body of main, do this (instead of the comment, put what you currently have as the body of main):
EventQueue.invokeLater(
new Runnable()
public void run()
// Your current body of main.
}); -
What is wrong about this DefaultTableModel code?
Hi,
Can anybody tell me what is wrong about the construction of my JTable. I create the instance of the below class and add to my JTable:
MyTableModel myModel = new MyTableModel();
JTable costTable = new JTable(myModel);
I can see printouts "MTM_1,2,3,4" then it gives me an exception
Exception caught in Scenegraph: 16 >= 16
The vector IFC_Tree.totalVector has members like:
IFC_Tree.totalVector[0]: [IFCBeam, 4.962499618530273, m3, 0.0, 0.0]
IFC_Tree.totalVector[1]: [IFCColumn, 13.84760570526123, m3, 0.0, 0.0]
IFC_Tree.totalVector[2]: [IFCFloor, 113.82814025878906, m3, 0.0, 0.0]
IFC_Tree.totalVector[3]: [IFCWall, 229.7195587158203, m3, 0.0, 0.0]
IFC_Tree.totalVector[4]: [IFCRoofSlab, 215.8400421142578, m2, 0.0, 0.0]
IFC_Tree.totalVector[5]: [IFCWindow_2.375*2.45, 8.0, number, 0.0, 0.0]
IFC_Tree.totalVector[6]: [IFCWindow_0.6*0.6, 20.0, number, 0.0, 0.0]
IFC_Tree.totalVector[7]: [IFCWindow_3.85*2.45, 3.0, number, 0.0, 0.0]
IFC_Tree.totalVector[8]: [IFCWindow_2.0*2.1, 2.0, number, 0.0, 0.0]
IFC_Tree.totalVector[9]: [IFCDoor_0.9*2.1, 17.0, number, 0.0, 0.0]
IFC_Tree.totalVector[10]: [IFCDoor_1.8*2.45, 2.0, number, 0.0, 0.0]
IFC_Tree.totalVector[11]: [IFCDoor_0.8*2.1, 28.0, number, 0.0, 0.0]
IFC_Tree.totalVector[12]: [IFCDoor_0.9*2.45, 11.0, number, 0.0, 0.0]
IFC_Tree.totalVector[13]: [IFCDoor_2.0*2.1, 2.0, number, 0.0, 0.0]
IFC_Tree.totalVector[14]: [IFCDoor_1.0*2.1, 4.0, number, 0.0, 0.0]
IFC_Tree.totalVector[15]: [null, null, null, TOTAL COST, 0.0]
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import javax.swing.DefaultCellEditor;
import java.util.Vector;
//public class MyTableModel extends AbstractTableModel
public class MyTableModel extends DefaultTableModel
private boolean DEBUG = true;
static double totalCost = 0.0;
static Vector data = new Vector();
static Vector columnNames = new Vector();
static Vector tmp;
public MyTableModel()
System.out.println("MTM_1");
addColumn("IFCOBJECTS OR PROCESSES");
addColumn("QUANTITY");
addColumn("UNITS");
addColumn("UNIT COST (�)");
addColumn("TOTAL COST (�)");
System.out.println("MTM_2");
for(int i=0; i < IFC_Tree.totalVector.size(); i++)
System.out.println("MTM_3");
tmp = (Vector)(IFC_Tree.totalVector.elementAt(i));
System.out.println("MTM_4");
addRow(tmp);
System.out.println("MTM_5");
System.out.println("MTM_6");
public int getColumnCount()
return columnNames.size();
public int getRowCount()
public String getColumnName(int col)
public Object getValueAt(int row, int col)
public boolean isCellEditable(int row, int col)
public void setValueAt(Object value, int row, int col)
}Hi,
Can anybody tell me what is wrong about the construction of my JTable. I create the instance of the below class and add to my JTable:
MyTableModel myModel = new MyTableModel();
JTable costTable = new JTable(myModel);
I can see printouts "MTM_1,2,3,4" then it gives me an exception
Exception caught in Scenegraph: 16 >= 16
The vector IFC_Tree.totalVector has members like:
IFC_Tree.totalVector[0]: [IFCBeam, 4.962499618530273, m3, 0.0, 0.0]
IFC_Tree.totalVector[1]: [IFCColumn, 13.84760570526123, m3, 0.0, 0.0]
IFC_Tree.totalVector[2]: [IFCFloor, 113.82814025878906, m3, 0.0, 0.0]
IFC_Tree.totalVector[3]: [IFCWall, 229.7195587158203, m3, 0.0, 0.0]
IFC_Tree.totalVector[4]: [IFCRoofSlab, 215.8400421142578, m2, 0.0, 0.0]
IFC_Tree.totalVector[5]: [IFCWindow_2.375*2.45, 8.0, number, 0.0, 0.0]
IFC_Tree.totalVector[6]: [IFCWindow_0.6*0.6, 20.0, number, 0.0, 0.0]
IFC_Tree.totalVector[7]: [IFCWindow_3.85*2.45, 3.0, number, 0.0, 0.0]
IFC_Tree.totalVector[8]: [IFCWindow_2.0*2.1, 2.0, number, 0.0, 0.0]
IFC_Tree.totalVector[9]: [IFCDoor_0.9*2.1, 17.0, number, 0.0, 0.0]
IFC_Tree.totalVector[10]: [IFCDoor_1.8*2.45, 2.0, number, 0.0, 0.0]
IFC_Tree.totalVector[11]: [IFCDoor_0.8*2.1, 28.0, number, 0.0, 0.0]
IFC_Tree.totalVector[12]: [IFCDoor_0.9*2.45, 11.0, number, 0.0, 0.0]
IFC_Tree.totalVector[13]: [IFCDoor_2.0*2.1, 2.0, number, 0.0, 0.0]
IFC_Tree.totalVector[14]: [IFCDoor_1.0*2.1, 4.0, number, 0.0, 0.0]
IFC_Tree.totalVector[15]: [null, null, null, TOTAL COST, 0.0]
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import javax.swing.DefaultCellEditor;
import java.util.Vector;
//public class MyTableModel extends AbstractTableModel
public class MyTableModel extends DefaultTableModel
private boolean DEBUG = true;
static double totalCost = 0.0;
static Vector data = new Vector();
static Vector columnNames = new Vector();
static Vector tmp;
public MyTableModel()
System.out.println("MTM_1");
addColumn("IFCOBJECTS OR PROCESSES");
addColumn("QUANTITY");
addColumn("UNITS");
addColumn("UNIT COST (�)");
addColumn("TOTAL COST (�)");
System.out.println("MTM_2");
for(int i=0; i < IFC_Tree.totalVector.size(); i++)
System.out.println("MTM_3");
tmp = (Vector)(IFC_Tree.totalVector.elementAt(i));
System.out.println("MTM_4");
addRow(tmp);
System.out.println("MTM_5");
System.out.println("MTM_6");
public int getColumnCount()
return columnNames.size();
public int getRowCount()
public String getColumnName(int col)
public Object getValueAt(int row, int col)
public boolean isCellEditable(int row, int col)
public void setValueAt(Object value, int row, int col)
} -
What is wrong with this idoc code snip?
Hi all here's the code that's supposed to give me a default value for a metadata in check-in:
1. <$if dDocAccount like "test*"$>
2. <$dprDefaultValue="Test"$>
3. <$elseif userHasRole("TesterA") or userHasRole("TesterB")$>
4. <$dprDefaultValue="A or B"$>
5. <$elseif userHasRole("TesterC") or userHasRole("TesterD")$>
6. <$dprDefaultValue="C or D"$>
7. <$else$>
8. <$dprDefaultValue="Not A nor B nor C nor D"$>
9. <$endif$>
Now if I leave the code like that only the first 2 lines work meaning that if first condition fails then the whole code stops working even though line 3 is true... is there something wrong in just calling dDocAccount on its own? never seen that happen before.
If I change that first line for <$if *#active.* dDocAccount like "test*"$> then this first condition won't work but the rest (line 3+) does work!
please help!!Hmmmm,
If your first two lines work if true then the issue is with the elseif lines right?
userHasRole("foo") returns true or false. Can you wrap userHasRole("foo") in an "isTrue()" function and test that way?
What about exploding the OR statement and writing a bunch of elseifs to see if it works that way.
The other thing you can do is to wrap your OR clause itself in parens
<$elseif ((userHasRole("foo")) or (userHasRole("bar")))$>
do stuff
<$endif$>
let us know what works for you
Warmly,
Billy Cripe
Fishbowl Solutions -
Does any one know what is wrong with this servlet code
package com.bt.ros;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
* This class is a servlet that searches for a Finder Aid.
* @author
public class FinderAidsSearchS extends HttpServlet {
* This is the static initializer,
* executed the first time this class is referred to.
* It makes sure the JDBC pool driver is loaded.
* This method examines an HTTP request and searches for the
* specified Finder Aid record in the database. It then redirects
* the response to the <tt>Results.jsp</tt> JSP page.
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException
HttpSession session = req.getSession(true);
//res.setContentType("text/html");
//PrintWriter out = res.getWriter( );
//out.println("<HTML>");
//out.println("<HEAD>");
//out.println("<TITLE>");
//out.println("A Servlet Example");
String year = req.getParameter("Year");
String year_range = req.getParameter("Year_Range");
String county = req.getParameter("County");
Connection conn = null;
try {
//example code from tomcatmanual
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/rosDS");
//Connection
conn = ds.getConnection();
Statement stmt = conn.createStatement();
String select = "select * from abridgment where " +
"(a_county = '" + county +
"' AND a_year_date = " + year +
out.println("<DEBUG> <select> the select staement is : " + select);
stmt.execute(select);
ResultSet resultSet = stmt.getResultSet();
Results abridgeresults = new Results();
abridgeresults.setName("NaeemColl");
Abridgment varabridgment = null;
int nRows = 0;
while(resultSet.next()){
nRows++;
varabridgment = new Abridgment();
varabridgment.seta_county(county);
varabridgment.seta_year_date(Integer.parseInt(year));
varabridgment.seta_sub_year_volume(resultSet.getInt("a_sub_year_volume"));
// out.println("varabridgment - attributes are:");
//out.println("varabridgment - attributes are:" +varabridgment.geta_sub_year_volume());
//out.println("varabridgment - attributes are:"+resultSet.getInt("a_sub_year_volume"));
varabridgment.seta_page_id(resultSet.getString("a_page_id"));
varabridgment.seta_month_date(resultSet.getInt("a_month_date"));
varabridgment.seta_day_date(resultSet.getInt("a_day_date"));
varabridgment.seta_year_sequence(resultSet.getLong("a_year_sequence"));
varabridgment.seta_day_sequence(resultSet.getLong("a_day_sequence"));
varabridgment.seta_year_volume(resultSet.getInt("a_year_volume"));
varabridgment.seta_volume_id(resultSet.getString("a_volume_id"));
varabridgment.seta_summary(resultSet.getString("a_summary"));
varabridgment.seta_batch_id(resultSet.getLong("a_batch_id"));
varabridgment.seta_image_id(resultSet.getLong("a_image_id"));
abridgeresults.addAbridgment(varabridgment);
//trying to use vector construct
req.setAttribute("results",abridgeresults);
//session.setAttribute("results", abridgeresults);
stmt.close();
conn.close();
//out.println("</BODY>");
//out.println("</HTML>");
// String sURL = res.encodeRedirectURL("/rossearch/results.jsp");
try{
//TEMPCOMM res.sendRedirect(sURL);
req.getRequestDispatcher("/rossearch/results.jsp").forward(req, res);
//TEMPCODE
//out.println("</BODY>");
//out.println("</HTML>");
catch(Exception e){
System.err.println("Exception: FinderAidsSearchS.service: " + e);
catch (Exception e) {
System.err.println("Exception: FinderAidsSearchS.service: " + e);
}i really need some assistance at the following areas of code :
where the database results are set to attributes of one bean varabridgment (Type Abridgement) - the declaration and use of this bean.
and where this bean is then added to another bean abridgeresults (Type Results) as a List collection.
i get a null pointer exception when i try to retrieve the List from abridgeresults object of Type Results Bean.
i would really appreciate some assistance in this - i really need to go to sleep now - but cant until i solve this issue. - thanks all in advance.below is exception outputed to tomcat log file.
it is thrown at the following line of code in the jsp that tries to get the List object :
currently jsp code to retrieve List: <% List myAbridgments = (List) request.getAttribute("results");
for (int i = 0; i < myAbridgments.size(); i++) {
abridgment = (Abridgment) myAbridgments.get(i);
%>
line that gives problem is
(results_jsp.java:95)
//myAbridgments - is variable where i store the List object in jsp scriptlet
for (int i = 0; i < myAbridgments.size(); i++) {
Also, i dont understand why the servlet keeps on forwarding to the results.jsp when i even comment out the line of code to forward request oobject to results.jsp - i recompile copy it over original and restart tomcat - but still i get the null pointer exception in results_jsp - but i'm no longer forwarding anything to this jsp. --- i want to do some out.printline statemets in servelt to see some of the data from the query - but i cant as it just forwrads the request to results.jsp - how can i output the data to look at debug - i dont have a log4j logger setup and dont have IDE to be able to place break points - so wanted to just output stuff to browser to have a look at what was going on - but can't as just forwards request on ?
Exception ....
2005-11-07 02:45:20 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536)
----- Root Cause -----
java.lang.NullPointerException
at org.apache.jsp.results_jsp._jspService(results_jsp.java:95)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536) -
What's wrong with this button code
Dear All,
I am trying to set up a button handler for many buttons
rather just one. The
intention of this code is to say if I press Load1 to Load40
that button and
only that button's alpha should change to 50%. This code
makes them all 50%
alpha when the frame loads rather than on the onPress event.
Can someone please help me out with this one?
i = 0;
while (i<40) {
this["Load"+i].onPress = btnEvaluate(this["Load"+i]);
++i;
function btnEvaluate(target_btn:Button) {
target_btn._alpha = 50;
Thanks again.
Alastair MacFarlanekglad,
Thanks again. What would this group do without your help.
Alastair
"kglad" <[email protected]> wrote in message
news:gh0sq0$cbv$[email protected]..
> :
>
>
>
> for (var i = 0;i<40;i++) {
> this["Load"+i].onPress =function(){
> this._alpha=50;
> }
> } -
Can't gotoAndStop ...what's wrong with this button code?
Hi,
I'm totally stumped as to why I can't navigate to another frame.
I have put 2 days into this simple problem now and I'm ready to give up and go back to AS2.
Please help!
I'm using CS4; publish settings AS3, 10.0
I have a button on frame 2 that should take me to frame 3 when clicked.
(So far I've tried a hundred different ways but I don't get to frame 3...)
Different things I tried...
> Creating the button dynamically from the library...
> Inserting it statically from the library on frame 2...
> referencing the mainTimeline through a variable...
> wrapping the gotoAndStop action in another function...(if placed directly on the timeLine the movie correctly goes straight to frame 3)
> naming frame 3...
> using 'nextFrame' instead of 'gotoAndStop'...
etc..
In most cases I don't get an error in the output panel and no compiler error either; it just doesn't work!!!
(Just stays on the same frame after I click the button)
Here's the code I think should work; but doesn't:
function moveTo3 (event:MouseEvent):void {
trace("button_clicked"); // always traces correctly; but movie does not go to frame 3 !!!
gotoAndStop(3);
f_btn.addEventListener(MouseEvent.CLICK, moveTo3);
WHAT AM I MISSING HERE?
Thanks in advance ...Hi Ned,
I have to run out and don't have the time to deal with it right now but you're RIGHT.
I do have an 'onEnterFrame' listener on frame 1 !
It's doing some animation with a symbol and I don't think I removed the listener itself.
I just set the object to null when it reached [alpha:0].
THANKS!
I'll check it out as soon as I can but I really think you got me looking in the right direction now.
Thanks again,
Connor
(I'll post an update when I get back to it) -
Hi guys
I have a little experience with java
I have to classes LoginScreen and newUser. LoginScreen calss reads data from text file which is user name and passwords then extracts usernames and load them to Comobox .in the first position of the Comobox I Inserted Create New Profile string .When the user click on it another Screen will appear which is instance of the newUser class .And that will allow new user to enter his name and press Ok button to confirm the operation ,then the new Screen will be closed .When that happen I want new user name be inserted into the Combox in LoginScreen.Anybody has any clue why the code below does not work correctly .
import javax.swing.*;
import java.awt.*;
public class newUser extends javax.swing.JFrame {
private String allowed = "abcdefghijklmnopqrstuvwxyz_- ";
LoginScreen loginScreen;
private Dimension loginSize;
/** Creates new form AddnewUser */
public newUser() {
initComponents();
setLocationRelativeTo(null);
loginScreen =new LoginScreen();
private void initComponents() {
setLayout(new FlowLayout());
setSize(300, 100);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("AddNew User");
setResizable(true);
jTextField1 = new javax.swing.JTextField();
loginSize = new Dimension(110, 25);//125
jTextField1.setPreferredSize(loginSize);
this.add(jTextField1);
jButton1 = new JButton("OK");
jButton1.setPreferredSize(loginSize);
this.add(jButton1);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String addNew = jTextField1.getText();
String passwors1 ="123";
//here when I invoke postAdd in LoginScreen class
loginScreen.postAdd(addNew,passwors1);
loginScreen.setEnabled(true);
private javax.swing.JButton jButton1;
private javax.swing.JTextField jTextField1;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class LoginScreen extends javax.swing.JFrame {
private ArrayList<String> newUser = new ArrayList<String>();
private Dimension loginSize;
String choice="";
/** Creates new form LoginScreen */
public LoginScreen() {
initComponents();//**
setLocationRelativeTo(null);
initProfiles();
private void initComponents() {//**
setLayout(new FlowLayout());
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setSize(300, 100);
loginSize = new Dimension(110, 25);
jComboBox1 = new javax.swing.JComboBox();
jComboBox1.setPreferredSize(loginSize);
jButton1 = new javax.swing.JButton("OK");
jButton1.setPreferredSize(loginSize);
this.add(jComboBox1);
this.add(jButton1);
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
jButton1.setText("OK");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
* Extracts the profiles from the profile.txt file and inputs them within the combo box.
* Called from the constructor of this class.
void initProfiles()
try {
File f = new File("c:\\JavaPrjImplemention\\javaProject\\profiles.txt");
Scanner filein;
filein = new Scanner(f);
newUser.add("Create New Profile");
while (filein.hasNext())
String temp = filein.nextLine();
newUser.add(temp);
filein.close();
jComboBox1.insertItemAt(newUser.get(0), 0);
for (int i = 1; i < newUser.size(); i++)
{ if(!(newUser.get(i).charAt(0) == '*'))
jComboBox1.insertItemAt(newUser.get(i), (i+1)/2);
catch (FileNotFoundException ex)
Logger.getLogger(LoginScreen.class.getName()).log(Level.SEVERE, null, ex);
//here when I inserted the new user to the combox
void postAdd(String addNew ,String addPassword) {
try
newUser.add(addNew);
String password='*'+addPassword;
newUser.add(password);
int len = newUser.size()/2 ;
jComboBox1.insertItemAt(addNew,len);
PrintWriter filepw;
filepw = new PrintWriter("c:\\JavaPrjImplemention\\javaProject\\profiles.txt");
for (int i = 1; i < newUser.size(); i++)
filepw.println(newUser.get(i));
filepw.close();
catch (FileNotFoundException ex)
Logger.getLogger(LoginScreen.class.getName()).log(Level.SEVERE, null, ex);
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
JComboBox cb = (JComboBox)evt.getSource();
choice = (String)cb.getSelectedItem();
//here new user will be allwoed to enter
//his name by invoking newUser calss
if (choice.equals("Create New Profile"))
newUser addNewuser=new newUser();
addNewuser.setVisible(true);
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LoginScreen().setVisible(true);
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
}1. You have to precisely define "does not work."
2. You have to use code tags to make your code readable. Re-paste it from the original source (not from you post here), highlight it, and clicke the CODE button above the message entry box. -
What is wrong with this trigger code?
Hi folks,
Just wondering whether I might be missing something here about Oracle 9i, that one of you might notice, either from the syntax perspective, or regarding a bug? The code below compiles in the database I have, but the trigger does not fire, and no data is being inserted into the tables. The trigger is owned by sys, and the insert statements are in dynamic sql because I don't want the trigger not to compile if ever the tables are deleted from the b1dev schema.
Incidentally, this same trigger works well on Oracle 10.2.1.0 and Oracle 11.1.0. Any feedback would be much appreciated.
CREATE OR REPLACE TRIGGER cc_LogOff_Trig
BEFORE LogOff ON DATABASE
DECLARE
LogOff_sid PLS_INTEGER;
LogOff_Time DATE := SYSDATE;
Table_1 VARCHAR2(30) := 'CC_SESSION_EVENT_HISTORY';
Table_2 VARCHAR2(30) := 'CC_SESSTAT_HISTORY';
Table_Count NUMBER;
v_sql1 VARCHAR2(4000);
v_sql2 VARCHAR2(4000);
BEGIN
SELECT sId
INTO LogOff_sId
FROM sys.v$MysTat
WHERE ROWNUM < 2;
SELECT COUNT(* )
INTO Table_Count
FROM dba_Objects
WHERE Object_Name = Table_1
AND Object_Type = 'TABLE';
IF Table_Count = 1 THEN
v_sql1 := 'INSERT INTO bdev.cc_session_event_history(sid, serial#, username, osuser, session_process_addr, os_client_process_id, logon_time, type, event, total_waits, total_timeouts, time_waited_csecs,
average_wait_csecs, max_wait_csecs, logoff_timestamp) SELECT se.sid, s.serial#, s.username, s.osuser, s.paddr, s.process, s.logon_time, s.type, se.event, se.total_waits, se.total_timeouts, se.time_waited, se.average_wait,
se.max_wait, '''
||LogOff_Time
||''' FROM sys.v$session_event se, sys.v$session s WHERE se.sid = s.sid AND s.username = '''
||LogIn_User
||''' AND s.sid = '
||LogOff_sId;
EXECUTE IMMEDIATE v_sql1;
END IF;
SELECT COUNT(* )
INTO Table_Count
FROM dba_Objects
WHERE Object_Name = Table_2
AND Object_Type = 'TABLE';
IF Table_Count = 1 THEN
v_sql2 := 'INSERT INTO bdev.cc_sesstat_history(username, osuser, sid, serial#, session_process_addr, os_client_process_id, logon_time, statistic#, name, VALUE, logoff_timestamp) SELECT s.username,
s.osuser, ss.sid, s.serial#, s.paddr, s.process, s.logon_time, ss.statistic#, sn.name, ss.VALUE, '''
||LogOff_Time
||''' FROM sys.v$sesstat ss, sys.v$statname sn, sys.v$session s
WHERE ss.statistic# = sn.statistic# AND ss.sid = s.sid AND sn.name IN(''CPU used when call started'', ''CPU used by this session'', ''recursive cpu usage'', ''parse time cpu'')
AND s.username = '''
||Login_User
||''' AND s.sid = '
||LogOff_sId;
EXECUTE IMMEDIATE v_sql2;
END IF;
COMMIT;
END;
desc cc_session_event_history;
Name Null Type
SID NUMBER
SERIAL# NUMBER
USERNAME VARCHAR2(30)
OSUSER VARCHAR2(30)
SESSION_PROCESS_ADDR RAW(0)
OS_CLIENT_PROCESS_ID VARCHAR2(24)
LOGON_TIME DATE
TYPE VARCHAR2(10)
EVENT VARCHAR2(64)
EVENT# NUMBER
TOTAL_WAITS NUMBER
TOTAL_TIMEOUTS NUMBER
TIME_WAITED_CSECS NUMBER
AVERAGE_WAIT_CSECS NUMBER
MAX_WAIT_CSECS NUMBER
TIME_WAITED_MICRO NUMBER
LOGOFF_TIMESTAMP DATE
17 rows selected
desc cc_sesstat_history;
Name Null Type
USERNAME VARCHAR2(30)
OSUSER VARCHAR2(30)
SID NUMBER
SERIAL# NUMBER
SESSION_PROCESS_ADDR RAW(0)
OS_CLIENT_PROCESS_ID VARCHAR2(24)
LOGON_TIME DATE
STATISTIC# NUMBER
NAME VARCHAR2(64)
VALUE NUMBER
LOGOFF_TIMESTAMP DATE
11 rows selectedI have taken out the 'commit' and have added the 'when others then null' exception clause, but I would imagine there is a better way to do it than this? I don't want to do an insert into another table either. With Oracle 11g, this gives me the compile time warning....
CREATE OR REPLACE TRIGGER cc_LogOff_Trig
BEFORE LogOff ON DATABASE
DECLARE
LogOff_sid PLS_INTEGER;
LogOff_Time DATE := SYSDATE;
Table_1 VARCHAR2(30) := 'CC_SESSION_EVENT_HISTORY';
Table_2 VARCHAR2(30) := 'CC_SESSTAT_HISTORY';
Table_Count NUMBER;
v_sql1 VARCHAR2(4000);
v_sql2 VARCHAR2(4000);
BEGIN
SELECT sId
INTO LogOff_sId
FROM sys.v$MysTat
WHERE ROWNUM < 2;
SELECT COUNT(* )
INTO Table_Count
FROM dba_Objects
WHERE Object_Name = Table_1
AND Object_Type = 'TABLE';
IF Table_Count = 1 THEN
v_sql1 := 'INSERT INTO bdev.cc_session_event_history(sid, serial#, username, osuser, session_process_addr, os_client_process_id, logon_time, type, event, total_waits, total_timeouts, time_waited_csecs,
average_wait_csecs, max_wait_csecs, logoff_timestamp) SELECT se.sid, s.serial#, s.username, s.osuser, s.paddr, s.process, s.logon_time, s.type, se.event, se.total_waits, se.total_timeouts, se.time_waited, se.average_wait,
se.max_wait, '''
||LogOff_Time
||''' FROM sys.v$session_event se, sys.v$session s WHERE se.sid = s.sid AND s.username = '''
||LogIn_User
||''' AND s.sid = '
||LogOff_sId;
EXECUTE IMMEDIATE v_sql1;
END IF;
SELECT COUNT(* )
INTO Table_Count
FROM dba_Objects
WHERE Object_Name = Table_2
AND Object_Type = 'TABLE';
IF Table_Count = 1 THEN
v_sql2 := 'INSERT INTO bdev.cc_sesstat_history(username, osuser, sid, serial#, session_process_addr, os_client_process_id, logon_time, statistic#, name, VALUE, logoff_timestamp) SELECT s.username,
s.osuser, ss.sid, s.serial#, s.paddr, s.process, s.logon_time, ss.statistic#, sn.name, ss.VALUE, '''
||LogOff_Time
||''' FROM sys.v$sesstat ss, sys.v$statname sn, sys.v$session s
WHERE ss.statistic# = sn.statistic# AND ss.sid = s.sid AND sn.name IN(''CPU used when call started'', ''CPU used by this session'', ''recursive cpu usage'', ''parse time cpu'')
AND s.username = '''
||Login_User
||''' AND s.sid = '
||LogOff_sId;
EXECUTE IMMEDIATE v_sql2;
END IF;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;Edited by: efachim on Jan 6, 2009 11:30 AM -
What's wrong with this small code?
hi, there,
I tried to compile the following code and get the error like:
Can't make static reference to non-static reference in line System.out.println(msg);
It is wired to me. Could somebody give a hint? Really appreciate!!!
Jianmin
import java.awt.*;
import java.awt.event.*;
public class fram extends Frame
String msg="hello";
public static void main(String arg[])
fram f=new fram();
Button b=new Button("Click");
b.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println(msg);
f.add(b);
f.pack();
f.show();Thanks a lot!!! it works.
msg is non-static, that is 'instance' variable,
and you can not acces it from static context. Simply
speaking you have to use b.msg, will not work
eather though -
What is wrong with this Java class and method?
Created a managed bean and following method as shown below.
public void setEvent(DisclosureEvent disclosureEvent, CoreShowDetail detail) {
if (disclosureEvent.isExpanded()) {
detail.setDisclosed(!detail.isDisclosed());
-- Then integrated above in the following jspx.
<af:showOnePanel inlineStyle="width:400px;height:300px;"
binding="#{ShowApanel.showOnePanel1}"
id="showOnePanel1">
<af:showDetailItem text="ADF Faces Components"
binding="#{ShowApanel.showDetailItem3}"
id="showDetailItem3" disclosureListener="#{ShowApanel.setEvent}">
<af:panelHeader text="ADF Faces Components First Child"
binding="#{ShowApanel.panelHeader6}"
id="panelHeader6"/>
<af:panelHeader text="ADF Faces Components Second Child"
binding="#{ShowApanel.panelHeader5}"
id="panelHeader5"/>
</af:showDetailItem>
<af:showDetailItem text="Architecture"
binding="#{ShowApanel.showDetailItem2}"
id="showDetailItem2"
disclosureListener="#{ShowApanel.setEvent}">
<af:panelHeader text="Architecture First Child"
binding="#{ShowApanel.panelHeader4}"
id="panelHeader4"/>
<af:panelHeader text="Architecture Second Child"
binding="#{ShowApanel.panelHeader3}"
id="panelHeader3"/>
</af:showDetailItem>
</af:showOnePanel>
THE ISSUE:[b]
I am still not able to programmatically disclose or undisclose the panel component.
Where am I going wrong? Please help.
Thanks,
RuchirHello Frank,
I put several print statments but none of them is executing on browser. Does this mean that the method is not being called even once?
public void setEvent(DisclosureEvent disclosureEvent, CoreShowDetail detail) {
System.out.println("HelloServer Exiting ...");
if (disclosureEvent.isExpanded()) {
System.out.println("HelloServer Exiting1 ...");
// detail.setDisclosed(!detail.isDisclosed());
System.out.println("HelloServer Exiting2 ...");
Thanks,
Ruchir -
What's wrong with this widget code?
Hi everyone,
(I hope this is a good place to put this) I'm trying to build a widget in Dashcode, and one of the things I want to do is run a system command (specifically "ps -ax"). I enabled command line access in the widget attributes, and I now have:
var processes = widget.system("/bin/ps -ax", NULL);
The problem is that "processes" is always undefined. I read on here that there's a bug that if the output is too long, then the variable is undefined. So I tried substituting the command with this:
var processes = widget.system("/bin/ls ~/", NULL);
When I run the command in Terminal, the output is minimal:
Desktop Documents Downloads Library Movies Music Pictures Public Sites
But when I try to run that in Dashcode, it still returns undefined. Am I missing something obvious here?bump I'm still at a standstill with this. Any ideas?
Thanks! -
I can't figure out what's wrong with this code
First i want this program to allow me to enter a number with the EasyReader class and depending on the number entered it will show that specific line of this peom:
One two buckle your shoe
Three four shut the door
Five six pick up sticks
Seven eight lay them straight
Nine ten this is the end.
The error message i got was an illegal start of expression. I can't figure out why it is giving me this error because i have if (n = 1) || (n = 2) statements. My code is:
public class PoemSeventeen
public static void main(String[] args)
EasyReader console = new EasyReader();
System.out.println("Enter a number for the poem (0 to quit): ");
int n = console.readInt();
if (n = 1) || (n = 2)
System.out.println("One, two, buckle your shoe");
else if (n = 3) || (n = 4)
System.out.println("Three, four, shut the door");
else if (n = 5) || (n = 6)
System.out.println("Five, six, pick up sticks");
else if (n = 7) || (n = 8)
System.out.println("Seven, eight, lay them straight");
else if (n = 9) || (n = 10)
System.out.println("Nine, ten, this is the end");
else if (n = 0)
System.out.println("You may exit now");
else
System.out.println("Put in a number between 0 and 10");
I messed around with a few other thing because i had some weird errors before but now i have narrowed it down to just this 1 error.
The EasyReader class code:
// package com.skylit.io;
import java.io.*;
* @author Gary Litvin
* @version 1.2, 5/30/02
* Written as part of
* <i>Java Methods: An Introduction to Object-Oriented Programming</i>
* (Skylight Publishing 2001, ISBN 0-9654853-7-4)
* and
* <i>Java Methods AB: Data Structures</i>
* (Skylight Publishing 2003, ISBN 0-9654853-1-5)
* EasyReader provides simple methods for reading the console and
* for opening and reading text files. All exceptions are handled
* inside the class and are hidden from the user.
* <xmp>
* Example:
* =======
* EasyReader console = new EasyReader();
* System.out.print("Enter input file name: ");
* String fileName = console.readLine();
* EasyReader inFile = new EasyReader(fileName);
* if (inFile.bad())
* System.err.println("Can't open " + fileName);
* System.exit(1);
* String firstLine = inFile.readLine();
* if (!inFile.eof()) // or: if (firstLine != null)
* System.out.println("The first line is : " + firstLine);
* System.out.print("Enter the maximum number of integers to read: ");
* int maxCount = console.readInt();
* int k, count = 0;
* while (count < maxCount && !inFile.eof())
* k = inFile.readInt();
* if (!inFile.eof())
* // process or store this number
* count++;
* inFile.close(); // optional
* System.out.println(count + " numbers read");
* </xmp>
public class EasyReader
protected String myFileName;
protected BufferedReader myInFile;
protected int myErrorFlags = 0;
protected static final int OPENERROR = 0x0001;
protected static final int CLOSEERROR = 0x0002;
protected static final int READERROR = 0x0004;
protected static final int EOF = 0x0100;
* Constructor. Prepares console (System.in) for reading
public EasyReader()
myFileName = null;
myErrorFlags = 0;
myInFile = new BufferedReader(
new InputStreamReader(System.in), 128);
* Constructor. opens a file for reading
* @param fileName the name or pathname of the file
public EasyReader(String fileName)
myFileName = fileName;
myErrorFlags = 0;
try
myInFile = new BufferedReader(new FileReader(fileName), 1024);
catch (FileNotFoundException e)
myErrorFlags |= OPENERROR;
myFileName = null;
* Closes the file
public void close()
if (myFileName == null)
return;
try
myInFile.close();
catch (IOException e)
System.err.println("Error closing " + myFileName + "\n");
myErrorFlags |= CLOSEERROR;
* Checks the status of the file
* @return true if en error occurred opening or reading the file,
* false otherwise
public boolean bad()
return myErrorFlags != 0;
* Checks the EOF status of the file
* @return true if EOF was encountered in the previous read
* operation, false otherwise
public boolean eof()
return (myErrorFlags & EOF) != 0;
private boolean ready() throws IOException
return myFileName == null || myInFile.ready();
* Reads the next character from a file (any character including
* a space or a newline character).
* @return character read or <code>null</code> character
* (Unicode 0) if trying to read beyond the EOF
public char readChar()
char ch = '\u0000';
try
if (ready())
ch = (char)myInFile.read();
catch (IOException e)
if (myFileName != null)
System.err.println("Error reading " + myFileName + "\n");
myErrorFlags |= READERROR;
if (ch == '\u0000')
myErrorFlags |= EOF;
return ch;
* Reads from the current position in the file up to and including
* the next newline character. The newline character is thrown away
* @return the read string (excluding the newline character) or
* null if trying to read beyond the EOF
public String readLine()
String s = null;
try
s = myInFile.readLine();
catch (IOException e)
if (myFileName != null)
System.err.println("Error reading " + myFileName + "\n");
myErrorFlags |= READERROR;
if (s == null)
myErrorFlags |= EOF;
return s;
* Skips whitespace and reads the next word (a string of consecutive
* non-whitespace characters (up to but excluding the next space,
* newline, etc.)
* @return the read string or null if trying to read beyond the EOF
public String readWord()
StringBuffer buffer = new StringBuffer(128);
char ch = ' ';
int count = 0;
String s = null;
try
while (ready() && Character.isWhitespace(ch))
ch = (char)myInFile.read();
while (ready() && !Character.isWhitespace(ch))
count++;
buffer.append(ch);
myInFile.mark(1);
ch = (char)myInFile.read();
if (count > 0)
myInFile.reset();
s = buffer.toString();
else
myErrorFlags |= EOF;
catch (IOException e)
if (myFileName != null)
System.err.println("Error reading " + myFileName + "\n");
myErrorFlags |= READERROR;
return s;
* Reads the next integer (without validating its format)
* @return the integer read or 0 if trying to read beyond the EOF
public int readInt()
String s = readWord();
if (s != null)
return Integer.parseInt(s);
else
return 0;
* Reads the next double (without validating its format)
* @return the number read or 0 if trying to read beyond the EOF
public double readDouble()
String s = readWord();
if (s != null)
return Double.parseDouble(s);
// in Java 1, use: return Double.valueOf(s).doubleValue();
else
return 0.0;
Can anybody please tell me what's wrong with this code? ThanksString[] message = {
"One, two, buckle your shoe",
"One, two, buckle your shoe",
"Three, four, shut the door",
"Three, four, shut the door",
"Five, six, pick up sticks",
"Five, six, pick up sticks",
"Seven, eight, lay them straight",
"Seven, eight, lay them straight",
"Nine, ten, this is the end",
"Nine, ten, this is the end"
if(n>0)
System.out.println(message[n]);
else
System.exit(0);
Maybe you are looking for
-
Hi Team We have our RDP client and i came across with one issue "Expected data got 3" with this client. This issue is getting while connecting some of below operating system flavors. Microsoft Windows 2008 Enterprise edition Microsoft Windows 2008 St
-
Hello, I need to develop a scenario: async ABAP-proxy - > PI <----> sync ABAP-proxy RFC <---- I need to take response from sync interface and put it to RFC. How can I do it?
-
Connecting FIreWire to MACBook PRO
I have a SmartDisk FireLite drive i used on my old MAC for back-ups. It only has a FireWire port. My new MACBook Pro only has USB ports. How do I connect them?
-
Photo/text distorted in slide show mode in iphoto....help!
I have created a photobook in iphoto. When I view it in slideshow mode, the text and photo on both flaps are distorted. None of the other photos or text are distorted. Why is this and will it print like this when I go to buy the book?
-
Hello, I work in a large pre-press department, we store and work from all Windows servers utilizing the AFP/SFM protocol/service on our servers. All Mac users currently mount via AFP. I would like to eliminate AFP/SFM from my servers and work exclusi