我想在我的項目中使用一些外部jar文件,但是當我運行該應用程序時,它給了我ether java.lang.IllegalStateException
或java.lang.ClassDefNotFoundError
。我嘗試了幾乎所有在這裏提到的方法,但找不到解決方案。我使用的ADT版本22和Android SDK版本17.java.lang.IllegalStateException/java.lang.ClassDefNotFoundError將外部罐子添加到Android項目
這裏是日誌:
8-26 16:50:21.022: E/AndroidRuntime(16642): FATAL EXCEPTION: main
08-26 16:50:21.022: E/AndroidRuntime(16642): java.lang.NoClassDefFoundError: sun.misc.BASE64Encoder
08-26 16:50:21.022: E/AndroidRuntime(16642): at com.test.testlibs.MainActivity.convertMD5(MainActivity.java:48)
08-26 16:50:21.022: E/AndroidRuntime(16642): at com.test.testlibs.MainActivity$1.onClick(MainActivity.java:30)
08-26 16:50:21.022: E/AndroidRuntime(16642): at android.view.View.performClick(View.java:4128)
08-26 16:50:21.022: E/AndroidRuntime(16642): at android.view.View$PerformClick.run(View.java:17142)
08-26 16:50:21.022: E/AndroidRuntime(16642): at android.os.Handler.handleCallback(Handler.java:615)
08-26 16:50:21.022: E/AndroidRuntime(16642): at android.os.Handler.dispatchMessage(Handler.java:92)
08-26 16:50:21.022: E/AndroidRuntime(16642): at android.os.Looper.loop(Looper.java:213)
08-26 16:50:21.022: E/AndroidRuntime(16642): at android.app.ActivityThread.main(ActivityThread.java:4787)
08-26 16:50:21.022: E/AndroidRuntime(16642): at java.lang.reflect.Method.invokeNative(Native Method)
08-26 16:50:21.022: E/AndroidRuntime(16642): at java.lang.reflect.Method.invoke(Method.java:511)
08-26 16:50:21.022: E/AndroidRuntime(16642): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
08-26 16:50:21.022: E/AndroidRuntime(16642): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
08-26 16:50:21.022: E/AndroidRuntime(16642): at dalvik.system.NativeStart.main(Native Method)
和類執行力度:
package com.test.testlibs;
import sun.misc.BASE64Encoder;
import com.test.testlibs.R.id;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(id.btnTest);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
convertMD5();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void convertMD5()
{
TextView textView = (TextView) findViewById(id.txtTest);
String text = textView.getText().toString();
BASE64Encoder base64Encoder = new BASE64Encoder();
String uname64 = base64Encoder.encode(text.getBytes());
Toast toast = Toast.makeText(getApplicationContext(), text+" "+uname64, Toast.LENGTH_LONG);
toast.show();
}
}
我可以通過電子郵件發送我的項目,即使這是必要的太。
你有沒有檢查過,如果你的庫項目正確導入或不是,也可在工作區或不? – Piyush
是的,我做到了。導入的文件也在工作區 – Sajirupee
和您的類將在sun.misc包? – Piyush