我试图在我的项目中使用一些外部 jar 文件,但是当我运行应用程序时,它给了我 ether java.lang.IllegalStateException
或java.lang.ClassDefNotFoundError
. 我几乎尝试了这里提到的所有方法,但找不到解决方案。我正在使用 ADT 版本 22 和 Android SDK 版本 17。
这是日志:
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();
}
}
即使有必要,我也可以通过电子邮件发送我的项目。