title: My last java question Problem that even my professor couldn't solve
body: <p>I am writing my last java assignment (Yayy! - thanks to all of you that have helped me through the others).  In this one, I have to write a servlet that takes an age, marital status, house income and number of kids, goes out to a DB, and then returns the updated averages to the user. However, I am encountering <em>this</em> stacktrace:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: HouseSurvey$SurveyResults
      at HouseSurvey.doPost(HouseSurvey.java:23)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:419)
      at org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:169)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      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:868)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
      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(Unknown Source)
  Caused by: java.lang.ClassNotFoundException: HouseSurvey$SurveyResults
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1338)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1187)
      ... 21 more
  </code></pre>
  
  <p>In the past, I have been guilty of posting too much code, not enough code etc. I apologize for my newbishness. Here is the class I have written:</p>
  
  <pre><code>import java.text.DecimalFormat;
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  public class HouseSurvey extends HttpServlet {
      private final static String SURVEY_FILE = "HouseSurvey.dat";
      SurveyResults results;
      Household h;
      DecimalFormat form = new DecimalFormat("#,###,#00.00");
  
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          PrintWriter out = response.getWriter();  //make a printwriter to print the page
          File survey = new File(SURVEY_FILE);
          if (!survey.exists())    //check to see if the file exists
              results = new SurveyResults();
          else {     //If the file exists, read it the latest survey tallies
              try {
                  ObjectInputStream ips = new ObjectInputStream(new FileInputStream(survey));
                  results = (SurveyResults) ips.readObject(); //read the file into 'results'
                  ips.close();   //close the input stream
              } catch (ClassNotFoundException e) {
                  e.printStackTrace();
              } catch (FileNotFoundException f) {
                  f.printStackTrace();
              } catch (IOException ioe) {
                  ioe.printStackTrace();
              }
          }
          int ageValue = Integer.parseInt(request.getParameter("age")),
                  childValue = Integer.parseInt(request.getParameter("children"));
          double incomeValue = Double.parseDouble(request.getParameter("income"));
          Boolean marriedValue;
          if (request.getParameter("status") == "married") {
              marriedValue = true;
          } else {
              marriedValue = false;
          }
          Household h = new Household(ageValue, childValue, incomeValue, marriedValue);
          results.totalResults(h);
          //Write results to disk.
          try {
              ObjectOutputStream ops = new ObjectOutputStream(new FileOutputStream(survey));
              ops.writeObject(results);
              ops.flush();
              ops.close();
          } catch (IOException ioe) {
              ioe.printStackTrace();
          }
          response.setContentType("text/html");       //contnent type for the responding webpage
          out.println("&lt;html&gt;\n" +
                  "&lt;head&gt;&lt;title&gt;Thanks!&lt;/tile&gt;&lt;/head&gt;" +
                  "&lt;body&gt;" +
                  "   &lt;h1 style='text-align:center'&gt;RRC BIT Department - Household Survey&lt;/h1&gt;" +
                  "   &lt;hr&gt;&lt;br/&gt;" +
                  "   &lt;h2 style='text-align:center'&gt;Up to Date Survey Results&lt;/h2&gt;" +
                  "   &lt;h4 style='left-margin:200px'&gt;Average Age: " + results.getAvgAge() +
                  "   &lt;h4 style='left-margin:200px'&gt;Average Number of Children: " + results.getAvgKids() +
                  "   &lt;h4 style='left-margin:200px'&gt;Average Number of Married Respondents: " + results.getAvgKids() +
                  "   &lt;h4 style='left-margin:200px'&gt;Average Number of Single Respondents: " + results.getTotalSingle() +
                  "   &lt;h4 style='left-margin:200px'&gt;Average Income: " + results.getAvgIncome());
      }
  
      private class Household {
          private int age, children;
          private double income;
          private boolean married = false;
  
          /**
           * Method: Household
           * Constructor
           *
           * @ param age - age of person surveyed:int
           * @ param children - number of children person surveyed has:int
           * @ param married - true or false, used to determine married or single:boolean
           * @ param income - the family income of the person surveyed:double
           */
          private Household(int age, int children, double income, boolean married) {
              this.age = age;
              this.children = children;
              this.income = income;
              this.married = married;
          }
  
          //Getters
          private int getAge() {
              return age;
          }
  
          private int getChildren() {
              return children;
          }
  
          private double getIncome() {
              return income;
          }
  
          private boolean getMarried() {
              return married;
          }
      }
  
      private class SurveyResults implements Serializable {
          private double totalAge, totalChildren, totalMarried, totalSingle, totalIncome;
  
          /**
           * Method: SurveyResults
           * Used for totals
           *
           * @ param h - Household object created above:Household
           */
          private void totalResults(Household h) {
              if (h.getMarried()) totalMarried += 1;
              else totalSingle += 1;
              totalAge += h.getAge();
              totalChildren += h.getChildren();
              totalIncome += h.getIncome();
          }
  
          private double getTotalHouseholds() {
              return totalSingle + totalMarried;
          }
  
          private double getAvgAge() {
              return totalAge / getTotalHouseholds();
          }
  
          private double getAvgKids() {
              return totalChildren / getTotalHouseholds();
          }
  
          private double getTotalMarried() {
              return totalMarried;
          }
  
          private double getTotalSingle() {
              return totalSingle;
          }
  
          private double getAvgIncome() {
              return totalIncome / getTotalHouseholds();
          }
      }
  }
  </code></pre>
  
  <p>I thought it was pretty damned close, so I went to ask my instructor.  He looked at it for about 20 minutes, and he couldn't figure it out.</p>
  
  <p>I know that you guys are pretty damned clever (especially when it comes to into stuff), so if any of you could spare a moment to help a brother out.......</p>