Question

Heyho. I'm writing an android client which is communicating between a Hessian Servlet and Hessdroid. Everything went fine until i wanted to transmit this selfimplemented type:

  • client & server are communicating between IUserService.java interface.

SERVER-SIDE:

odtObject.java:

import java.io.Serializable;

public class odtObject implements Serializable {

    private String siteName;
    private int siteId;

    public odtObject(String siteName, int siteId) {
        this.siteName = siteName;
        this.siteId = siteId;
    }

    public String getSiteName() {
        return siteName;
    }

    public int getSiteId() {
        return siteId;
    }
}

UserService.java:

public ArrayList<odtObject> getSiteList() {
    ArrayList<odtObject> siteList = new ArrayList<odtObject>();
    siteList.add(new odtObject("hello", 1));
    System.out.println(siteList.get(0).getSiteName()); // out: hello
    return siteList;
}

CLIENT-SIDE

PageOne.java:

IUserService con = new IUserService();
ArrayList<odtObject> siteList = new ArrayList<odtObject>(); 
siteList = con.getSiteList();
System.out.println(siteList.get(0).getSiteName()); // 87: Exception

odtObject.java: ...

Exception:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testapp/com.testapp.PageOne}: java.lang.ClassCastException: java.util.HashMap cannot be cast to com.testapp.odtObject
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    at android.app.ActivityThread.access$600(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to com.testapp.odtObject
    at com.testapp.PageOne.onCreate(PageOne.java:87)
    at android.app.Activity.performCreate(Activity.java:5104)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)

Thank you for help! Just say it, if you want to see more code...

Edit:

RetrieveData calls IUserService function... PageOne code from above is kind of pseudo code to understand it easier.

protected void onCreate(Bundle savedInstanceState) {        
    Thread t = new Thread() {
        public void run() {
            Intent myIntent = getIntent();
            String user = myIntent.getStringExtra("user");
            String pass = myIntent.getStringExtra("pass");
            RetrieveData r = new RetrieveData(context);               
            if(r.login(user, pass.toCharArray()) != null) {                 
                siteList = r.getSiteList();
                System.out.println("done");
            } else {
                System.out.println("error");
            }

        }
    };     
    t.start();                  
    super.onCreate(savedInstanceState);
    setContentView(R.layout.page1);

    inputSearch = (EditText) findViewById(R.id.inputSearch);
    listView = (ListView) findViewById(R.id.mylist);

    /* wait for networking thread */
    try {
        t.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }           
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1);      

    System.out.println(siteList.get(0).getSiteName()); // 87: Exception     
    for (odtObject d : siteList) {
        adapter.add(d.getSiteName());
    }   
    listView.setAdapter(adapter); 

    ...
}

maybe this could be relevant too:

public String login(String username, char[] password) {
    HessianProxyFactory factory = new HessianProxyFactory();         
    String url = "http://192.168.56.1:8080/hessianServerX";
    factory.setHessian2Reply(false); // avoid hessian reply error
    try {
        userCon = (IUserService) factory.create(IUserService.class,  
                url+"/IUserService");                
        sessionId = userCon.login(username, password);
        secureCon = (ISecureService) factory.create(ISecureService.class,  
                url+"/restrictedArea/ISecureService;jsessionid="+sessionId);        
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return sessionId;
}

Edit:

I set DebugMode on the HessianProxyFactory and now i get this one:

03-26 16:07:06.909: W/SerializerFactory(6023): Hessian/Burlap: 'com.hessian.odtObject' is an unknown class in dalvik.system.PathClassLoader[dexPath=/data/app/tsch.serviceApp-1.apk,libraryPath=/data/app-lib/tsch.serviceApp-1]:
03-26 16:07:06.909: W/SerializerFactory(6023): java.lang.ClassNotFoundException: com.hessian.odtObject
03-26 16:07:06.909: W/dalvikvm(6023): threadid=10: thread exiting with uncaught exception (group=0x9e50d908)
03-26 16:07:06.909: E/AndroidRuntime(6023): FATAL EXCEPTION: Thread-527
03-26 16:07:06.909: E/AndroidRuntime(6023): java.lang.ClassCastException: java.util.HashMap cannot be cast to tsch.serviceApp.types.odtObject
03-26 16:07:06.909: E/AndroidRuntime(6023):     at tsch.serviceApp.net.HessianConnect.<init>(HessianConnect.java:31)
03-26 16:07:06.909: E/AndroidRuntime(6023):     at tsch.serviceApp.PageLogin$1.run(PageLogin.java:17)
Était-ce utile?

La solution

Solved the problem by myself. I had to export the custom type class OdtObject.java as a jar and add it to the classpaths!

Autres conseils

If this lop's result is false:

 if(r.login(user, pass.toCharArray()) != null) {                 
                siteList = r.getSiteList();
                System.out.println("done");
            } else {
                System.out.println("error");
            }

Then your siteList is going to be null and not initialized.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top