title: Android init Array Problems
body: <p>I've been stucked to find what's wrong with my code below.</p>
  
  <p>here's the <strong>MainActivity.java</strong></p>
  
  <pre><code>package com.andri.hilltest;
  
  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.EditText;
  import android.widget.Toast;
  
  public class MainActivity extends Activity implements OnClickListener {
  
      EditText txtPlain, txtKey, txtCipher;
      Button btnEncrypt;
      String char_db = "ABCDEFGHIJKLMNOPQRSTUVWXYZabc";
      int array_angka[];
      int i;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          txtPlain = (EditText) findViewById(R.id.txtPlain);
          txtKey = (EditText) findViewById(R.id.txtKey);
          txtCipher = (EditText) findViewById(R.id.txtCipher);
  
          btnEncrypt = (Button) findViewById(R.id.btnEncrypt);
  
          btnEncrypt.setOnClickListener(this);
  
  
      }
  
      @Override
      public void onClick(View v) {
          if(v == btnEncrypt){
  
              String plainTextInput = txtPlain.getText().toString();
  
              char[] array_huruf = plainTextInput.toCharArray();
              //int[] angka2;
  
  
              for (i=0 ; i &lt; array_huruf.length ; i++){
  
                  int posisi_huruf =  char_db.indexOf(array_huruf[i]);
  
                  Toast.makeText(this, "Tombol ditekan " +  posisi_huruf , Toast.LENGTH_SHORT).show();
                  array_angka[i] = posisi_huruf; //if I disable this line the code should run well
              }
  
          }
      }
  
      @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;
      }
  
  
  
  }
  </code></pre>
  
  <p>Here's the <strong>MainActivity.xml</strong></p>
  
  <pre><code>&lt;LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
  
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"&gt;
      &lt;TextView 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Plaintext"
          /&gt;
      &lt;EditText 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:id="@+id/txtPlain"
          android:hint="Masukkan plaintext"
          /&gt;
      &lt;TextView 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Key"
          /&gt;
      &lt;EditText 
          android:layout_width="fill_parent"
          android:hint="Masukkan Key"
          android:layout_height="wrap_content"
          android:id="@+id/txtKey"
          /&gt;
      &lt;Button 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Encrypt"
          android:id="@+id/btnEncrypt"
          /&gt;
      &lt;TextView 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Cipher (Hill Cipher)"
          /&gt;
      &lt;EditText 
          android:layout_width="fill_parent"
          android:hint=""
          android:layout_height="wrap_content"
          android:id="@+id/txtCipher"
          /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>the problem is when I put a line of code to insert the value of an int array from a loop. the when I ran and put some string as input, I got this error message</p>
  
  <p><strong>Log.txt</strong></p>
  
  <pre><code>04-11 10:50:22.039: D/AndroidRuntime(17743): Shutting down VM
  04-11 10:50:22.039: W/dalvikvm(17743): threadid=1: thread exiting with uncaught exception (group=0x40a621f8)
  04-11 10:50:22.049: E/AndroidRuntime(17743): FATAL EXCEPTION: main
  04-11 10:50:22.049: E/AndroidRuntime(17743): java.lang.NullPointerException
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at com.andri.hilltest.MainActivity.onClick(MainActivity.java:52)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at android.view.View.performClick(View.java:3511)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at android.view.View$PerformClick.run(View.java:14105)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at android.os.Handler.handleCallback(Handler.java:605)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at android.os.Handler.dispatchMessage(Handler.java:92)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at android.os.Looper.loop(Looper.java:137)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at android.app.ActivityThread.main(ActivityThread.java:4609)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at java.lang.reflect.Method.invoke(Method.java:511)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
  04-11 10:50:22.049: E/AndroidRuntime(17743):    at dalvik.system.NativeStart.main(Native Method)
  04-11 10:55:22.109: I/Process(17743): Sending signal. PID: 17743 SIG: 9
  </code></pre>
  
  <p>I don't know what's goin on this code, I hope someone out there could help to solve my problem. I really do hope.... Thanks for your attention...
  Terima kasih.</p>