이 코드는 그가 입력 한 사용자 이름과 비밀번호로 새 사용자를 생성 한 다음 그 이메일과 일치하는 파일 이름으로 폰 메모리에 새로운 객체를 저장하기 때문에 로그인 방법에서 입력 된 전자 메일과 일치하는 파일을 찾으십시오. deserialize하고 모든 사용자 정보가있을 것입니다 ... 그러나 FileNotFooundException을 계속 유지합니다 ... 이해가 안됩니다 ... 누군가 나를 도와주세요! :) 여기 안드로이드 - 내부 메모리에 객체 저장
코드입니다 :package com.example.eventmanager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class CreateAccount extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_account);
}
public void createUserAccount(View v) {
EditText username = (EditText) findViewById(R.id.editText1);
EditText password = (EditText) findViewById(R.id.editText2);
EditText secondPassword = (EditText) findViewById(R.id.editText3);
if (!(password.getText().toString().equals((secondPassword.getText()
.toString())))) {
Toast.makeText(this, "Passwords Don't Match", Toast.LENGTH_LONG).show();
} else {
User newUser = new User(username.getText().toString(), password.getText().toString());
String fileName = newUser.getEmail();
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(fileName));
os.writeObject(newUser);
os.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
Toast.makeText(this, "FileNotFoundException", Toast.LENGTH_LONG)
.show();
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Toast.makeText(this, "IOException", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
Intent intent = new Intent(this, LoginScreen.class);
startActivity(intent);
Toast.makeText(this, "Account Created Successfully",
Toast.LENGTH_LONG).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_create_account, menu);
return true;
}
}
fileName을 인쇄하는 Toast를 추가했으며 결과는 사용자가 입력 한 문자열입니다. 유효한 파일 이름입니까? –
@DerekLurette 사용자가 입력 한 파일 이름은 무엇입니까? 또한 프로그램에서 파일을 만들 수있는 권한이 있습니다. 전체 관련 오류 스택 추적을 공유 할 수 있습니까? –
파일 이름은 abc ...이고 파일을 만들려면 액세스 권한이 있어야한다는 것을 모릅니다 ... 어떻게 액세스 할 수 있습니까? :/.... 그리고 나는 이클립스와 안드로이드 API에 익숙하지 않다 ... 미안하게 스택 추적을 얻는 방법을 모르겠다! –