我正在android手机上使用jackrabbit jar文件(jackrabbit-webDav-2.2.5-jar-with-dependences)开发我的webDav客户端-这个jar是为android设备定制的版本。
我已经在libs文件夹中添加了这个jar文件,它不会给我编译错误,但当我在模拟器上运行.apk时,我会收到以下错误:
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
下面是我连接到webDav服务器的代码快照
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);
}
}
以下是活动布局文件
<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>
梅尼费斯特文件
<?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>
请帮忙,从早上开始我就被困在这上面了。
谨致问候,Ram Rote
1-转到项目属性
2-转到java构建路径
3-点击订单并导出
4-检查你的jar文件点击ok