Referencing LOCAL SCOPE varible of outter class

From inner class, I can reference the outter's class variable by OutterClassName.this.variableName. However, the variableName has LOCAL SCOPE, how do I access it?
Code sample:
for(int i=0; i<m_keyButton.length; i++)
m_keyButton.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
if(m_keyButton[1].isEnabled())
m_feedbackScroll.setViewportView(m_mouseOverKeyImagePanel[i]);
Referencing i in m_mouseOverKeyImagePanel[i] causes an compile error:
"Acuity.java": local variable i is accessed from within inner class; needs to be declared final at line ...
Any quick solution? thanks a bunch.

The reason it has to be final is b'cos anonymous class
needs to know exactly what the value of i is at
compile-time. Unlike normal and inner classes, which
you could pass in the value via the constructor or
setter method at runtime, the only time for anonymous
classes could know the value is at compile-time.It's not really compile time. Adding the mouse listeners happens on the main thread. The code inside the listener runs on the event thread. The compiler just wants to make sure the variable isn't going to be changed by one thread or the other.
BTW: if(m_keyButton[j].isEnabled()) is kind of redundant. If the button isn't enabled, you won't get mouse events.

Similar Messages

  • Weblogic 10.3.2 EJB3 Local Interface in POJO/Helper classes

    Hi,
    I have a jar file containing all EJB's in application & some Helper classes. I want to access Local interfaces of EJBs in those helper classes. Is there any way I can do it? I've gone through Maxence Button & Jay SenSharma 's blogs about accessing Local interface. but it doesn't help. May be these two guys can help me more here.. My requirement is very simple. Just to access local interface in POJO/Helper classes that are in same JAR file as EJB's. I can't get reference with @EJB class level annotation as Helper classes are called independently from MBean services.. not from any EJB or Servlert.
    Please if anyone can tell me how do I get reference of local interfaces, that would be really good.
    my environment is
    Weblogic 10.3.2
    EJB3
    Regards,
    Prasad

    Hi,
    Just check ...If you want something like mentioned in the below Link with a complete Example:
    [http://jaysensharma.wordpress.com/2009/08/16/weblogic-10-3-ejb3-local-lookup-sample/|http://jaysensharma.wordpress.com/2009/08/16/weblogic-10-3-ejb3-local-lookup-sample/]
    Regards
    Jay SenSharma

  • How to access var in outter class inside inner class

    I've problem with this, how to access var number1 and number2 at outter class inside inner class? what statement do i have to use to access it ? i tried with " int number1 = Kalkulator1.this.number1; " but there no value at class option var y when the program was running...
    import java.io.*;
    public class Kalkulator1{
    int number1,number2,x;
    /* The short way to create instance object for input console*/
    private static BufferedReader stdin =
    new BufferedReader( new InputStreamReader( System.in ) );
    public static void main(String[] args)throws IOException {
    System.out.println("---------------------------------------");
    System.out.println("Kalkulator Sayur by Cumi ");
    System.out.println("---------------------------------------");
    System.out.println("Tentukan jenis operasi bilangan [0-4] ");
    System.out.println(" 1. Penjumlahan ");
    System.out.println(" 2. Pengurangan ");
    System.out.println(" 3. Perkalian ");
    System.out.println(" 4. Pembagian ");
    System.out.println("---------------------------------------");
    System.out.print(" Masukan jenis operasi : ");
    String ops = stdin.readLine();
         int numberops = Integer.parseInt( ops );
    System.out.print("Masukan Bilangan ke-1 : ");
    String input1 = stdin.readLine();
    int number1 = Integer.parseInt( input1 );
    System.out.print("Masukan Bilangan ke-2 : ");
    String input2 = stdin.readLine();
    int number2 = Integer.parseInt( input2 );     
         Kalkulator1 op = new Kalkulator1();
    Kalkulator1.option b = op.new option();
         b.pilihan(numberops);
    System.out.println("Bilangan yang dimasukkan adalah = " + number1 +" dan "+ number2 );
    class option{
    int x,y;
         int number1 = Kalkulator1.this.number1;
         int number2 = Kalkulator1.this.number2;
    void pilihan(int x) {
    if (x == 1)
    {System.out.println("Operasi yang digunakan adalah Penjumlahan");
            int y = (number1+number2);
            System.out.println("Hasil dari operasi adalah = " + y);}
    else
    {if (x == 2) {System.out.println("Operasi yang digunakan adalah Pengurangan");
             int y = (number1-number2);
             System.out.println("Hasil dari operasi adalah = " + y);}
    else
    {if (x == 3) {System.out.println("Operasi yang digunakan adalah Perkalian");
             int y = (number1*number2);
             System.out.println("Hasil dari operasi adalah = " + y);}
    else
    {if (x == 4) {System.out.println("Operasi yang digunakan adalah Pembagian ");
             int y = (number1/number2);
             System.out.println("Hasil dari operasi adalah =" + y);}
    else {System.out.println( "Operasi yang digunakan adalah Pembagian ");
    }

    Delete the variables number1 and number2 from your inner class. Your inner class can access the variables in the outer class directly. Unless you need the inner and outer class variables to hold different values then you can give them different names.
    In future place code tags around your code to make it retain formatting. Highlight code and click code button.

  • Scope of a java class in JSP page

    Hi
    If I use a java bean using the
    <jsp:useBean
    id="beanSomeName"
    scope="page|request|session|applicaton
    I can specify the scope of of the bean after which I can assume it is Garbage Collected.
    However if I just create a new Java Class in a jsp bean ( I inherited this code ) what will be scope of this java class. When will it be Garbage collected.
    Is it Page scope?
    Thanks
    bib/-

    If you do
    <% MyClass c = new MyClass(); %>
    and don't do anything else to store it in the request or session than it is like page scope.
    if you do
    <%! MyClass c = new MyClass(); %>
    it is more like application scope.

  • Catch-22: need to assign a local variable within an anonymous class

    static boolean showMessage(Window parent, String button0, String button1)
        throws HeadlessException {
              final Window w = new Window(parent);
              Panel p = new Panel(new GridBagLayout());
              final Button b[] = new Button[]{new Button(button0), (button1 != null) ? new Button(button1) : (Button)null};
              boolean rval[]; //tristate: null, true, false
              w.setSize(100, 50);
              w.setVisible(true);
              //add b[0
              gbc.fill = GridBagConstraints.HORIZONTAL;
              gbc.gridx = 0;
              gbc.gridy = 3;
              p.add(b[0], gbc);
              //add b[1]
              if (button1 != null) {
                   gbc.fill = GridBagConstraints.HORIZONTAL;
                   gbc.gridx = 1;
                   gbc.gridy = 3;
                   p.add(b[1], gbc);
              w.add(p);
              w.pack();
            w.setVisible(true);
            //actionListener for button 0
              b[0].addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             if (e.getSource() == b[0]) {
                                  w.setVisible(false);
                                  rval = new boolean[1];
                                  rval[0] = true;
              //actionListener for button 1
              if (button1 != null) {
                   b[1].addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent e) {
                                  if (e.getSource() == b[1]) {
                                       w.setVisible(false);
                                       rval = new boolean[1];
                                       rval[0] = false;
            while (true) {
                 try {
                      if (rval[0] == true || rval[0] == false) //should trigger NullPointerException
                           return rval[0];
                 } catch (NullPointerException e) { }
         }catch-22 is at
    rval = new boolean[1];
    rval = false;javac whines: "local variable rval is accessed from within inner class; needs to be declared final"
    How do I assign to rval if it's declared final?
    Or at the very least, how do I get rid of this error (by all means, hack fixes are okay; this is not C/C++, I don't have to use sanity checks)?
    I'm trying to make a messagebox in java without using JOptionPane and I'm trying to encapsulate it in one method.
    And I'm far too lazy to make a JNI wrapper for GTK.

    dcminter wrote:
    How do I assign to rval if it's declared final?You don't and you can't. You're not allowed to assign to the local variable of the outer class for extremely good reasons, so forget about trying.
    Or at the very least, how do I get rid of this errorIf you don't want the side effect, then just use an inner class variable or a local variable.
    If you want the side effect then use a named class and provide it with a getter and setter.
    Finally, in this specific case because you're using an array object reference, you could probably just initialise the array object in the outer class. I.e.
    // Outer class
    final boolean[] rval = new boolean[1];
    // Anonymous Inner class
    rval[0] = true; // No need to intialize the array.
    I declared it as an array so that it would be a tristate boolean (null, true, false) such that accessing it before initialization from the actionPerformed would trigger a NullPointerException.
    Flowchart:
    is button pressed? <-> no
    |
    V
    Yes->set and return
    Is there a way to accomplish this without creating a tribool class?

  • BPEL designer bug changing local scope variables

    My appologies if this was already known.
    I am using bpelz version 0.9.10 and encountered the following bug:
    When I use the BPEL Inspector to change the XML variable name in a scope (the variable is defined locally in the scope), the name change occurs in other scopes (including leaf scopes not in the local scope chain).
    Perhaps I am using to old a version and this has been fixed.
    Cheers,
    -Dustin

    Thanks a lot Dustin. I will check it and communicate the same to dev team.

  • Local variable accessed within inner class

    Hey everybody,
    My program keeps telling me that it wont work because one of my methods is calling a local variable inside an inner class. Does anyone know what this means and how to fix it?
    Heres the code:
    public class SliderExample extends JPanel{
    int value=0;
    public SliderExample(int imw, int imh, Image img, BufferedImage buf, Graphics2D biCon){
    super(true);
    this.setLayout(new BorderLayout());
    JSlider slider= new JSlider(JSlider.HORIZONTAL,0,imw,25);
    slider.setMinorTickSpacing(10);
    slider.setMajorTickSpacing(100);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    JButton redraw= new JButton("Scroll");
    redraw.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ev){
    reDraw(slider,img,buf,biCon,imw,imh);
    add(slider,BorderLayout.CENTER);
    add(redraw,BorderLayout.AFTER_LINE_ENDS);
    public void reDraw(JSlider slid, Image im, BufferedImage bf, Graphics2D biC, int iw, int ih){
    value=slid.getValue();
    Graphics g= getGraphics();
    g.drawImage(im,value,0,iw,ih,this);
    g.drawImage(bf,value,0,iw,ih,this);
    biC.drawImage(bf,value,0,iw,ih,this);
    Any ideas???
    THanks,
    Rick

    Its getting them from another class thats calling the mothod to construct the slider bar with dedraw button. Thats a pretty big class but I will post the code where I called the method:
    public class Process extends JFrame implements MouseListener, MouseMotionListener{
    private int [][] points;
    private int [] lengths={0};
    private int [] bin;
    private String imstr;
    private String imsav;
    private int imgw=658;
    private int imgh=512;
    private int xArrayPos=0;
    private int yArrayPos=0;
    private int xpos=0;
    private int ypos=0;
    private int xprev;
    private int yprev;
    private int xadd;
    private int yadd;
    private String filstr;
    Image image;
    SimpleGUI gui;
    BufferedImage buffer;
    Graphics2D biContext;
    Graphics2D g2;
    BufferedImage last;
    Graphics2D lastContext;
    public Process(){
    JFrame slideFrame = new JFrame("Please slide to scroll image");
    slideFrame.setContentPane(new SliderExample(imgw, imgh,image,buffer,biContext));
    slideFrame.pack();
    slideFrame.setVisible(true);
    Thats what anything having to do with that function in the other class that calls the Slider Class.
    Do you know how I can fix this??
    Thanks,
    Rick

  • Error referencing locally installed JSTL

    Using the JWSDP, I downloaded JSTL 1.0 from Jakarta.
    I am able to use my own custom tag libs, and indeed the JSTL when the
    directive is thus:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    However, when I try to use JSTL installed locally thus:
    <%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
    and c.tld looking thus:
    <uri>/WEB-INF/lib</uri>
    I get this error(/exception):
    org.apache.jasper.JasperException: /ForTokens.jsp(15,2) According to
    TLD or attribute directive in tag file, attribute value does not accept
    any expressions
    This is calling the ForTokens.jsp supplied in the JSTL bundle.
    Is it the case that one can only use JSTL in an Internet connected environment?
    The client would ideally not want Internet access for their Intranet servers.
    Finally, I am aware that a number of class files do not come reside on
    the local server, but surely everything is contained the files in
    /WEB-INF/lib*.jar, is it not?
    Please help as I have been trying to solve this for too long a time.
    Happy coding.

    Hi DanielO,
    No, JSTL doesn't require an Internet connected environment.
    I wouldn't change that taglib URI. You shouldn't duplicate the .tld files in your WEB-INF or declare the taglibs in your web.xml either, in spite of what the books tell you.
    Put the standard.jar in the CLASSPATH and use the .tld files and default URI that are already inside that JAR. That's the way I do it, and it works every time. Shawn Bayern, the author of "JSTL In Action" and a lead developer on JSTL, explained this on the JSTL mailing list one day. Since I read that I've had no troubles with JSTL.
    The error message leads me to believe that you've got some syntax error in your page. Maybe you need to look harder at that. - MOD

  • How to change local object to own dev class

    in the table maintenance generator my object is stored under local object how to change loacal object to our own development class and how to change the function group in table maintenance generator

    Hi Narendra,
    In order to change the function group, you need to delete the table maintenance generator first.
    Then you create a new table maintenance generator.
    To change the package of your object :
    1. for Function Group
       - tcode SE80
       - right click on the Function Group
       - choose : More Function - Object Directory Entry
    2. for Table / Function Module
       - tcode se11 / se37 / se38
       - in the upper menu : choose : Goto -- Object Directory Entry
    Hope this helps.
    best regards

  • Need to change the local change request to development class for Process Ch

    Hello ,
    I have created a Tranport request for Process chain but its saved as local change request .
    Please suggest how to change that .
    Thanks ,
    Rahul

    Hi
    1.First delete the request which you collected the process chain as local object becuase you will not able to collect the process chian again.
    2. Goto Tranport connector to collect the process chain again.
    3. Select grouping option as necessary objects.
    4. Drag and drop the process chain to the right hand side
    5. After collecting the process chain, click on the package icon and give the package created for development class.
    6. The system will ask for Transport request and save the PC in the Transport Request.
    Hope it helps.
    Regards
    Sadeesh

  • Local Attributes of the T_SERVER Class

    What's the secret to getting the attributes listed as "local" in the MIB doc? I have some simple code to do GETs and then dump the contents of the receive buffer. Everything works nicely except I can't seem to get any of the "local" T_SERVER Attributes. I have tried setting the MIB_LOCAL flag. I have tried specifying the local attributes in a filter. All to no avail.
    This snippet...
    FBFR32* fmlbuf;
    if ((fmlbuf = (FBFR32*)tpalloc("FML32", NULL, 10000)) == NULL)
    cerr<<"ERROR: mibget: tpalloc: "<<tpstrerror(tperrno)<<endl;
    return;
    if (Finit32(fmlbuf, Fsizeof32(fmlbuf)) == -1)
    cerr<<"ERROR: mibget: Finit32: "<<Fstrerror32(Ferror32)<<endl;
    tpfree((char*)fmlbuf);
    return;
    Fchg32(fmlbuf, TA_OPERATION, 0, "GET", 0);
    Fchg32(fmlbuf , TA_FLAGS, 0, (char*)MIB_LOCAL, 0);
    Fchg32(fmlbuf, TA_CLASS, 0, (char*)tclass.c_str(), 0);
    long len = -1;
    if (tpcall(".TMIB", (char*)fmlbuf, (long)0, (char**)&fmlbuf, (long*)&len, (long)0) == -1)
    cerr<<"ERROR: "<<tclass.c_str()<<": tpcall: Error "<<tperrno<<" "<<tpstrerror(tperrno)<<endl;
    tpfree((char*)fmlbuf);
    return;
    string path = "c:\\temp\\";
    path.append(tclass);
    path.append(".log");
    FILE* f = fopen(path.c_str(), "a");
    Ffprint32(fmlbuf, f);
    fclose(f);
    tpfree((char*)fmlbuf);
    Prints the following 38 fields for each server occurrence when tclass=T_SERVER...
    TA_BASESRVID     1
    TA_GRPNO     30002
    TA_MAX     1
    TA_MAXGEN     0
    TA_MIN     1
    TA_PID     6256
    TA_RPID     1537
    TA_RPPERM     432
    TA_RQID     1537
    TA_RQPERM     432
    TA_SEQUENCE     0
    TA_TIMERESTART     1322356429
    TA_TIMESTART     1322356429
    TA_MINDISPATCHTHREADS     0
    TA_THREADSTACKSIZE     0
    TA_MAXQUEUELEN     -1
    TA_SRVID     0
    TA_MAXEJBCACHE     0
    TA_EJBCACHE_FLUSH     0
    TA_CLASS     T_SERVER
    TA_STATE     ACTIVE
    TA_CLOPT     
    TA_CONV     N
    TA_ENVFILE     
    TA_RCMD     
    TA_REPLYQ     N
    TA_RESTART     Y
    TA_RQADDR     43349
    TA_SERVERNAME     c:\\Oracle\\tuxedo11gR1_VS2010\\bin\\BBL.exe
    TA_SYSTEM_ACCESS     FASTPATH
    TA_SEC_PRINCIPAL_NAME     
    TA_SEC_PRINCIPAL_LOCATION     
    TA_SEC_PRINCIPAL_PASSVAR     
    TA_SICACHEENTRIESMAX     0
    TA_LMID     SLC00FDG
    TA_SRVGRP     
    TA_SRVTYPE     
    TA_CONCURR_STRATEGY     
    Oracle Tuxedo, Version 11.1.1.2.0 with VS2010, 64-bit, Patch Level (none) running on Microsoft Windows Server 2008 R2 Enterprise 6.1.7601 Service Pack 1 Build 7601.
    What am I missing?

    Answering my own post. What I was missing was the '&' in front of MIB_LOCAL. Chalk that one up to a stupid typo.

  • Referencing fields between objects of same class

    Say I have created multiple TicketMachines from this class. Is there a way I create a method that uses "System.out.println" that would print the price of another TicketMachine object. And if so, could you please point me in the direction to find out how.
    * TicketMachine models a naive ticket machine that issues
    * flat-fare tickets.
    * The price of a ticket is specified via the constructor.
    * It is a naive machine in the sense that it trusts its users
    * to insert enough money before trying to print a ticket.
    * It also assumes that users enter sensible amounts.
    * @author David J. Barnes and Michael Kolling
    * @version 2006.03.30
    public class TicketMachine
        // The price of a ticket from this machine.
        private int price;
        // The amount of money entered by a customer so far.
        private int balance;
        // The total amount of money collected by this machine.
        private int total;
        //Creates a machine that issues tickets at a default price of 1000.
        public TicketMachine( )
         //Exercise 2.39  & 2.42(continues below)
          * By removing the parameter from this constructer
          * and setting the value of price to 1000, objects
          * from this class are automatically constructed with
          * a ticket price of 1000.
            price = 1000;
            balance = 0;
            total = 0;
        //Exercise 2.42
         * Create a machine that issues tickets of the given price.
         * Note that the price must be greater than zero, and there
         * are no checks to ensure this.
        public TicketMachine(int thePrice)
            price = thePrice;
            balance = 0;
            total = 0;
         * Return the price of a ticket.
        public int getPrice()
            return price;
         * Return the amount of money already inserted for the
         * next ticket.
        public int getBalance()
            return balance;
         * Receive an amount of money in cents from a customer.
        public void insertMoney(int amount)
            balance = balance + amount;
         * Print a ticket.
         * Update the total collected and
         * reduce the balance to zero.
        public void printTicket()
            // Simulate the printing of a ticket.
            System.out.println("##################");
            System.out.println("# The BlueJ Line");
            System.out.println("# Ticket");
            System.out.println("# " + price + " cents.");
            System.out.println("##################");
            System.out.println();
            // Update the total collected with the balance.
            total = total + balance;
            // Clear the balance.
            balance = 0;
        //Exercise 2.33
        //Prints "Please insert the correct amount of money." to the text terminal.
        public void prompt()
            System.out.println("Please insert the correct amount of money.");
        //Exercise 2.34
        //Displays the value of the price field in the text terminal.
        public void showPrice()
            System.out.println("The price of a ticket is " + price + " cents.");
        //Exercise 2.35
         * After creating two ticket machines with different prices
         * and calling thier showPrice methods it showed a different
         * output for each instance. This effect happenes because the
         * showPrice method prints out a string and the value of the price
         * field, which happens to be different in each instance, thereby
         * printing a different output.
        //Exercise 2.36
         * The result of System.out.println("# " + "price" + " cents.");
         * would print the string "# price cents." to the text terminal.
        //Exercise 2.37
         * The result of System.out.println("# price cents.");
         * would be the same as the result of exercise 2.36.
        //Exercise 2.40
        //This method is a mutator and takes no parameters
        //Empties the money form the ticket machine
        public void empty()
            total = 0;
        //Exercise 2.41
        //This method is a mutator
        //Changes the price of a ticket
        public void setPrice(int newPrice)
            price = newPrice;
    }

    Objects can refer to fields in other objects of the same class.
    It's not clear from your description what you're trying to accomplish, however.

  • Is there any concept in LabVIEW that is similar to static local scope variables in C?

    I'd like to retain the value between calls to a subVI, as can be done using a static function scoped variable in C. The textbook example of how this is used would be a variable in the function that is a state machine, and knows what state it was in last time it was executed. A simpler example would be just keeping count of how many times the function has been called.
    I suppose I could use a global or I could pass values in and out of the subVI, but I'd like to keep the variable known only in the scope of the subVI if at all possible. For example, the outside world has no business knowing (or god forbid) changing what the state information of this function is.

    Bmarsh wrote:
    > I'd like to retain the value between calls to a subVI, as can be done
    > using a static function scoped variable in C. The textbook example of
    > how this is used would be a variable in the function that is a state
    > machine, and knows what state it was in last time it was executed. A
    > simpler example would be just keeping count of how many times the
    > function has been called.
    >
    > I suppose I could use a global or I could pass values in and out of
    > the subVI, but I'd like to keep the variable known only in the scope
    > of the subVI if at all possible. For example, the outside world has
    > no business knowing (or god forbid) changing what the state
    > information of this function is.
    There is no need to do something "conceptual" or spec
    ific to have this
    static variable. You already have this in any control or indicator in
    your sub-vi while it is in memory. Control/indicator value will remain
    in sub-vi data space between calls. Don't forget about make your sub-vi
    non-reentrant or keep track of sub-vi data space copies.
    If you want to read/write this value from another vi, consider it global
    or I'd prefer to suggest using functional global(uninitialized shift
    register in 1 iteration while loop). Think of it as about 1 value data
    repository.
    LabVIEW CIN reference manual is a good place to look at, as well as
    LabVIEW course kits, describing LabVIEW memory issues in details.
    To simplify: create empty sub-vi with control and indicator connected to
    each other and call it wiring indicator in caller vi. Keep sub-vi front
    panel open and change control in sub-vi manually. You see what happens.
    Sergey Krasnishov
    Automated Control Systems
    National Instruments Alliance Member
    Mos
    cow, Russia
    [email protected]
    http://acs.levsha.ru

  • Jsp:useBean : Missing value of String classed bean with 'session' scope

    Hi!
    I'd like to ask some help.
    I have these two JSP pages:
    1.jsp<jsp:useBean id="str" class="java.lang.String" scope="session"/>
    <html>
    <body>
    <% str="hello"; %>
    <a href="2.jsp">click</a>
    </body>
    </html>
    2.jsp<jsp:useBean id="str" class="java.lang.String" scope="session"/>
    <html>
    <body>
    <%=str%>
    </body>
    </html>When I open 1.jsp in my browser, then click on the link, the result is "nothing" (empty string). Why does the bean lose its value on the way?
    I use a Tomcat 5.5.9 server.
    Any help will be highly appreciated.

    You have to think of several scopes when working with JSP. The first is the local scope: the method _jspService() where all the work of the JSP is done.  This acts as a normal method and is where all the sciptlet code goes.
    When you use jsp:useBean you are creating two references to a new String object. One in the local scope accessible through <%= str %> and the other in the session scope.
    When you do <% str = "hello"; %> you are changing the local str variable to reference the String "hello" (this is equivalant to doing <% str = new String("hello"); %>). Only the local reference is changed, not the second reference in session.
    If you want the change to take affect, then you will have to store the new value in session with the same name:
    <% session.setAttribute("str", str); %>

  • Referencing a method from another class

    Hi,
    I am creating a chat program using RMI and i am experiencing a few difficulties. I would be very grateful if you could help me with the following problem.
    I'm getting the following error:
    non-static method Login(java.lang.String,java.lang.String) cannot be referenced from a static context
    The code is:
    GUI code/
    boolean loggedOn = ChatClient.Login(username,password);
    which is referencing the method Login in the class ChatClient class. I want to return a boolean value back. So i can use the variable loggedOn.
    The ClientChat Login method code is:
    public boolean Login(String username, String password) throws RemoteException
    try
    Chat c = (Chat)Naming.lookup("rmi://localhost/chat1");
    boolean loggedOn = c.Login(username,password,this);
    catch (Exception e)
    e.printStackTrace();
    return loggedOn;
    but i get an error saying it does not recognize the variable loggedOn.
    Can anyone please suggest some possible solutions.
    Many thanks,

    You have a scope problem.
    int youCanSeeMe = 1;
    try
       int youCannotSeeMe = 3;
       youCanSeeMe = 2;
    catch (Exception e)
       e.printStackTrace();
    System.out.println(youCanSeeMe);
    System.out.println(youCannotSeeMe);What is the difference in the location of the declaration of the two variables youCanSeeMe and youCannotSeeMe? You want loggedOn to look like youCanSeeMe.
    Your static problem needs something like this:
    ChatClient myClient = new ChatClient();
    myClient.Login("user","pass");You need to call Login on an instance of ChatClient.

Maybe you are looking for

  • Schema to be handled does not contain a definition of type SODetailResponse

    I am creating a new data type named SODetailResponse and I get an error trying to import xml schema. I used XMLSpy and Business Connector with the schema and had no problems. <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.o

  • Blackberry messanger

    I am trying to add contacts to my Blackberry Messanger but I keep getting and email that says this... This message is used to carry data between the BlackBerry handheld and an associated server. Please do not delete, move or respond to this message -

  • BB10 File Manager keeps showing previously linked (and gone) computer

    Hi. After upgrade from 10.2.1 to 10.3.1, access to / from my paired computer stopped working.  I tried removing and readding it and apparently ran into a bug.  In Device Connections I have my computer linked again BUT in File Manager I can see it twi

  • MacBookPro Has Started Crashing

    Hello there, I rarely post here, so hope I am not breaking any rules or etiquette! My wife's macbook pro started crashing about 1 month ago. I can't find no rhyme or reason for when it crashes. Sometimes with web browser, sometimes not. Either everyt

  • Searching in text by contact name

    Before iOS6, I could search by contact name within the text messages area and it would sift through my long list of text messages to bring up the contact name that I had texted with.  Now it appears that Apple is not allowing the contact name to be i