2012-03-03 4 views
0

내 응용 프로그램을 시작할 때마다 파일을 만든 새 에뮬레이터에서도 파일을 만들었습니다. 즉, 파일이 만들어지면이 의도를 수행합니다. , 나는 이해할 수 없다, 안된다. 안드로이드 폰이 아니기 때문에 테스트 할 방법이 없다. 이론적으로 두 번째로 앱을로드 할 때만 코드를 호출하면 안된다.응용 프로그램이 로그인 화면을 우회하지 않아도

감사합니다.

코드 : if (file.exists()); 조건에 해당하는 경우 실행 블록으로 간주합니다 :

Public class LogIn extends Activity implements OnClickListener { 
    Button send; 
    EditText user; 
    EditText pass; 
    CheckBox staySignedIn; 
    FileOutputStream Fos; 
    String a; 
    String b; 
    String string = a; 
    String string2 = b; 
    String DANNYISREALLLLYYYGAAYYYYYIMNOTBS; 

    String FILENAME = "userandpass"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.login); 
     send = (Button) findViewById(R.id.bLogIn); 
     user = (EditText) findViewById(R.id.eTuser); 
     pass = (EditText) findViewById(R.id.eTpassword); 
     staySignedIn = (CheckBox) findViewById(R.id.Cbstay); 
     send.setOnClickListener(this); 
     File file = getBaseContext().getFileStreamPath(FILENAME); 
     if (file.exists()); 
     Intent i = new Intent(LogIn.this, ChatService.class); 
     startActivity(i);}  


    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     switch (v.getId()) { 
     case R.id.bLogIn: 
      if (pass.length() == 0) 
       Toast.makeText(this, 
         "Try to type in your username and password again!", 
         Toast.LENGTH_LONG).show(); 
      else if (user.length() == 0) 
       Toast.makeText(this, 
         "Try to type in your username and password again!", 
         Toast.LENGTH_LONG).show(); 
      { 
       if (staySignedIn.isChecked()) { 

       String a = user.getText().toString(); 
       String b = pass.getText().toString(); 
       File f = new File(FILENAME); 
       try { 
        Fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); 
        if (Fos != null) { 
        Fos.write(a.getBytes()); 
        Fos.write(b.getBytes()); 
        } 
        Fos.close(); 
       } catch (FileNotFoundException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } catch (IOException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       }finally { 
         String u = user.getText().toString(); 
         String p = pass.getText().toString(); 
         Bundle send = new Bundle(); 
         send.putString("key", u); 
         send.putString("key1", p); 
         Intent c = new Intent(LogIn.this, logincheck.class); 
         c.putExtra("key", u); 
         c.putExtra("key1", p); 
         startActivity(c); 
         Toast.makeText(this, "Were signing you in!", Toast.LENGTH_LONG) 
           .show(); 
         if (!staySignedIn.isChecked()) { 
          finish(); 

         break; 
         } 
       } 
       } 
      } 





      } 
     } 
    } 

답변

0

당신은 테스트 후 세미콜론이있다. 세미콜론 만 빼면 괜찮을 것입니다.

+0

, 나는 앱 충돌이 일어난다. – TheBlueCat

+0

분명히이 코드에는 많은 의문점이 있습니다. 이 경우 충돌이 없어야하지만 전혀 작동하지 않아야합니다. 나는 원래의 질문이 농담이라고 두려워 ... –

+0

정말 이해가 안되니? – TheBlueCat

0

jbowes 당신이 코드가있는 경우가 여전히 발생합니다 어떤 예외 말해 충돌하는 경우 응용 프로그램이 이런 식으로

if (file.exists()) 
{ 
     Intent i = new Intent(LogIn.this, ChatService.class); 
     startActivity(i); 
} 

에 을 중단해야 아무 소용이없는 세미콜론을 제거 말했듯이

관련 문제