I've been stucked to find what's wrong with my code below.
here's the MainActivity.java
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 < 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;
}
}
Here's the MainActivity.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Plaintext"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/txtPlain"
android:hint="Masukkan plaintext"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Key"
/>
<EditText
android:layout_width="fill_parent"
android:hint="Masukkan Key"
android:layout_height="wrap_content"
android:id="@+id/txtKey"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Encrypt"
android:id="@+id/btnEncrypt"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cipher (Hill Cipher)"
/>
<EditText
android:layout_width="fill_parent"
android:hint=""
android:layout_height="wrap_content"
android:id="@+id/txtCipher"
/>
</LinearLayout>
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
Log.txt
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
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.
angka_arrayArray.