title: Using Spongy Castle library to generate a key pair in ECDH
body: <p>I am a student in Taiwan. I am learning how to programming in Android.
  but I have a problem about using Spongy Castle library to generate a key pair in ECDH.
  when I start the app, android system shows the app has stopped.</p>
  
  <p>Here is my code and my import</p>
  
  <pre><code>public class MainActivity&lt;ECParams&gt; extends Activity {
      String msg,Test;
  
      @Override
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Button generator= (Button) findViewById(R.id.key_pair_generator);
          generator.setOnClickListener(ECkeyPairGenerator);
      }
  
      @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;
      }
      private Button.OnClickListener ECkeyPairGenerator = new Button.OnClickListener()
      {
          public void onClick(View v) {
              KeyPairGenerator kpg=null;
              ECGenParameterSpec ecParamSpec = new ECGenParameterSpec("secp224k1");
              try {
                  kpg = KeyPairGeneratorSpi.getInstance("ECDH", "SC");
              } catch (NoSuchAlgorithmException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (NoSuchProviderException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              try {
                  kpg.initialize(ecParamSpec);
              } catch (InvalidAlgorithmParameterException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              KeyPair kpair=kpg.generateKeyPair();
              msg="pp";
              ShowMsg();
          }
  
      };
      public static String byteArrayToHexString(byte b[]) {
          StringBuffer s = new StringBuffer();
          int LEN = b.length;
          if (b.length != LEN)
              throw new RuntimeException("byteArrayToHexString() " +
                                         "wrong argument length (!="+LEN);
          for (int j = 0; j &lt; b.length; j++) {
              s.append(Integer.toHexString((int)((b[j]&gt;&gt;4)&amp;0x0f)));
              s.append(Integer.toHexString((int)(b[j]&amp;0x0f)));
          }        
          return new String(s);
      }
      public void ShowMsg(){
          Intent intent = new Intent();
          intent.setClass(MainActivity.this, Show.class);
          Bundle bundle = new Bundle();
          bundle.putString("Show", msg);
          intent.putExtras(bundle); 
          startActivity(intent);
      }
  
  }
  </code></pre>
  
  <p>Please help.</p>