앱이 꺼져 버리는 부분은 에디트를 작성하고나서 암호화 버튼을 선택하고
패스워드(키)를 입력하고서 버튼을 클릭할 때 프로그램이 죽습니다.
예외는 NullPointException인데 왜 이렇게 되었는지 이해가 가지 않습니다.
Edit.java
package org.memo.pkg;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import org.kisa.*;
public class Edit extends Activity implements Variable{
static{
System.loadLibrary("KISACrypto");
}
//iv
public static final byte[] iv = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
//key and inputKey
public static byte[] key = new byte[16];
public static byte[] KeyCode;
//input password
String password;
Button btn = null;
boolean isOpenEdit = false;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.edit);
final Intent intent = getIntent();
isOpenEdit = intent.getBooleanExtra("isOpenEdit", false);
if( isOpenEdit ){
EditText etFileName = (EditText)findViewById(R.id.et_filename);
EditText etMemo = (EditText)findViewById(R.id.et_edit);
etFileName.setText(intent.getStringExtra("FILENAME"));
etMemo.setText(intent.getStringExtra("FILECONTENT"));
}
ButtonProc(R.id.btn_save);
ButtonProc(R.id.btn_menu);
암호화 버튼은 아래부분입니다.
Button enBtn = (Button)findViewById(R.id.btn_encrypt);
enBtn.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v)
{
final LinearLayout linear = (LinearLayout)View.inflate(Edit.this, R.layout.keydialog2, null);
AlertDialog.Builder input = new AlertDialog.Builder(Edit.this);
input.setTitle("Notification");
input.setView(linear);
input.setMessage("Input your key");
input.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
EditText mUserText;
mUserText = (EditText)findViewById(R.id.trueyourKey);
password = mUserText.getText().toString();
KeyCode = stringToByte(password);
KeyManage.saveHashPass(KeyCode);
}
}).show();
}
});
}
//버튼 처리하기
public void ButtonProc(final int id)
{
btn = (Button)findViewById(id);
btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
switch(id)
{
case R.id.btn_save:
SaveProc();
break;
case R.id.btn_menu:
// finish();
Intent intent = new Intent(Edit.this, Memo.class);
startActivity(intent);
overridePendingTransition(R.anim.zoom_exit,R.anim.fade);
break;
}
}
});
}
//해시 처리 전 입력한 패스워드를 HIGHT의 키로 초기화
public static void initKey(byte[] pass)
{
for(int i=0;i<pass.length;i++)
{
key[i] = pass[i];
}
}
public void SaveEncrypt()
{
EditText cet = (EditText)findViewById(R.id.et_filename);
String enFileName = cet.getText().toString();
encryption(enFileName);
enFileName=enFileName+data.toString();
}
//저장 과정-일반 파일
public void SaveProc()
{
EditText et = (EditText)findViewById(R.id.et_filename);
String getFileName = et.getText().toString();
if( getFileName.equals(""))
{
Intent intent = new Intent(Edit.this, Message.class);
intent.putExtra("MESSAGE", NO_NAME);
startActivity(intent);
overridePendingTransition(R.anim.zoom_exit,R.anim.fade);
}
else
{
int iFileLeng = fileList().length;
if( iFileLeng != 0 )
{
boolean isAlreadyFile = false;
String[] sFileList = fileList();
for( int i = 0 ; i < iFileLeng ; i++)
{
if( sFileList[i].equals(getFileName) )
{
isAlreadyFile = true;
break;
}
}
if(isAlreadyFile)
{
Intent intent = new Intent(Edit.this, Message.class);
intent.putExtra("MESSAGE", ALREADY_FILE);
startActivity(intent);
overridePendingTransition(R.anim.zoom_exit,R.anim.fade);
}
else
{
FileSave(getFileName);
}
}
else
{
FileSave(getFileName);
}
}
}
//파일 저장,동시에 암호화 수행
//입력 키와 파일 이름을 인자로 지정
public void encryption(String sName)
{
byte[] plainText = new byte[128];
byte[] cipherText = new byte[136];
int outputTextLen = 0;
HIGHT hight = new HIGHT();
hight.init(HIGHT.ENC,key,iv);
try{
EditText et = (EditText)findViewById(R.id.et_edit);
byte[] buffer = stringToByte(et.getText().toString());
for(int i=0;i<buffer.length;i++)
{
plainText[i] = buffer[i];
}
outputTextLen = hight.process(plainText, plainText.length, cipherText, 0);
hight.close(cipherText, outputTextLen);
FileOutputStream fos = openFileOutput(sName,Context.MODE_PRIVATE);
fos.write(cipherText);
fos.flush();
fos.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//일반 파일
public void FileSave(String sName)
{
try {
EditText et = (EditText)findViewById(R.id.et_edit);
byte[] buffer = stringToByte(et.getText().toString());
FileOutputStream fos = openFileOutput(sName, Context.MODE_PRIVATE);
fos.write(buffer);
fos.flush();
fos.close();
} catch (IOException e)
{
e.printStackTrace();
}
Intent intent = new Intent(Edit.this, Message.class);
intent.putExtra("MESSAGE", SAVE_COMPLETE);
startActivityForResult(intent, 0);
}
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if( data.getAction().equals("ACTION_A")){
finish();
}
}
public byte[] stringToByte(String sBuffer)
{
byte[] bBuffer = new byte[sBuffer.length()];
for(int i = 0 ; i < sBuffer.length() ; i ++)
bBuffer[i]=(byte)sBuffer.charAt(i);
return bBuffer;
}
}
굵게 처리된 부분이 로그캣에 찍혀진 코드입니다.
혹시 몰라서 manifest.xml도 올립니다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.memo.pkg"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Memo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".OpenList"
android:label="@string/app_name">
</activity>
<activity android:name=".Edit"
android:label="@string/app_name">
</activity>
<activity android:name=".Read"
android:label="@string/app_name">
</activity>
<activity android:name=".Message"
android:label="@string/str_warningTitle"
android:theme="@android:style/Theme.Dialog">
</activity>
</application>
<uses-sdk android:minSdkVersion="8"/>
</manifest>
조언 부탁드립니다.ㅜㅜ
어떤 오류인지 봐도 이해가 안갑니다.
참고하시기 위해서 소스 자료도 올립니다,




EditText mUserText;
mUserText = (EditText)findViewById(R.id.trueyourKey);
password = mUserText.getText().toString();
->
EditText mUserText;
mUserText = (EditText) Edit.findViewById(R.id.trueyourKey); ( Edit.this.findviewById 일지도..)
password = mUserText.getText().toString();
로 고쳐보세요;;