Hallo!
Ich habe mich mal an einer App versucht, die eingegebenen Text um eine bestimmte anzahl stelle in der ASCI-Tabelle verschieben soll.
Ich habe nun das Problem das die App jedesmal abstürzt, wenn ich den Button drücke.
ich habe keine ahnung warum.
Bitte um Hilfe.
die Activity_main.java
die Activity_main.xml
Ich habe mich mal an einer App versucht, die eingegebenen Text um eine bestimmte anzahl stelle in der ASCI-Tabelle verschieben soll.
Ich habe nun das Problem das die App jedesmal abstürzt, wenn ich den Button drücke.
ich habe keine ahnung warum.
Bitte um Hilfe.
die Activity_main.java
Java:
package com.example.messagecrypter;
import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText edt_tocryptsmg = (EditText)findViewById(R.id.editText1);
final EditText edt_offset = (EditText)findViewById(R.id.editText2);
final TextView tw_cryotmsg = (TextView)findViewById(R.id.textView3);
Button btn_encrypt = (Button)findViewById(R.id.button1);
btn_encrypt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final String strEdt2 = edt_tocryptsmg.toString();
final Editable textEdt1 = edt_offset.getText();
final String strEdt1 = textEdt1.toString();
int offset = Integer.parseInt(strEdt1);
offset = offset%128;
char[] myArray = strEdt2.toCharArray();
char[] myNewArray = encrypt(offset, myArray);
for (int i = 0; i < myNewArray.length; i++) {
tw_cryotmsg.setText(myNewArray[i]);
}
myNewArray = decrypt(offset, myNewArray);
for (int i = 0; i< myNewArray.length; i++) {
tw_cryotmsg.setText(myNewArray[i]);
}
}});
}
public static char[] encrypt(int offset, char[] charArray) {
char[] cryptArray = new char[charArray.length];
for (int i = 0; i < charArray.length; i++) {
int verschiebung = (charArray[i] + offset)%128;
cryptArray[i] = (char) (verschiebung);
}
return cryptArray;
}
public static char[] decrypt(int offset, char[] charArray) {
char[] cryptArray = new char[charArray.length];
int verschiebung;
for (int i = 0; i < charArray.length; i++) {
if (charArray[i] - offset < 0) verschiebung =
charArray[i] - offset + 128;
else verschiebung = (charArray[i] - offset)%128;
cryptArray[i] = (char) (verschiebung);
}
return cryptArray;
}
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/blackscreen"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.messagecrypter.MainActivity" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_below="@+id/editText1"
android:layout_marginTop="14dp"
android:text="Encryption type:"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText1"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:textColor="#FFFFFF"
android:ems="10" >
<requestFocus />
</EditText>
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:textColor="#FFFFFF"
android:text="ASCI-Rotation" />
<EditText
android:id="@+id/editText2"
android:layout_width="140dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/radioButton1"
android:ems="10"
android:textColor="#FFFFFF"
android:inputType="number"
android:text="rotate by" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignLeft="@+id/radioButton1"
android:layout_below="@+id/radioButton1"
android:textColor="#FFFFFF"
android:text="Comming soon..." />
<RadioButton
android:id="@+id/RadioButton01"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/radioButton2"
android:textColor="#FFFFFF"
android:text="Comming soon..." />
>
<Button
android:id="@+id/Button02"
android:layout_width="140dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/radioButton1"
android:background="@drawable/buttonshape"
android:text="copy"
android:textColor="#FFFFFF"
android:textSize="25sp" />
<Button
android:id="@+id/Button03"
android:layout_width="140dp"
android:layout_height="40dp"
android:layout_alignBaseline="@+id/Button02"
android:layout_alignBottom="@+id/Button02"
android:layout_toRightOf="@+id/radioButton2"
android:background="@drawable/buttonshape"
android:text="share"
android:textColor="#FFFFFF"
android:textSize="25sp" />
<TextView
android:id="@+id/textView3"
android:layout_width="285dp"
android:layout_height="80dp"
android:layout_above="@+id/Button02"
android:layout_alignRight="@+id/Button03"
android:layout_marginBottom="24dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/radioButton1"
android:layout_alignParentTop="true"
android:text="Your Message: "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<Button
android:id="@+id/button1"
android:layout_width="140dp"
android:layout_height="40dp"
android:layout_above="@+id/textView3"
android:layout_alignLeft="@+id/textView3"
android:layout_marginBottom="14dp"
android:background="@drawable/buttonshape"
android:text="encrypt"
android:textColor="#FFFFCC"
android:textSize="25sp" />
<Button
android:id="@+id/Button04"
android:layout_width="140dp"
android:layout_height="40dp"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_alignRight="@+id/textView3"
android:background="@drawable/buttonshape"
android:text="decrypt"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</RelativeLayout>