2014-02-27 2 views
1

저는 안드로이드를 배우면서 저를 도와주세요. 그것은 내가 logcat에 다음과 같은 오류를 제공합니다.VM 종료

02-27 14:14:42.455: D/dalvikvm(1655): GC_FOR_ALLOC freed 46K, 5% free 2891K/3020K, paused 152ms, total 156ms 
02-27 14:14:42.465: I/dalvikvm-heap(1655): Grow heap (frag case) to 3.668MB for 810016-byte allocation 
02-27 14:14:42.545: D/dalvikvm(1655): GC_FOR_ALLOC freed 2K, 4% free 3680K/3812K, paused 76ms, total 77ms 
02-27 14:14:43.425: I/Choreographer(1655): Skipped 35 frames! The application may be doing too much work on its main thread. 
02-27 14:14:43.645: D/gralloc_goldfish(1655): Emulator without GPU emulation detected. 
02-27 14:14:48.395: I/Choreographer(1655): Skipped 58 frames! The application may be doing too much work on its main thread. 
02-27 14:14:49.725: I/Choreographer(1655): Skipped 58 frames! The application may be doing too much work on its main thread. 
02-27 14:14:52.355: I/Choreographer(1655): Skipped 61 frames! The application may be doing too much work on its main thread. 
02-27 14:14:55.195: D/AndroidRuntime(1655): Shutting down VM 
02-27 14:14:55.195: W/dalvikvm(1655): threadid=1: thread exiting with uncaught exception (group=0xb3aaaba8) 
02-27 14:14:55.275: E/AndroidRuntime(1655): FATAL EXCEPTION: main 
02-27 14:14:55.275: E/AndroidRuntime(1655): Process: com.example.dreamhome, PID: 1655 
02-27 14:14:55.275: E/AndroidRuntime(1655): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dreamhome/com.example.dreamhome.LoginFormActivity}: java.lang.NullPointerException 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at android.os.Handler.dispatchMessage(Handler.java:102) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at android.os.Looper.loop(Looper.java:136) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at android.app.ActivityThread.main(ActivityThread.java:5017) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at java.lang.reflect.Method.invoke(Method.java:515) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at dalvik.system.NativeStart.main(Native Method) 
02-27 14:14:55.275: E/AndroidRuntime(1655): Caused by: java.lang.NullPointerException 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at com.example.dreamhome.LoginFormActivity.onCreate(LoginFormActivity.java:45) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at android.app.Activity.performCreate(Activity.java:5231) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
02-27 14:14:55.275: E/AndroidRuntime(1655):  ... 11 more 
02-27 14:15:03.295: I/Process(1655): Sending signal. PID: 1655 SIG: 9 

HomeActivity.java

public class HomeActivity extends Activity 
{ 
Button search_property, log_in, exit; 


@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_home); 

    search_property=(Button)findViewById(R.id.homebutton1); 
    log_in=(Button)findViewById(R.id.homebutton2); 
    exit=(Button)findViewById(R.id.homebutton3); 


    search_property.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 

      Intent main1=new Intent(HomeActivity.this,EndUserSearchPropertyActivity.class); 
      startActivity(main1); 

     } 
    }); 


    log_in.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 

      Intent main2 = new Intent(HomeActivity.this,LoginFormActivity.class); 
      startActivity(main2); 

     } 
    }); 


    exit.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 
      finish(); 
      System.exit(0); 

     } 
    }); 



    // Show the Up button in the action bar. 
    setupActionBar(); 
} 

/** 
* Set up the {@link android.app.ActionBar}. 
*/ 
private void setupActionBar() 
{ 

    getActionBar().setDisplayHomeAsUpEnabled(true); 

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) 
{ 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.home, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) 
{ 
    switch (item.getItemId()) 
    { 
     case android.R.id.home: 
     // This ID represents the Home or Up button. In the case of this 
     // activity, the Up button is shown. Use NavUtils to allow users 
     // to navigate up one level in the application structure. For 
     // more details, see the Navigation pattern on Android Design: 
     // 
     // http://developer.android.com/design/patterns/navigation.html#up-vs-back 
     // 
     NavUtils.navigateUpFromSameTask(this); 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

public class LoginFormActivity extends Activity 
{ 

private Button sign_up = null; 
private Button btnSignIn = null; 
LoginDataBaseAdapter loginDataBaseAdapter = null; 


@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_login_form); 


    // create a instance of SQLite Database 
    loginDataBaseAdapter=new LoginDataBaseAdapter(this); 
    loginDataBaseAdapter=loginDataBaseAdapter.open(); 


    final Dialog dialog = new Dialog(LoginFormActivity.this); 

    // get the Refferences of views 
    final EditText editTextUserName=(EditText)dialog.findViewById(R.id.login_editText1); 
    final EditText editTextPassword=(EditText)dialog.findViewById(R.id.login_editText2); 

    btnSignIn = (Button)dialog.findViewById(R.id.login_form_button1); 
    // Set On ClickListener 
    btnSignIn.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 
      // get The User name and Password 
      String userName = editTextUserName.getText().toString(); 
      String password = editTextPassword.getText().toString(); 

      // fetch the Password form database for respective user name 
      String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName); 

      // check if the Stored password matches with Password entered by user 
      if(password.equals(storedPassword)) 
      { 
       Toast.makeText(LoginFormActivity.this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show(); 
       dialog.dismiss(); 
      } 

      else 
      { 
       Toast.makeText(LoginFormActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show(); 
      } 
     } 
    }); 

    dialog.show(); 
    } 


@Override 
protected void onDestroy() 
{ 
    super.onDestroy(); 
    // Close The Database 
    loginDataBaseAdapter.close(); 



    sign_up = (Button)findViewById(R.id.login_form_button2); 

    sign_up.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 

      Intent main2=new Intent(LoginFormActivity.this,SignupFormActivity.class); 
      startActivity(main2); 

     } 
    }); 



    // Show the Up button in the action bar. 
    setupActionBar(); 
} 

/** 
* Set up the {@link android.app.ActionBar}. 
*/ 
private void setupActionBar() 
{ 

    getActionBar().setDisplayHomeAsUpEnabled(true); 

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) 
{ 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.login_form, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) 
{ 
    switch (item.getItemId()) 
    { 
     case android.R.id.home: 
     // This ID represents the Home or Up button. In the case of this 
     // activity, the Up button is shown. Use NavUtils to allow users 
     // to navigate up one level in the application structure. For 
     // more details, see the Navigation pattern on Android Design: 
     // 
     // http://developer.android.com/design/patterns/navigation.html#up-vs-back 
     // 
     NavUtils.navigateUpFromSameTask(this); 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

LoginFormActivity.java}

+2

45 번째 줄에 NullPointerException이 있습니다. – zmbq

+2

여기에 문제가 없지만 System.exit을 사용하면 안드로이드 응용 프로그램을 닫는 좋은 방법이 아닙니다. http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238#2034238 및 http://stackoverflow.com/a/16480930/261821을 참조하십시오. –

답변

1
final Dialog dialog = new Dialog(LoginFormActivity.this); 

dialog을 인스턴스화하는 것만으로 레이아웃이 팽창하거나 생성되지 않습니다. 모든 후속 dialog.findViewById() 호출 null 반환 당신은 NPE 여기에 null 참조에 메소드를 호출하려고 시도하는거야 :

btnSignIn = (Button)dialog.findViewById(R.id.login_form_button1); 
// Set On ClickListener 
btnSignIn.setOnClickListener(new View.OnClickListener() 
당신은 아마 당신이 참조 할 모든 뷰와 대화에 콘텐츠보기를 설정해야

. 대화 상자가 표시된 후보기를 findViewById()과 함께 사용할 수 있습니다.