The Artima Developer Community
Sponsored Link

Java Answers Forum
Errors please help!

1 reply on 1 page. Most recent reply: Feb 7, 2003 10:29 AM by Mike Penner

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Chris

Posts: 3
Nickname: topagae
Registered: Feb, 2003

Errors please help! Posted: Feb 7, 2003 8:16 AM
Reply to this message Reply
Advertisement
In this program it says all the lines with "readInt" not found in class java.io.DataInputStream. Also it says in the
catch(IOException c) exception java.io.IOException is never thrown in the corresponding try block, I have pointed out the errors so u can see them.





import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class SurveyTest extends Applet implements ActionListener
{
DataInputStream input;
DataOutputStream output;
Label surveyNameLabel = new Label ("NHS Parental Survey");
Label getToWorkLabel = new Label ("Please Ansewer the Questions to the Best of Your Ability");

Checkbox q1 = new Checkbox("q1");
int q1Total=0;
Checkbox q2 = new Checkbox("q2");
int q2Total=0;
Checkbox q3 = new Checkbox("q3");
int q3Total=0;
Checkbox q4 = new Checkbox("q4");
int q4Total=0;
Checkbox q5 = new Checkbox("q5");
int q5Total=0;
Checkbox q6 = new Checkbox("q6");
int q6Total=0;
Checkbox q7 = new Checkbox("q7");
int q7Total=0;
Checkbox q8 = new Checkbox("q8");
int q8Total=0;
Checkbox q9 = new Checkbox("q9");
int q9Total=0;
Checkbox q10 = new Checkbox("q10");
int q10Total=0;
Button submitButton = new Button("Submit Results");
int counter=0;

public void init()
{
setBackground(Color.cyan);
add(surveyNameLabel);
add(getToWorkLabel);

setLayout(new GridLayout(11,1));
Panel panels[]=new Panel[11];
for(int i=0;i<panels.length;++i)
{
panels=new Panel();
panels.setLayout(new FlowLayout(FlowLayout.LEFT));
}
panels[0].add(q1);
panels[1].add(q2);
panels[2] .add(q3);
panels[3].add(q4);
panels[4].add(q5);
panels[5].add(q6);
panels[6].ad d (q7);
panels[7].add(q8);
panels[8].add(q9);
panels[9].add(q10);
panels[10].add( s ubmitButton);
submitButton.addActionListener(this);
for(int i=0;i<panels.length;i++)
{
add(panels);
}
//Open File to read data
try
{
input = new DataInputStream(new FileInputStream("Survey.dat"));
}
catch(IOException ex)
{
System.exit(1);
}
//read data
try
{
input.readInt(q1Total);//Error here
input.readInt(q2Total);//Error here
input.readInt(q3Tota l);//Error here
input.readInt(q4Total);//Error here
input.readInt(q5Total);//Error here
input.readInt(q6Total);//Error here
inpu t.readInt(q7Total);//Error here
input.readInt(q8Total);//Error here
input.readInt(q9Total);//Error here
input.readIn t(q10Total);//Error here
input.readInt(counter);//Error here
}
catch(IOException c)//Error here
{
System.exit(1);
}
}
//Do stuff at button's click
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
try
{
output = new DataOutputStream(new FileOutputStream("Survey.dat"));
}
catch(IOException op)
{
System.exit(1);
}
try
{
q1Total+=toDigit(q1);
q2Total+=toDigit(q2);
q3Tot al+=toDigit(q3);
q4Total+=toDigit(q4);
q5Total+=toDigit(q5);
q6Total+=toDigit(q 6 );
q7Total+=toDigit(q7);
q8Total+=toDigit(q8);
q9Total+=toDigit(q9);
q10Total+= t oDigit(q10);
counter++;
}
catch(Exception cng)
{
System.exit(1);
}
//write data to files
try
{
output.writeInt(q1Total);
output.writeInt(q2Total);
output.writeInt (q3Total);
output.writeInt(q4Total);
output.writeInt(q5Total);
output.writeInt( q 6Total);
output.writeInt(q7Total);
output.writeInt(q8Total);
output.writeInt(q9 T otal);
output.writeInt(q10Total);
output.writeInt(counter);
}
catch(IOException wt)
{
System.exit(1);
}
}
//change checkboxes to int
int toDigit(Checkbox ch)
{
boolean state = ch.getState();
if(state) return (1);
else return (0);
}
}
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class SurveyTest extends Applet implements ActionListener
{
DataInputStream input;
DataOutputStream output;
Label surveyNameLabel = new Label ("NHS Parental Survey");
Label getToWorkLabel = new Label ("Please Ansewer the Questions to the Best of Your Ability");

Checkbox q1 = new Checkbox("q1");
int q1Total=0;
Checkbox q2 = new Checkbox("q2");
int q2Total=0;
Checkbox q3 = new Checkbox("q3");
int q3Total=0;
Checkbox q4 = new Checkbox("q4");
int q4Total=0;
Checkbox q5 = new Checkbox("q5");
int q5Total=0;
Checkbox q6 = new Checkbox("q6");
int q6Total=0;
Checkbox q7 = new Checkbox("q7");
int q7Total=0;
Checkbox q8 = new Checkbox("q8");
int q8Total=0;
Checkbox q9 = new Checkbox("q9");
int q9Total=0;
Checkbox q10 = new Checkbox("q10");
int q10Total=0;
Button submitButton = new Button("Submit Results");
int counter=0;

public void init()
{
setBackground(Color.cyan);
add(surveyNameLabel);
add(getToWorkLabel);

setLayout(new GridLayout(11,1));
Panel panels[]=new Panel[11];
for(int i=0;i<panels.length;++i)
{
panels=new Panel();
panels.setLayout(new FlowLayout(FlowLayout.LEFT));
}
panels[0].add(q1);
panels[1].add(q2);
panels[2] .add(q3);
panels[3].add(q4);
panels[4].add(q5);
panels[5].add(q6);
panels[6].ad d (q7);
panels[7].add(q8);
panels[8].add(q9);
panels[9].add(q10);
panels[10].add( s ubmitButton);
submitButton.addActionListener(this);
for(int i=0;i<panels.length;i++)
{
add(panels);
}
//Open File to read data
try
{
input = new DataInputStream(new FileInputStream("Survey.dat"));
}
catch(IOException ex)
{
System.exit(1);
}
//read data
try
{
input.readInt(q1Total);
input.readInt(q2Total);
input.readInt(q3Tota l);
input.readInt(q4Total);
input.readInt(q5Total);
input.readInt(q6Total);
inp u t.readInt(q7Total);
input.readInt(q8Total);
input.readInt(q9Total);
input.readI n t(q10Total);
input.readInt(counter);
}
catch(IOException c)
{
System.exit(1);
}
}
//Do stuff at button's click
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
try
{
output = new DataOutputStream(new FileOutputStream("Survey.dat"));
}
catch(IOException op)
{
System.exit(1);
}
try
{
q1Total+=toDigit(q1);
q2Total+=toDigit(q2);
q3Tot al+=toDigit(q3);
q4Total+=toDigit(q4);
q5Total+=toDigit(q5);
q6Total+=toDigit(q 6 );
q7Total+=toDigit(q7);
q8Total+=toDigit(q8);
q9Total+=toDigit(q9);
q10Total+= t oDigit(q10);
counter++;
}
catch(Exception cng)
{
System.exit(1);
}
//write data to files
try
{
output.writeInt(q1Total);
output.writeInt(q2Total);
output.writeInt (q3Total);
output.writeInt(q4Total);
output.writeInt(q5Total);
output.writeInt( q 6Total);
output.writeInt(q7Total);
output.writeInt(q8Total);
output.writeInt(q9 T otal);
output.writeInt(q10Total);
output.writeInt(counter);
}
catch(IOException wt)
{
System.exit(1);
}
}
//change checkboxes to int
int toDigit(Checkbox ch)
{
boolean state = ch.getState();
if(state) return (1);
else return (0);
}
}import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class SurveyTest extends Applet implements ActionListener
{
DataInputStream input;
DataOutputStream output;
Label surveyNameLabel = new Label ("NHS Parental Survey");
Label getToWorkLabel = new Label ("Please Ansewer the Questions to the Best of Your Ability");

Checkbox q1 = new Checkbox("q1");
int q1Total=0;
Checkbox q2 = new Checkbox("q2");
int q2Total=0;
Checkbox q3 = new Checkbox("q3");
int q3Total=0;
Checkbox q4 = new Checkbox("q4");
int q4Total=0;
Checkbox q5 = new Checkbox("q5");
int q5Total=0;
Checkbox q6 = new Checkbox("q6");
int q6Total=0;
Checkbox q7 = new Checkbox("q7");
int q7Total=0;
Checkbox q8 = new Checkbox("q8");
int q8Total=0;
Checkbox q9 = new Checkbox("q9");
int q9Total=0;
Checkbox q10 = new Checkbox("q10");
int q10Total=0;
Button submitButton = new Button("Submit Results");
int counter=0;

public void init()
{
setBackground(Color.cyan);
add(surveyNameLabel);
add(getToWorkLabel);

setLayout(new GridLayout(11,1));
Panel panels[]=new Panel[11];
for(int i=0;i<panels.length;++i)
{
panels=new Panel();
panels.setLayout(new FlowLayout(FlowLayout.LEFT));
}
panels[0].add(q1);
panels[1].add(q2);
panels[2] .add(q3);
panels[3].add(q4);
panels[4].add(q5);
panels[5].add(q6);
panels[6].ad d (q7);
panels[7].add(q8);
panels[8].add(q9);
panels[9].add(q10);
panels[10].add( s ubmitButton);
submitButton.addActionListener(this);
for(int i=0;i<panels.length;i++)
{
add(panels);
}
//Open File to read data
try
{
input = new DataInputStream(new FileInputStream("Survey.dat"));
}
catch(IOException ex)
{
System.exit(1);
}
//read data
try
{
input.readInt(q1Total);
input.readInt(q2Total);
input.readInt(q3Tota l);
input.readInt(q4Total);
input.readInt(q5Total);
input.readInt(q6Total);
inp u t.readInt(q7Total);
input.readInt(q8Total);
input.readInt(q9Total);
input.readI n t(q10Total);
input.readInt(counter);
}
catch(IOException c)
{
System.exit(1);
}
}
//Do stuff at button's click
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
try
{
output = new DataOutputStream(new FileOutputStream("Survey.dat"));
}
catch(IOException op)
{
System.exit(1);
}
try
{
q1Total+=toDigit(q1);
q2Total+=toDigit(q2);
q3Tot al+=toDigit(q3);
q4Total+=toDigit(q4);
q5Total+=toDigit(q5);
q6Total+=toDigit(q 6 );
q7Total+=toDigit(q7);
q8Total+=toDigit(q8);
q9Total+=toDigit(q9);
q10Total+= t oDigit(q10);
counter++;
}
catch(Exception cng)
{
System.exit(1);
}
//write data to files
try
{
output.writeInt(q1Total);
output.writeInt(q2Total);
output.writeInt (q3Total);
output.writeInt(q4Total);
output.writeInt(q5Total);
output.writeInt( q 6Total);
output.writeInt(q7Total);
output.writeInt(q8Total);
output.writeInt(q9 T otal);
output.writeInt(q10Total);
output.writeInt(counter);
}
catch(IOException wt)
{
System.exit(1);
}
}
//change checkboxes to int
int toDigit(Checkbox ch)
{
boolean state = ch.getState();
if(state) return (1);
else return (0);
}
}import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class SurveyTest extends Applet implements ActionListener
{
DataInputStream input;
DataOutputStream output;
Label surveyNameLabel = new Label ("NHS Parental Survey");
Label getToWorkLabel = new Label ("Please Ansewer the Questions to the Best of Your Ability");

Checkbox q1 = new Checkbox("q1");
int q1Total=0;
Checkbox q2 = new Checkbox("q2");
int q2Total=0;
Checkbox q3 = new Checkbox("q3");
int q3Total=0;
Checkbox q4 = new Checkbox("q4");
int q4Total=0;
Checkbox q5 = new Checkbox("q5");
int q5Total=0;
Checkbox q6 = new Checkbox("q6");
int q6Total=0;
Checkbox q7 = new Checkbox("q7");
int q7Total=0;
Checkbox q8 = new Checkbox("q8");
int q8Total=0;
Checkbox q9 = new Checkbox("q9");
int q9Total=0;
Checkbox q10 = new Checkbox("q10");
int q10Total=0;
Button submitButton = new Button("Submit Results");
int counter=0;

public void init()
{
setBackground(Color.cyan);
add(surveyNameLabel);
add(getToWorkLabel);

setLayout(new GridLayout(11,1));
Panel panels[]=new Panel[11];
for(int i=0;i<panels.length;++i)
{
panels=new Panel();
panels.setLayout(new FlowLayout(FlowLayout.LEFT));
}
panels[0].add(q1);
panels[1].add(q2);
panels[2] .add(q3);
panels[3].add(q4);
panels[4].add(q5);
panels[5].add(q6);
panels[6].ad d (q7);
panels[7].add(q8);
panels[8].add(q9);
panels[9].add(q10);
panels[10].add( s ubmitButton);
submitButton.addActionListener(this);
for(int i=0;i<panels.length;i++)
{
add(panels);
}
//Open File to read data
try
{
input = new DataInputStream(new FileInputStream("Survey.dat"));
}
catch(IOException ex)
{
System.exit(1);
}
//read data
try
{
input.readInt(q1Total);
input.readInt(q2Total);
input.readInt(q3Tota l);
input.readInt(q4Total);
input.readInt(q5Total);
input.readInt(q6Total);
inp u t.readInt(q7Total);
input.readInt(q8Total);
input.readInt(q9Total);
input.readI n t(q10Total);
input.readInt(counter);
}
catch(IOException c)
{
System.exit(1);
}
}
//Do stuff at button's click
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
try
{
output = new DataOutputStream(new FileOutputStream("Survey.dat"));
}
catch(IOException op)
{
System.exit(1);
}
try
{
q1Total+=toDigit(q1);
q2Total+=toDigit(q2);
q3Tot al+=toDigit(q3);
q4Total+=toDigit(q4);
q5Total+=toDigit(q5);
q6Total+=toDigit(q 6 );
q7Total+=toDigit(q7);
q8Total+=toDigit(q8);
q9Total+=toDigit(q9);
q10Total+= t oDigit(q10);
counter++;
}
catch(Exception cng)
{
System.exit(1);
}
//write data to files
try
{
output.writeInt(q1Total);
output.writeInt(q2Total);
output.writeInt (q3Total);
output.writeInt(q4Total);
output.writeInt(q5Total);
output.writeInt( q 6Total);
output.writeInt(q7Total);
output.writeInt(q8Total);
output.writeInt(q9 T otal);
output.writeInt(q10Total);
output.writeInt(counter);
}
catch(IOException wt)
{
System.exit(1);
}
}
//change checkboxes to int
int toDigit(Checkbox ch)
{
boolean state = ch.getState();
if(state) return (1);
else return (0);
}
}import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class SurveyTest extends Applet implements ActionListener
{
DataInputStream input;
DataOutputStream output;
Label surveyNameLabel = new Label ("NHS Parental Survey");
Label getToWorkLabel = new Label ("Please Ansewer the Questions to the Best of Your Ability");

Checkbox q1 = new Checkbox("q1");
int q1Total=0;
Checkbox q2 = new Checkbox("q2");
int q2Total=0;
Checkbox q3 = new Checkbox("q3");
int q3Total=0;
Checkbox q4 = new Checkbox("q4");
int q4Total=0;
Checkbox q5 = new Checkbox("q5");
int q5Total=0;
Checkbox q6 = new Checkbox("q6");
int q6Total=0;
Checkbox q7 = new Checkbox("q7");
int q7Total=0;
Checkbox q8 = new Checkbox("q8");
int q8Total=0;
Checkbox q9 = new Checkbox("q9");
int q9Total=0;
Checkbox q10 = new Checkbox("q10");
int q10Total=0;
Button submitButton = new Button("Submit Results");
int counter=0;

public void init()
{
setBackground(Color.cyan);
add(surveyNameLabel);
add(getToWorkLabel);

setLayout(new GridLayout(11,1));
Panel panels[]=new Panel[11];
for(int i=0;i<panels.length;++i)
{
panels=new Panel();
panels.setLayout(new FlowLayout(FlowLayout.LEFT));
}
panels[0].add(q1);
panels[1].add(q2);
panels[2] .add(q3);
panels[3].add(q4);
panels[4].add(q5);
panels[5].add(q6);
panels[6].ad d (q7);
panels[7].add(q8);
panels[8].add(q9);
panels[9].add(q10);
panels[10].add( s ubmitButton);
submitButton.addActionListener(this);
for(int i=0;i<panels.length;i++)
{
add(panels);
}
//Open File to read data
try
{
input = new DataInputStream(new FileInputStream("Survey.dat"));
}
catch(IOException ex)
{
System.exit(1);
}
//read data
try
{
input.readInt(q1Total);
input.readInt(q2Total);
input.readInt(q3Tota l);
input.readInt(q4Total);
input.readInt(q5Total);
input.readInt(q6Total);
inp u t.readInt(q7Total);
input.readInt(q8Total);
input.readInt(q9Total);
input.readI n t(q10Total);
input.readInt(counter);
}
catch(IOException c)
{
System.exit(1);
}
}
//Do stuff at button's click
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
try
{
output = new DataOutputStream(new FileOutputStream("Survey.dat"));
}
catch(IOException op)
{
System.exit(1);
}
try
{
q1Total+=toDigit(q1);
q2Total+=toDigit(q2);
q3Tot al+=toDigit(q3);
q4Total+=toDigit(q4);
q5Total+=toDigit(q5);
q6Total+=toDigit(q 6 );
q7Total+=toDigit(q7);
q8Total+=toDigit(q8);
q9Total+=toDigit(q9);
q10Total+= t oDigit(q10);
counter++;
}
catch(Exception cng)
{
System.exit(1);
}
//write data to files
try
{
output.writeInt(q1Total);
output.writeInt(q2Total);
output.writeInt (q3Total);
output.writeInt(q4Total);
output.writeInt(q5Total);
output.writeInt( q 6Total);
output.writeInt(q7Total);
output.writeInt(q8Total);
output.writeInt(q9 T otal);
output.writeInt(q10Total);
output.writeInt(counter);
}
catch(IOException wt)
{
System.exit(1);
}
}
//change checkboxes to int
int toDigit(Checkbox ch)
{
boolean state = ch.getState();
if(state) return (1);
else return (0);
}
}


Mike Penner

Posts: 16
Nickname: mikepenner
Registered: Jan, 2003

Re: Errors please help! Posted: Feb 7, 2003 10:29 AM
Reply to this message Reply
It looks like you're calling readInt incorrectly. It takes no parameters and returns an int. So you should code

q5Total = input.readInt()

instead of

input.readInt(q5Total)

Flat View: This topic has 1 reply on 1 page
Topic: help in java graphics Previous Topic   Next Topic Topic: How to use jdbc:odbc without using ODBC applet in Control Panel??

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use