Question

im actually working on an Android application which provides user a connexion to a DataSnap server but I got a problem with my NetworkManager class.

I wish I have access to its content (user, host, port ...) but I can't and I didn't found the solution online (or may be I didn't read all posts)

There is my code for the network manager:

package com.smdroid;

import com.embarcadero.javaandroid.DSProxy.TServerMethods1;
import com.embarcadero.javaandroid.DSRESTConnection;

public class NetworkManager{
    DSRESTConnection     conn = new DSRESTConnection();
    TServerMethods1      proxy;
    int                  servId = 0;
}

and where I want to call my class and access the content :

    public class ServerMenu extends Fragment {

    TJSONArray      servList;
    NetworkManager  nm = NetworkManager;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
                 Bundle savedInstanceState) {

         final View servView = inflater.inflate(R.layout.server_menu, container, false);

         try {
            System.out.println(nm.proxy.ReverseString("reverse test"));
         } catch (DBXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }

         return servView; 
    };
 }

If someone could help me, it would be nice. Thanks you =) Regards, Pierre

Was it helpful?

Solution

Usually in Java when you have a class that has some attributes there're several ways to make them accessibile.

  1. Make attributes public
  2. Make attributes private and provide get and set methods. The convension is to use get or set with then first letter of the attribute name in uppercase. These methods must be public

Usually the solution n.2 is the best one because you avoid direct access to private attributes from other classes (see encapsulation).

In general, but not your case, when declaring the attributes as you did you make their access 'default', so you can access them from another class extending your NetworkManager in the same package.

If this class is just a configuration parameter holder you can even make this attributes static and public, so you don't have to instantiate the class to access them.

OTHER TIPS

Put in your NetworkManager class a public method which return the objects - for example public TServerMethods1 getProxy(){ return proxy; }

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top