Android - 使用DigestUtils.sha1Hex()并崩溃

时间:2017-12-17 07:10:00

标签: java android apache digest

所以我尝试使用DigestUtils.sha1Hex()将我的输入字符串转换为SHA-1

我的MainActivity.java:

package com.example.haiph.hash;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import org.apache.commons.codec.digest.DigestUtils;

public class MainActivity extends AppCompatActivity {
    EditText myEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myEditText = findViewById(R.id.editText);
    }

   public void sha1encrypt(View view) {
        try {
            String sTemp1 = myEditText.getText().toString();
            String sTemp2 = DigestUtils.sha1Hex(sTemp1);
            myEditText.setText(sTemp2);
        }
        catch (Exception e){

        }
    }
}

但我的应用程序崩溃了,收到了这个,我不知道:

  

致命异常:主程序:com.example.haiph.hash,PID:2506
  java.lang.IllegalStateException:无法执行方法   安卓的onClick         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)         在android.view.View.performClick(View.java:5702)         在android.widget.TextView.performClick(TextView.java:10896)         在android.view.View $ PerformClick.run(View.java:22546)         在android.os.Handler.handleCallback(Handler.java:739)         在android.os.Handler.dispatchMessage(Handler.java:95)         在android.os.Looper.loop(Looper.java:158)         在android.app.ActivityThread.main(ActivityThread.java:7225)         at java.lang.reflect.Method.invoke(Native Method)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)引起:java.lang.reflect.InvocationTargetException         at java.lang.reflect.Method.invoke(Native Method)         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)         在android.view.View.performClick(View.java:5702)         在android.widget.TextView.performClick(TextView.java:10896)         在android.view.View $ PerformClick.run(View.java:22546)         在android.os.Handler.handleCallback(Handler.java:739)         在android.os.Handler.dispatchMessage(Handler.java:95)         在android.os.Looper.loop(Looper.java:158)         在android.app.ActivityThread.main(ActivityThread.java:7225)         at java.lang.reflect.Method.invoke(Native Method)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230)

  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)     Caused by: java.lang.NoSuchMethodError: No static method
     

encodeHexString([B)Ljava /郎/字符串;在班上   Lorg /阿帕奇/公地/编解码器/二进制/己烷;或者它的超级课程   ('org.apache.commons.codec.binary.Hex'的声明出现在   /system/framework/org.apache.http.legacy.boot.jar)         在org.apache.commons.codec.digest.DigestUtils.sha1Hex(DigestUtils.java:456)         在com.example.haiph.hash.MainActivity.sha1encrypt(MainActivity.java:21)         at java.lang.reflect.Method.invoke(Native Method)         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)

  at android.view.View.performClick(View.java:5702) 
  at android.widget.TextView.performClick(TextView.java:10896) 
  at android.view.View$PerformClick.run(View.java:22546) 
  at android.os.Handler.handleCallback(Handler.java:739) 
  at android.os.Handler.dispatchMessage(Handler.java:95) 
  at android.os.Looper.loop(Looper.java:158) 
  at android.app.ActivityThread.main(ActivityThread.java:7225) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)

  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

0 个答案:

没有答案