0

I am using an Apache Tomcat 5.5 web server (which I'm very new to) on a Windows Server.

I have written a class called HRCapture with a class within it called HR:

package edu.usf.cse.uguard;
import java.util.*;

 public class HRCapture
{
    class HR
    {
        int heartRate;
        Date timeStamp;

        HR (int hr, Date ts)
        {
            heartRate = hr;
            timeStamp = ts;
        }

        HR()
        {

        }
    }
    public HRCapture()
    {
        user = "";
        activity = "";
        typeOfTravel = "";
    }
    public void newHR(int hr, Date ts)
    {
        hrArray.add( new HR(hr, ts));
    }
    public String user, activity, typeOfTravel;
    private ArrayList<HR> hrArray = new ArrayList<HR>();
    double longitude = 0.0;
    double latitude = 0.0;  
}

I compiled it with javac (which gave me "HRCapture.class" and "HRCapture$HR.class") and I put it in: "C:\Program Files\Apache Software Foundatioin\Tomcat5.5\webapps\ROOT\WEB-INF\classes\edu\usf\cse\uguard".

In another file, I'm trying to initialize a variable of type HRCapture:

<%@ page language="java" %>
<%@ page import="edu.usf.cse.uguard.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="org.json.simple.JSONObject" %>
<%@ page import="org.json.JSONArray" %>
<%@ page import="java.util.*" %>
<%@ page import="com.google.gson.*" %>
<%@ page import="com.google.gson.Gson" %>

<%
    HRCapture hrc = new HRCapture();
    if (request.getParameter("id") == null)
    {
    }
    else
    {
        String input = request.getParameter("id");
        Gson gson = new Gson();
        try
        {
            //hrc = gson.fromJson(input , HRCapture.class);
            //out.println(input);
            out.println("Success");
        }
        catch (JsonSyntaxException ex)
        {
        }
        catch (JsonParseException ex)
        {
        }
        catch (Exception e)
        {
        }
    }
%>

However, when I go to the webpage, I get an error saying that "The constructor HRCapture() is not visible" even though I have the constructor set to public within the HRCapture class. This error occurs on line where I have HRCapture hrc = new HRCapture();

I have tried both: <%@ page import="edu.usf.cse.uguard.*" %> and <%@ page import="edu.usf.cse.uguard.HRCapture" %> and I get the same result...

Is my import statement incorrect? Did I screw up the constructor some how?

Any help would be appreciated!

Hebron George
  • 329
  • 1
  • 6
  • 21
  • Well, Apache is on version 7 at the moment, looks like you're somehow lost in time. – Luiggi Mendoza Apr 25 '13 at 22:21
  • I have no control over which version of Tomcat I have to use :( – Hebron George Apr 25 '13 at 22:22
  • Post your code, don't make us go find it. – Dave Newton Apr 25 '13 at 22:22
  • Looks like `HRCapture` class is not public or you're not using the right constructor. – Luiggi Mendoza Apr 25 '13 at 22:22
  • @DaveNewton, I have posted the links to my code already... – Hebron George Apr 25 '13 at 22:23
  • @LuiggiMendoza, If you look at the first paste, you'll see that I have the class as public and there is only one constructor for HRCapture which is also set to public. – Hebron George Apr 25 '13 at 22:24
  • are you sure you have the package for HRCapture imported? – rees Apr 25 '13 at 22:47
  • The thing is that most people here **won't look at code posted outside of your question**, so edit your question and add a [SSCCE](http://sscce.org) of your code in order to help you find the problem. – Luiggi Mendoza Apr 25 '13 at 22:47
  • @LuiggiMendoza @rees I have edited my original post with the important parts of the code in it. @rees I believe I am importing it properly, when I don't try to initialize the class but just make a variable of type HRCapture (for example: `HRCapture myVar;`) there is no error. – Hebron George Apr 25 '13 at 22:56
  • Struggling with Scriptlet in 2013 is [not recommended](http://stackoverflow.com/a/3180202/1037210) at all. It's highly discouraged for over a decade. – Lion Apr 26 '13 at 00:21

2 Answers2

1

The HRCapture you pasted has no package declared.

Just copying the .class file to the given directory within the classes directory isn't going to put it in that package. You should add a package declaration to the java file (and put it in the right directory within your source tree) and compile it again and put it in the right location within the classes directory.

Of course, this assumes you didn't just omit the package declaration from your code sample.

digitaljoel
  • 26,265
  • 15
  • 89
  • 115
  • I had `package edu.usf.cse.uguard;` in my code earlier, which didn't make a difference, so I tried compiling it without the package declaration in case that was the issue and it made no difference. So you're right, I didn't just omit it from the code sample, I actually don't have it in there. I just put the package declaration back in there and it made no difference :( – Hebron George Apr 25 '13 at 23:10
0

So after a lot of testing, it looks like the issue was that Tomcat was caching my class files for some reason and not serving me the newest one always. When I restarted the Tomcat service, it worked without any issues.

Edit: I would mark this as the answer, but I can't for 2 days.

Hebron George
  • 329
  • 1
  • 6
  • 21