0

I am developing my webDav client on android mobile using jackrabbit jar file (jackrabbit-webdav-2.2.5-jar-with-dependencies)- This JAR is customized version for android devices.

I have added this jar file at libs folder, It does not give me compilation error but when i run .apk on emulator i am getting below errors:

04-16 02:55:50.387: E/AndroidRuntime(2122): FATAL EXCEPTION: main
04-16 02:55:50.387: E/AndroidRuntime(2122): Process: com.example.jackrabbit, PID: 2122
04-16 02:55:50.387: E/AndroidRuntime(2122): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.jackrabbit/com.example.jackrabbit.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.jackrabbit.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.jackrabbit-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.jackrabbit-1, /system/lib]]
04-16 02:55:50.387: E/AndroidRuntime(2122):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at android.os.Looper.loop(Looper.java:136)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at java.lang.reflect.Method.invokeNative(Native Method)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at java.lang.reflect.Method.invoke(Method.java:515)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at dalvik.system.NativeStart.main(Native Method)
04-16 02:55:50.387: E/AndroidRuntime(2122): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.jackrabbit.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.jackrabbit-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.jackrabbit-1, /system/lib]]
04-16 02:55:50.387: E/AndroidRuntime(2122):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
04-16 02:55:50.387: E/AndroidRuntime(2122):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
04-16 02:55:50.387: E/AndroidRuntime(2122):     ... 11 more

Below is my code snap shot for connecting to webDav server

package com.example.jackrabbit;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class webDavClient extends Activity {

    MultiThreadedHttpConnectionManager manager;
    HostConfiguration config;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btn = (Button)findViewById(R.id.button1);

        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                //webDav host configuration
                ConfigureHost();
                 //webDav client configuration
                 ConfigureClient();             
            }
        });
    }

    public void ConfigureHost() {
        //create host configuration
        HostConfiguration config = new HostConfiguration();
        config.setHost("http://webdav.in.soti.net");

        //setup connection manager
        manager = new MultiThreadedHttpConnectionManager();
        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
        params.setMaxConnectionsPerHost(config, 5); // currently allowing 5 we may revise count afterwards

    }

    public void ConfigureClient() {
        //create client configuration
        HttpClient client = new HttpClient(manager);
        client.setHostConfiguration(config);
        Credentials creds = new UsernamePasswordCredentials("username", "password");
        client.getState().setCredentials(AuthScope.ANY, creds);
    }

}

Below is activity layout file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="127dp"
        android:text="ConnectToServer" />

</RelativeLayout>

Menifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.jackrabbit"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.jackrabbit.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Please help on this since morning i am stuck on this.

Best Regards, Ram Rote

Ram Rote
  • 199
  • 1
  • 1
  • 9

1 Answers1

2

1- go to project property
2- go to java build path
3- click order and export
4- checked your jar file click ok

Sandeep Tiwari
  • 2,042
  • 3
  • 24
  • 47
  • @Wizard why? http://stackoverflow.com/questions/15707024/android-eclipse-put-jar-in-libadd-to-build-path-vs-put-jar-in-libs. SO if you add the jar to the libs folder it will add it to the build path at run time and op says he added jar to libs folder. – Raghunandan Apr 16 '14 at 07:33
  • Hi Sandeep, I see on Order and Export Android Private Library is already checked and i can see jackrabbit-webdav-2.2.5-jar-with-dependencies JAR file in Libraries. – Ram Rote Apr 16 '14 at 07:34
  • @RamRote post the activity layout xml – Raghunandan Apr 16 '14 at 07:36
  • @Wizard you are wrong it has nothing to with what you suggest. Re-read the stacktrace. `Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.jackrabbit.MainActivity"` – Raghunandan Apr 16 '14 at 07:39
  • @RamRote you need to post the manifest file . no need for the layot xml – Raghunandan Apr 16 '14 at 07:40
  • @RamRote clean and build the project. restart eclipse it should work fine – Raghunandan Apr 16 '14 at 07:41
  • @Raghunandan - i have already post my menifest along with layout file – Ram Rote Apr 16 '14 at 07:41
  • @RamRote there is nothting wrong in the code. uninstall the app. clean and build the project. Restart eclipse. – Raghunandan Apr 16 '14 at 07:42
  • Guys, error is solved now, i did silly mistake in changing class name from MainActivity to webDavClient. – Ram Rote Apr 16 '14 at 07:45
  • @Raghunandan ya if he didnot wrote activity in manifest file. and some times if library is not added this exception will occur or not? – W I Z A R D Apr 16 '14 at 07:47
  • 1
    @Wizard the exception is clear. Android cannot find MainActivity. package name is different in manifest than the one in activity. But in this case there is nothing wrong with it. SO it should work fine. Also the classnotfoundexcpetion is not for the class in library ie jar – Raghunandan Apr 16 '14 at 07:49