Creating an instance of a class from within another class

I am trying to create an instance of MCQ in the T class but I am getting this error:
File: E:\JAVA PROGRAMS\assignment 1\T.java [line: 15]
Error: cannot find symbol
symbol : class MCQ
location: class T
here are the two classes:
// class T
import java.awt.*;
import java.util.*;
import java.lang.*;
public class T{
public T(String aT)
pest = aT;
public static T t_one()
T aT = new T("Calculator");
aT.addQ(new MCQ( " 2 + 2", "equals 4", "equals 5", "equals 0", " equals -2",
"is a prime number", 1));
return aT;
private String pest;
//class Q
import java.awt.*;
import java.util.*;
import java.lang.*;
public abstract class Q{
Vector q = new Vector();
public String aT;
abstract void addQ(Q aQ);
public class MCQ extends Q{
String a,b,c,d,e,f,g;
int answer;
public MCQ (String a, String b, String c, String d, String e, int answer)
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.answer = answer;
void addQ(Q aQ)
q.addElement(new T(aT));
I tried to make reference to MCQ by doing this in class T:
MCC qT = new MCQ() ;
but that presents a whole other set of problems.
please help I think I have tried everything!

Use code tags (http://forum.java.sun.com/help.jspa?sec=formatting)
Don't import java.lang.* . You get those automatically.
Your MCQ class is really Q.MCQ (the way you posted, anyway).
If Q weren't abstract, you could do:
new Q().new MCQ(...)But, you can't create a Q without defining 'add'. You could do it anonymously, but that makes no sense. Put Q and MCQ in separate files and try again.

Similar Messages

  • Calling a java application from within another class

    I have written a working java application that accepts command line parameters through public static void main(String[] args) {} method.
    I'm using webMethods and I need to call myapplication from within a java class created in webMethods.
    I know I have to extend my application class within the webMethods class but I do not understand how to pass the parameters.
    What would the syntax look like?
    Thanks in advance!

    why do you want to call the second class by its main method ??
    Why not have another static method with a meaningfull name and well defined parameters ?
    main is used by the jvm as an entry point in your app. it is not really meant for two java applications to communicate with each other but main and the code is not really readable.
    Have a look at his sample
    double myBalance = Account.getBalance(myAccountId);
    here Account is a class with a static method getBalance which return the balance of the account id you passed.
    and now see this one, here Account has a main method which is implemented to call getBalance.
    String[] args = new String[1];
    args[0] = myAccountId;
    Account.main(args);
    the problem with the code above is
    main doesn't return anything so calling it does do much good. two the code is highly unreadable because no one know what does the main do... unlike the sample before this one where the function name getBalance clearly told what is the function doing without any additional comments.
    hope this helps.... let me know if you need any additional help.
    regards,
    Abhishek.

  • How to reach a method of an object from within another class

    I am stuck in a situation with my program. The current situation is as follows:
    1- There is a class in which I draw images. This class is an extension of JPanel
    2- And there is a main class (the one that has main method) which is an extension of JFrame
    3- In the main class a create an instance(object) of StatusBar class and add it to the main class
    4- I also add to the main class an instance of image drawing class I mentioned in item 1 above.
    5- In the image drawing class i define mousemove method and as the mouse
    moves over the image, i want to display some info on the status bar
    6- How can do it?
    7- Thanks!

    It would make sense that the panel not be forced to understand its context (in this case a JFrame, but perhaps an applet or something else later on) but offer a means of tracking.
    class DrawingPanel extends JPanel {
      HashSet listeners = new HashSet();
      public void addDrawingListener(DrawingListener l) {
         listeners.add(l);
      protected void fireMouseMove(MouseEvent me) {
         Iterator i = listeners.iterator();
         while (i.hasNext()) {
            ((DrawingListener) i.next()).mouseMoved(me.getX(),me.getY());
    class Main implements DrawingListener {
      JFrame frame;
      JLabel status;
      DrawingPanel panel;
      private void init() {
         panel.addDrawingListener(this);
      public void mouseMoved(int x,int y) {
         status.setText("x : " + x + " y: " + y);
    public interface DrawingListener {
      void mouseMoved(int x,int y);
    }Of course you could always just have the Main class add a MouseMotionListener to the DrawingPanel, but if the DrawingPanel has a scale or gets embedded in a scroll pane and there is some virtual coordinate transformation (not using screen coordinates) then the Main class would have to know about how to do the transformation. This way, the DrawingPanel can encapsulate that knowledge and the Main class simply provides a means to listen to the DrawingPanel. By using a DrawingListener, you could add other methods as well (versus using only a MouseMotionListener).
    Obviously, lots of code is missing above. In general, its not a good idea to extend JFrame unless you really are changing the JFrames behavior by overrding methods, etc. Extending JPanel is okay, as you are presumably modifiying the drawing code, but you'd be better off extending JComponent.

  • Request.getParameter("blah") from within a class?

    Hi Everyone,
    Not sure if I'm missing something...
    I'm trying to create a class that will examine and parse information from a form, and then pass it to another class that knows how to handle the input.
    A request in the form of http://www.domain.com/stuff.jsp?1=param1&2=param2&4=param4
    stuff.jsp only has this:
    UrlRequestGetter params = new UrlRequestGetter();
    out.println(params.getTheParams());and the general idea for the UrlRequestGetter class is this:
    public classUrlRequestGetter {
         public String getTheParams(){
              String request1 = request.getParameter("1");
                    String request2 = request.getParameter("2");
                    String request3 = request.getParameter("3");
                    String request4 = request.getParameter("4");
    }Within that class, there will be various actions to check whether or not fields are empty, etc. The big point is that i'm trying to do a request.getparameter from within a class. When i try to compile, I get:
    cannot find symbol
    symbol:variable request
    Any thoughts?
    Thanks!

    Take a step back from all that, and read the error message: cannot find symbol: symbol:variable request
    Is "request" a variable you have declared or passed into your method getTheParams() ?
    Where is it supposed to get the request from?
    "request" is an implicit variable to your JSP. If you want to use it in your bean, you have to pass it as a parameter.
    I'm trying to create a class that will examine and parse information from a form, and then pass it to another class that knows how to handle the input.You might consider using the <jsp:setProperty> tag to map parameters to bean attributes automagically.
    Or the BeanUtils.populate method provided by Jakarta Commons BeanUtils.
    Or any framework like struts, jsf, spring, stripes....
    Cheers,
    evnafets

  • Using System.err.println() from within the classes of WAS ?

    hi,
    I am using admin.jar,a jar file which is being used by Web Application Server in my own class.
    I am referencing some of the classes from admin.jar from my class.
    I tried to print some trace statements,using System.err.println() from within the classes in admin.jar but they did not reflect in defaulttrace0.trc.
    I made these changes in the admin.jar being used by WAS.
    I restarted the server and even restarted the machine but without success.
    I want to know how to print System.out.println() statements from within the classes in admin.jar.
    Also, am i looking for these statements in the right file for eg. defaulttrace0.trc. or is it some other file that i need to look into.
    I need urgent help on this.
    Reward points assured.
    thanks a lot.
    Saurav

    thanks craig,
    ur answer has helped me a lot.but it didnt quite help me.
    nevertheless i am trying to set different levels of severity.
    Is there anything else that i can do.
    Also,i commented out a line of code today in one of the class DataSourceManagerImpl.java in sapj2eenginedeploy.jar
    for eg. temp.delete in it deploy method.Buth that line still executed.
    I m totally lost as to wht to do.
    I m trying to create a datasource from my application in WAS.For that i m using the WAS APIs.But its not working completely.
    I am using the above jar and its method createdatasource.
    I am callin it from my application's class.
    It creates a datasource and i can see it in JDBC Connector list in Visual Administrator.But it appears with red sign meaning its not started.When i start it from the tool then it starts.
    But in defaulttrace.trc file it shows an error "FileNotFindException". This happens,and i am very much sure, in the deploy() of DataSourceManagerImpl.java class of sapj2eenginedeploy.jar.
    i want to apply println inside this method so i may know where exactly i ma getting the error and get so more info so i may solve my problem.
    pls help me.
    its really urgent.
    thanks again
    saurav

  • Is it possible to call methods from another class from within an abstract c

    Is it possible to call methods from another class from within an abstract class ?

    I found an example in teh JDK 131 JFC that may help you. I t is using swing interface and JTable
    If you can not use Swing, then you may want to do digging or try out with the idea presented here in example 3
    Notice that one should refine the abstract table model and you may want to create a method for something like
    public Object getValuesAtRow(int row) { return data[row;}
    to give the desired row and leave the method for
    getValuesAt alone for getting valued of particaular row and column.
    So Once you got the seelcted row index, idxSelctd, from your table
    you can get the row or set the row in your table model
    public TableExample3() {
    JFrame frame = new JFrame("Table");
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}});
    // Take the dummy data from SwingSet.
    final String[] names = {"First Name", "Last Name", "Favorite Color",
    "Favorite Number", "Vegetarian"};
    final Object[][] data = {
         {"Mark", "Andrews", "Red", new Integer(2), new Boolean(true)},
         {"Tom", "Ball", "Blue", new Integer(99), new Boolean(false)},
         {"Alan", "Chung", "Green", new Integer(838), new Boolean(false)},
         {"Jeff", "Dinkins", "Turquois", new Integer(8), new Boolean(true)},
         {"Amy", "Fowler", "Yellow", new Integer(3), new Boolean(false)},
         {"Brian", "Gerhold", "Green", new Integer(0), new Boolean(false)},
         {"James", "Gosling", "Pink", new Integer(21), new Boolean(false)},
         {"David", "Karlton", "Red", new Integer(1), new Boolean(false)},
         {"Dave", "Kloba", "Yellow", new Integer(14), new Boolean(false)},
         {"Peter", "Korn", "Purple", new Integer(12), new Boolean(false)},
         {"Phil", "Milne", "Purple", new Integer(3), new Boolean(false)},
         {"Dave", "Moore", "Green", new Integer(88), new Boolean(false)},
         {"Hans", "Muller", "Maroon", new Integer(5), new Boolean(false)},
         {"Rick", "Levenson", "Blue", new Integer(2), new Boolean(false)},
         {"Tim", "Prinzing", "Blue", new Integer(22), new Boolean(false)},
         {"Chester", "Rose", "Black", new Integer(0), new Boolean(false)},
         {"Ray", "Ryan", "Gray", new Integer(77), new Boolean(false)},
         {"Georges", "Saab", "Red", new Integer(4), new Boolean(false)},
         {"Willie", "Walker", "Phthalo Blue", new Integer(4), new Boolean(false)},
         {"Kathy", "Walrath", "Blue", new Integer(8), new Boolean(false)},
         {"Arnaud", "Weber", "Green", new Integer(44), new Boolean(false)}
    // Create a model of the data.
    TableModel dataModel = new AbstractTableModel() {
    // These methods always need to be implemented.
    public int getColumnCount() { return names.length; }
    public int getRowCount() { return data.length;}
    public Object getValueAt(int row, int col) {return data[row][col];}
    // The default implementations of these methods in
    // AbstractTableModel would work, but we can refine them.
    public String getColumnName(int column) {return names[column];}
    public Class getColumnClass(int col) {return getValueAt(0,col).getClass();}
    public boolean isCellEditable(int row, int col) {return (col==4);}
    public void setValueAt(Object aValue, int row, int column) {
    data[row][column] = aValue;
    };

  • Adding custom css classes from within edge animate

    is it possible to add  CSS classes from within Edge Animate, im not talking about adding your own stylesheet by ex. manually editing the .html document, but rather adding classes via ex. the code window ?, it would be immensely helpful to have everything in one place.
    any suggestions on this one ?

    Yes - you can use addclass() and you can use UI.
    1- UI
    Select elements in elements panel. Click the C button in the property panel.
    Use this for example
    sym.$('.classname').css({'color':'red'});
    2- addclaas()
    sym.$("name').addclass('classname');
    Use same as above.
    On Sat, Apr 25, 2015 at 8:56 AM mads18950258 <[email protected]>

  • Initialize/set a base class from a another base class instance

    Hi,
    How can I initialize/set a base class from a another base class instance? I do not want to do a copy of it.
    It would look something like:
    class A {...}
    class B extends A
        B(A a)
            // super = a;
        setA(A a)
            // super = a;
    }Thank you.

    erikku wrote:
    Thanks Winton. It is what I did first but A has lots of methods and if methods are later added to A, I will have to edit B again. For those two reasons, I wanted to use inheritance. The part I was not sure with was the way to initialize B's base (A).You pays your money and you takes your choice. One way (this way) you have to provide forwarders; the other way (inheritance) you have to provide constructors (and if A has a lot of em, you may be writing quite a few).
    Ask yourself this question: is every B also an A? No exceptions. Ever.
    If the answer is 'yes', then inheritance is probably the best way to go.
    However, if there is even the remotest chance that an instance of B should not exhibit 100% of the behaviour of A, now or in the future, then the wrapper style is probably what you want.
    Another great advantage of the wrapper style is that methods can be added to A without affecting the API for B (unless you want to).
    Winston
    PS: If your Class A has a constructor or constructors that take a pile of parameters, you might also want to look at the Builder pattern. However, that's not really what we're talking about here, and it should probably be implemented on A anyway.

  • Need help to call a simple function from within another function?

    I created a movieclip which has a function in its one and only frame.
    function testx() {
    x = x+2};
    This movieclip is in the main timeline (in its own layer).
    In another layer on the timeline I have created a single keyframe with a button instance called myBtn
    myBtn.onRelease = function() {
    var x
    x =2
    testx(2);
    trace (x);
    What I want to do is call the function in the movieclip frame from the button press function. However, I can't seem to reference it properly.
    Can anyone help me to basically call a simple function from within another function?

    Yes am using CS4.  Have saved it as CS3 now.  Ok the file is somewhat complicated and what I am testing is not what I ultimately want to do but if I can pass that variable I can figure it out.  In terms of describing the file I think the only parts of importance are what I put in my previous post (please let me know if there is something I should be telling you that I have missed).  I am 99.9% sure that I am using the correct instance name.
    Scene1 Layer3 Frame1 has the function call for the button.
    myBtn.onRelease = function() {
    var x
    x = 2
    testx(2);
    trace (x);
    Slideshow layer //Actions Frame1 has the function
    function testx(x) {
    x = x+2};
    thank you so much for helping me.

  • PL/SQL: Executing a procedure from within another procedure

    Hello, I'm a newbie and I need help on how to execute procedures from within another procedure. The procedure that I call from within the procedure have return values that I want to check.
    I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    but I get the error message:
    PLS-00103: Encountered the symbol "USER_GET_FORUM_INFO" when expecting one of the following::= . ( @ % ; immediate
    The symbol ":=" was substituted for "USER_GET_FORUM_INFO" to continue.
    And when I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    I get the error message:
    PLS-00222: no function with name 'USER_GET_FORUM_INFO' exists in this scope
    PL/SQL: Statement ignored
    The procedure USER_GET_FORUM_INFO exists. (don't understand why it says "no FUNCTION with name", it's a procedure I'm executing)
    I'm stuck so thanks for any help...
    Below is all the code. I'm using Oracle 9i on RedHat Linux 7.3.
    ================================================================================
    CREATE OR REPLACE PROCEDURE user_forum_requestsaccess (
    p_forumid IN NUMBER,
    p_requestmessage IN VARCHAR2
    AS
    var_forumid NUMBER;
    var_forum_exists NUMBER;
    var_forum_access NUMBER;
    request_exists NUMBER;
    var_forumname VARCHAR2(30);
    FORUM_DOESNT_EXIST EXCEPTION;
    FORUM_USER_HAS_ACCESS EXCEPTION;
    FORUM_REQUEST_EXIST EXCEPTION;
    BEGIN
    SELECT SIGN(NVL((SELECT request_id FROM forum.vw_all_forum_requests WHERE forum_id = p_forumid AND db_user = user),0)) INTO request_exists FROM DUAL;
    EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    IF var_forum_exists = 0 THEN
    RAISE FORUM_DOESNT_EXIST;
    ELSIF var_forum_access = 1 THEN
    RAISE FORUM_USER_HAS_ACCESS;
    ELSIF request_exists = 1 THEN
    RAISE FORUM_REQUEST_EXIST;
    ELSE
    INSERT INTO tbl_forum_requests VALUES (SEQ_TBL_FORUM_REQ_REQ_ID.NEXTVAL, SYSDATE, p_requestmessage, p_forumid, user);
    INSERT INTO tbl_forum_eventlog VALUES (SEQ_TBL_FORUM_EVNTLOG_EVNT_ID.NEXTVAL,SYSDATE,1,'User ' || user || ' requested access to forum ' || var_forumname || '.', p_forumid,user);
    COMMIT;
    END IF;
    EXCEPTION
    WHEN
    FORUM_DOESNT_EXIST
    THEN RAISE_APPLICATION_ERROR(-20003,'Forum doesnt exist.');
    WHEN
    FORUM_USER_HAS_ACCESS
    THEN RAISE_APPLICATION_ERROR(-20004,'User already have access to this forum.');
    WHEN
    FORUM_REQUEST_EXIST
    THEN RAISE_APPLICATION_ERROR(-20005,'A request to this forum already exist.');
    END;
    GRANT EXECUTE ON user_forum_requestsaccess TO forum_user;
    ================================================================================
    Regards Goran

    you don't have to use execute when you want to execute a procedure (only on sql*plus, you would use it)
    just give the name of the funtion
    create or replace procedure test
    as
    begin
        dbms_output.put_line('this is the procedure test');
    end test;
    create or replace procedure call_test
    as
    begin
        dbms_output.put_line('this is the procedure call_test going to execute the procedure test');
        test;
    end call_test;
    begin
        dbms_output.put_line('this is an anonymous block calling the procedure call_test');
        call_test;
    end;
    /

  • Invoke a method in one class from a different class

    I am working on a much larger project, but to keep this simple, I wrote out a little test that would convey the over all theory of the program.
    What I am doing is starting out with a 2 JFrames and a Class. When the program is launched, the first JFrame opens. In this JFrame is a label and a button. When the button is clicked, the second JFrame opens. This JFrame has a textField and a button. The user puts the text in the textField and presses the button. When the button is pushed, I want the text that was just put in the textField, to be displayed in the first JFrame's label. I am trying to invoke a method in the first JFrame from the second, but nothing happens. I have also tried making the Class extend from JFrame1 and invoke it from there, but no luck. So, how do I invoke a method in a class from a different class?
    JFrame1 (I omitted the layout part. I made this in Netbeans so its pretty long)
    public class NewJFrame1 extends javax.swing.JFrame {
         private NewClass1 nC = new NewClass1();
         /** Creates new form NewJFrame1 */
         public NewJFrame1() {
              initComponents();
              jLabel1.setText("Chuck");
         public void setLabels()
              jLabel1.setText(nC.getName());
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewJFrame2 j2 = new NewJFrame2();
         j2.setVisible(true);The class
    public class NewClass1 {
         public static String name;
         public NewClass1()
         public NewClass1(String n)
              name = n;
         public String getName()
              return name;
         public void setName(String n)
              name = n;
    }The second jFrame
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewClass1 nC = new NewClass1();
         NewJFrame1 nF = new NewJFrame1();     
         nC.setName(jTextField1.getText());
         nF.setLabels();
         System.out.println(nC.getName());At this point I am begging for help. I have been trying for days to figure this out, and I just feel like I am not getting anywhere.
    Thanks

    So, how do I invoke a method in a class from a different class?Demo:
    public class Main {
        public static void main(String [] args) {
         Test1 t1 = new Test1();
         Test2 t2 = new Test2();
         int i = t1.method1();
         String s = t2.method2(i);
         System.out.println(s);
    class Test1 {
        public int method1() {
         return 10;
    class Test2 {
        public String method2(int i) {
         if (i == 10)
             return "ten";
         else
             return "nothing";
    }Output is "ten".
    Edited by: newark on May 28, 2008 10:55 AM

  • Accessing private attribute of a class from its Friend Class

    Hi Experts ,
    Please help me to understand how can i access private attribute of one class from its friend class.
    I am coding in Method (DO_SAVE) of class /BOBF/CL_TRA_TRANSACTION_MGR.
    I need to access private variable ( MO_BOPF) of class /BOBF/CL_TRA_SERVICE_MGR ( Friend of /BOBF/CL_TRA_TRANSACTION_MGR ).
    Regards,
    Reny Richard

    Hi Reny,
    You should be able to access by creating object of friend class.
    Sample:
    data lo_frnd     TYPE REF TO  /BOBF/CL_TRA_SERVICE_MGR.
    data lo_compl  type REF TO /BOBF/IF_TRA_TRANS_MGR_COMPL.
       create OBJECT lo_frnd
         exporting
                   iv_bo_key = '111'
                   IO_COMPL_TRANSACTION_MANAGER = lo_compl.
    "access the private object of friend class
       clear lo_frnd->MO_BOPF.
    Note: need to provide iv_bo_key & IO_COMPL_TRANSACTION_MANAGER while creating object.
    Hope this helps you.
    Regards,
    Rama

  • How to access private attribute of a class from its Friend Class

    Hi Experts ,
    I am coding in Method (DO_SAVE) of class /BOBF/CL_TRA_TRANSACTION_MGR.
    I need to access private variable ( MO_BOPF) of class /BOBF/CL_TRA_SERVICE_MGR ( Friend of /BOBF/CL_TRA_TRANSACTION_MGR ).
    Please help me to understand how can i access private attribute of one class from its friend class.
    Regards- Abhishek

    Hi Reny,
    You should be able to access by creating object of friend class.
    Sample:
    data lo_frnd     TYPE REF TO  /BOBF/CL_TRA_SERVICE_MGR.
    data lo_compl  type REF TO /BOBF/IF_TRA_TRANS_MGR_COMPL.
       create OBJECT lo_frnd
         exporting
                   iv_bo_key = '111'
                   IO_COMPL_TRANSACTION_MANAGER = lo_compl.
    "access the private object of friend class
       clear lo_frnd->MO_BOPF.
    Note: need to provide iv_bo_key & IO_COMPL_TRANSACTION_MANAGER while creating object.
    Hope this helps you.
    Regards,
    Rama

  • Fire event from within another event ?

    It seems that an event fired from within another event does not
    actually execute its code until the firing event completes. The fired
    event's Time value in its Event Data Node indicates the time that it
    was told to execute, but using GetTickCount calls shows that its code
    does not execute until the firing event is finished. This happens
    whether Value Signaling is used to generate a Value Change event or if
    CreateUserEvent and GenerateUserEvent is used. Is this because events
    are placed in a queue ? This behavior is different from Delphi for
    example where the fired event executes right away when called from the
    firing event (before the firing event completes).
    I have an event that executes upon a button value change. I would
    like that same event's code to execute when another button is pressed,
    but also have other code in the second button's event execute after
    that first button's event's code completes. Is there another way to
    accomplish this ?
    Steve

    > It seems that an event fired from within another event does not
    > actually execute its code until the firing event completes. The fired
    > event's Time value in its Event Data Node indicates the time that it
    > was told to execute, but using GetTickCount calls shows that its code
    > does not execute until the firing event is finished. This happens
    > whether Value Signaling is used to generate a Value Change event or if
    > CreateUserEvent and GenerateUserEvent is used. Is this because events
    > are placed in a queue ? This behavior is different from Delphi for
    > example where the fired event executes right away when called from the
    > firing event (before the firing event completes).
    I'm not that familiar with Delphi, but LV events are asynchronous.
    Window
    s OS has two ways of firing events, Send and Post. The LV events
    are always posted. The primary reason is that the LV events are handled
    by a node, not by a callback. The node you are calling is in the middle
    of a diagram, and reentering it not valid.
    > I have an event that executes upon a button value change. I would
    > like that same event's code to execute when another button is pressed,
    > but also have other code in the second button's event execute after
    > that first button's event's code completes. Is there another way to
    > accomplish this ?
    The best way to reuse code is to use subVIs. Firing events, or rather
    sending events is pretty close in other events to making a function call
    dispatched to anyone interested in the event. The event just hides who
    you are calling and makes you put your parameters in a funny format
    stuffed inside the event. IMO it also makes the code very hard to read
    since you don't know what calls what.
    Instead, just put the code into a sub
    VI and call it whenever you need
    to, from the event structure in one or more locations, and from other
    loops and diagrams.
    Greg McKaskle

  • Reading files from within helper classes

    From within a servlet, I can get the servlet context to get a path to the "web" directory of my project and easily access properties files for my project. If I create another package in my project to hold helper classes that perform some specific function and want to create and/or read from a properties file, I get a path to the bin directory of my servlet container:
    Servlet Path: D:\Documents and Settings\Josh\My Documents\Josh\Projects\ServletSandBox\build\web\
    Helper Class File Path: D:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.14\bin\test
    I'd like to develop my helper packages as reusable APIs, so they're not tied directly to my project or to a servlet in general, but I'd like the properties files to stay somewhere in my project folder, preferably in the WEB-INF directory with the servlet's own specific properties file.
    I can't figure out the best way to handle this. I wanted to just be able to pass the helper class a String if somebody wanted to specify a filename other than the default filename. Does it make sense to specify a file URL instead? Is there any other way to get the calling servlet's context path without having to pass in a variable?
    Thanks

    It seems that the helper API shouldn't need to be given a path to its own config file. I would like to have code that will load the file regardless of whether or not its in a stand alone java app or a servlet. Whenever the helper API is jarred up and imported into my servlet, it can't find the config file unless it's in the "D:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.14\bin\test" directory. OR, if I use the current thread to get the loader, it will locate it in the "classes" folder, which is the only solution I can come up with that will let me write code to load the file that will work, regardless of its implementation.
    The "project" folder I'm talking about is just the NetBeans "project" folder for the servlet, or the "ServetSandBox" folder in my example. I guess that doesn't really matter in the context of the servlet though.
    So is using the current thread the appropriate way to do this? When you say that code will work if I put the resource in the WEB-INF directory, that seems to only be true if I try to load it from the servlet itself, not the helper class. The helper class doesn't find the resource in the WEB-INF directory.
    Also, I would like to be able to write the default values to a new config file if one doesn't exist. How in the heck do I get a pointer to the "classes" folder, or any other folder that I can also read from using the classloader, so I can write to a new file?

Maybe you are looking for

  • Help, my mac keeps crashing every time i try update Xcode

    Every time i try update Xcode to the 4.6 update my mac crashes and i have to restart the download, any tips on what to do to prevent this or whether i just need to get it serviced, i have a feeling that its because its overheating but im never at my

  • Where should I issue this command

    Hi all, I'm configuring a logical standby database (Oracle 10g R2 on Linux 4.5). In the steps, I should convert to a Logical Standby Database and thus the following command should be issued: ALTER DATABASE RECOVER TO LOGICAL STANDBY db_name;My questi

  • Register BI Publisher report in Oracle Apps

    Hi, I wanted to know, if we can register a BI Publisher report in Oracle Apps. Please note that this is BI publisher Release 10.1.3.4...I am not using any rdf here. Thanks, As

  • Flat file load changes in key figures

    Hello, I have a weird issue when i try to load some data into a cube(Flat File) with 1900 records only 1668 records gets loaded into the cube and also when i try to validate it the numbers doesnt match.Can you guys suggest me if i am missing anything

  • Trackpoint driver works differently than the older one

    I made the jump recently from Vista 32 to 64 and after  installing drivers i noticed that i can no longer tap the trackpoint instead of left click - have you guys noticed that ?