1

I get the following Android exception if launching the following code. I have a server - client application and an server agent which communicated with each other. Now I just get this exception in the Android application and not on the server agent. I know that this worked some time before correctly.

12-18 20:36:41.626: E/AndroidRuntime(19441): FATAL EXCEPTION: AsyncTask #1
12-18 20:36:41.626: E/AndroidRuntime(19441): java.lang.RuntimeException: An error occured while executing doInBackground()
12-18 20:36:41.626: E/AndroidRuntime(19441):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at java.util.concurrent.FutureTask.run(FutureTask.java:239)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at java.lang.Thread.run(Thread.java:841)
12-18 20:36:41.626: E/AndroidRuntime(19441): Caused by: java.lang.NoClassDefFoundError: de.hska.ilias.commons.server.Communication
12-18 20:36:41.626: E/AndroidRuntime(19441):    at de.hska.ilias.app.client.Client.handleServerPassword(Client.java:101)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at de.hska.ilias.app.client.Client.manageHandshake(Client.java:75)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at de.hska.ilias.app.client.LoginTask.doInBackground(LoginTask.java:85)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at de.hska.ilias.app.client.LoginTask.doInBackground(LoginTask.java:1)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-18 20:36:41.626: E/AndroidRuntime(19441):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-18 20:36:41.626: E/AndroidRuntime(19441):    ... 4 more
12-18 20:36:41.956: E/WindowManager(19441): Activity de.hska.ilias.app.activity.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{43168430 V.E..... R......D 0,0-1026,288} that was originally added here
12-18 20:36:41.956: E/WindowManager(19441): android.view.WindowLeaked: Activity de.hska.ilias.app.activity.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{43168430 V.E..... R......D 0,0-1026,288} that was originally added here
12-18 20:36:41.956: E/WindowManager(19441):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:450)
12-18 20:36:41.956: E/WindowManager(19441):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:258)
12-18 20:36:41.956: E/WindowManager(19441):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:73)
12-18 20:36:41.956: E/WindowManager(19441):     at android.app.Dialog.show(Dialog.java:287)
12-18 20:36:41.956: E/WindowManager(19441):     at de.hska.ilias.app.client.LoginTask.onPreExecute(LoginTask.java:73)
12-18 20:36:41.956: E/WindowManager(19441):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
12-18 20:36:41.956: E/WindowManager(19441):     at android.os.AsyncTask.execute(AsyncTask.java:534)
12-18 20:36:41.956: E/WindowManager(19441):     at de.hska.ilias.app.client.Client.tryConnect(Client.java:44)
12-18 20:36:41.956: E/WindowManager(19441):     at de.hska.ilias.app.ui.action.LoginAction.onClick(LoginAction.java:77)
12-18 20:36:41.956: E/WindowManager(19441):     at android.view.View.performClick(View.java:4475)
12-18 20:36:41.956: E/WindowManager(19441):     at android.view.View$PerformClick.run(View.java:18786)
12-18 20:36:41.956: E/WindowManager(19441):     at android.os.Handler.handleCallback(Handler.java:730)
12-18 20:36:41.956: E/WindowManager(19441):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-18 20:36:41.956: E/WindowManager(19441):     at android.os.Looper.loop(Looper.java:137)
12-18 20:36:41.956: E/WindowManager(19441):     at android.app.ActivityThread.main(ActivityThread.java:5419)
12-18 20:36:41.956: E/WindowManager(19441):     at java.lang.reflect.Method.invokeNative(Native Method)
12-18 20:36:41.956: E/WindowManager(19441):     at java.lang.reflect.Method.invoke(Method.java:525)
12-18 20:36:41.956: E/WindowManager(19441):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
12-18 20:36:41.956: E/WindowManager(19441):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
12-18 20:36:41.956: E/WindowManager(19441):     at dalvik.system.NativeStart.main(Native Method)

Where the exception comes from:

  private void handleServerPassword() throws ServerPasswordException
  {
    try
    {
      **if (Communication.rcvLineServerPasswordReq(input))**
      {
        Communication.sndServerPasswordAck(output);
        Communication.sndServerPassword(output);
      }
      else
        throw new ServerPasswordException();
    }
    catch (ServerPasswordException e)
    {
      throw new ServerPasswordException("Handling password communication failed.");
    }
  }
marc3l
  • 2,525
  • 7
  • 34
  • 62
  • Are you sure the class is there? Also `NoClassDefFoundError`s can be caused by exceptions being thrown in static initializers. Does `de.hska.ilias.commons.server.Communication` have static initializers / static variables that are initialized to a value? – Robin Green Dec 18 '13 at 19:58
  • Communication class does have static methods, but no initializers. – marc3l Dec 18 '13 at 19:58
  • I'm not at all up to date on Android issues but, as you probably know, this is a run time error. That means it has to do with class not found at run time (i.e. your build path isn't at fault). This link might give you an insight: http://stackoverflow.com/questions/8678630/noclassdeffounderror-for-code-in-an-java-library-on-android – Achim Schmitz Dec 18 '13 at 21:44

3 Answers3

0

A NoClassDefFoundError specifies that the class was not available during runtime. Make sure you have it in class path or the static initializer(if present) is not breaking. For the later, you will see an ExceptionInInitializerError somewhere below in the stacktrace. I suggest you to go through this to Debug a NoClassDefFoundError

Crickcoder
  • 2,135
  • 4
  • 22
  • 36
0

I've found a solution for this problem: It was the Java compiler compliance level, which was set to 1.6 in the Android project and to 1.7 in the dependent Java project. After setting both to 1.6 it solved the problem, but I don't know why ;)

marc3l
  • 2,525
  • 7
  • 34
  • 62
0

This is what happened to me: i had to launch a java program via sh script (linux), but i created that script in my local machine (windows).

When i uploaded the sh script to the linux server, and run it, i got this error.

This is because Windows and Linux handle the line breaks differently, so the linux machine could not understand the syntax written in windows.

In this case, all you have to do is create the script directly on the linux server.

BabaNew
  • 884
  • 1
  • 13
  • 27