2014-04-22 2 views
-2

로그인을 수락하는 내 안드로이드 응용 프로그램은 ruuning.It되지 않습니다 logcat.It에 다음과 같은 오류가 발생합니다. 그것을 해결할 수 없습니다. 도움이 될 것입니다. 나는 전체 code.If을 게시하고로그인 활동 안드로이드에서 실행되지 않음

04-22 17:42:55.786: W/dalvikvm(1353): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 
04-22 17:42:55.956: E/AndroidRuntime(1353): FATAL EXCEPTION: main 
04-22 17:42:55.956: E/AndroidRuntime(1353): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abhineel.studentinfo/com.abhineel.studentinfo.LoginActivity}: java.lang.NullPointerException 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at android.os.Handler.dispatchMessage(Handler.java:99) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at android.os.Looper.loop(Looper.java:137) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at android.app.ActivityThread.main(ActivityThread.java:5041) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at java.lang.reflect.Method.invokeNative(Native Method) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at java.lang.reflect.Method.invoke(Method.java:511) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at dalvik.system.NativeStart.main(Native Method) 
04-22 17:42:55.956: E/AndroidRuntime(1353): Caused by: java.lang.NullPointerException 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at com.abhineel.studentinfo.LoginActivity.onCreate(LoginActivity.java:67) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at android.app.Activity.performCreate(Activity.java:5104) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
04-22 17:42:55.956: E/AndroidRuntime(1353):  ... 11 more 

사전에 덕분에 쇼를 로그 캣 특정 줄에서 떨어져 다른 오류가 다음 패키지 com.abhineel 파일이 also.My LoginActivity.java 좀 도와주십시오있다 .studentinfo;

import java.util.ArrayList; 
import java.util.List; 

import org.apache.http.NameValuePair; 
import org.apache.http.message.BasicNameValuePair; 
import org.json.JSONException; 
import org.json.JSONObject; 

import android.app.Activity; 
import android.app.ProgressDialog; 
import android.content.Intent; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 

public class LoginActivity extends Activity implements OnClickListener{ 

    private EditText user, pass; 
    private Button mSubmit, mRegister; 

    // Progress Dialog 
    private ProgressDialog pDialog; 

    // JSON parser class 
    JSONParser jsonParser = new JSONParser(); 

    //php login script location: 

    //localhost : 
    //testing on your device 
    //put your local ip instead, on windows, run CMD > ipconfig 
    //or in mac's terminal type ifconfig and look for the ip under en0 or en1 
    // private static final String LOGIN_URL = "http://xxx.xxx.x.x:1234/webservice/login.php"; 

    //testing on Emulator: 
    private static final String LOGIN_URL = "http://10.0.2.2:80/androidProj/login.php"; 

    //testing from a real server: 
    //private static final String LOGIN_URL = "http://www.yourdomain.com/webservice/login.php"; 

    //JSON element ids from repsonse of php script: 
    private static final String TAG_SUCCESS = "success"; 
    private static final String TAG_MESSAGE = "message"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_login); 

     //setup input fields 
     user = (EditText)findViewById(R.id.usn); 
     pass = (EditText)findViewById(R.id.password); 

     //setup buttons 
     mSubmit = (Button)findViewById(R.id.login); 
     mRegister = (Button)findViewById(R.id.register); 

     //register listeners 
     mSubmit.setOnClickListener(LoginActivity.this); 
     mRegister.setOnClickListener(LoginActivity.this); 

    } 

    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     switch (v.getId()) { 
     case R.id.login: 
       new AttemptLogin().execute(); 
      break; 
     case R.id.register: 
       Intent i = new Intent(LoginActivity.this, RegisterActivity.class); 
       startActivity(i); 
      break; 

     default: 
      break; 
     } 
    } 

    class AttemptLogin extends AsyncTask<String, String, String> { 

     /** 
     * Before starting background thread Show Progress Dialog 
     * */ 
     boolean failure = false; 

     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      pDialog = new ProgressDialog(LoginActivity.this); 
      pDialog.setMessage("Attempting login..."); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(true); 
      pDialog.show(); 
     } 

     @Override 
     protected String doInBackground(String... args) { 
      // TODO Auto-generated method stub 
      // Check for success tag 
      int success; 
      String username = user.getText().toString(); 
      String password = pass.getText().toString(); 
      try { 
       // Building Parameters 
       List<NameValuePair> params = new ArrayList<NameValuePair>(); 
       params.add(new BasicNameValuePair("username", username)); 
       params.add(new BasicNameValuePair("password", password)); 

       Log.d("request!", "starting"); 
       // getting product details by making HTTP request 
       JSONObject json = jsonParser.makeHttpRequest(
         LOGIN_URL, "POST", params); 

       // check your log for json response 
       Log.d("Login attempt", json.toString()); 

       // json success tag 
       success = json.getInt(TAG_SUCCESS); 
       if (success == 1) { 
        Log.d("Login Successful!", json.toString()); 
        Intent i = new Intent(LoginActivity.this, ReadComments.class); 
        finish(); 
        startActivity(i); 
        return json.getString(TAG_MESSAGE); 
       }else{ 
        Log.d("Login Failure!", json.getString(TAG_MESSAGE)); 
        return json.getString(TAG_MESSAGE); 

       } 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 

      return null; 

     } 
     /** 
     * After completing background task Dismiss the progress dialog 
     * **/ 
     protected void onPostExecute(String file_url) { 
      // dismiss the dialog once product deleted 
      pDialog.dismiss(); 
      if (file_url != null){ 
       Toast.makeText(LoginActivity.this, file_url, Toast.LENGTH_LONG).show(); 
      } 

     } 

    } 

} 
+1

파일에서 LoginActivity.java 줄 번호 67을 표시하십시오 – Vladimir

+0

코드를 보여주십시오! – deleon

+0

스택 트레이스를 읽으십시오! – njzk2

답변

0

내가 볼 수있는 것이 몇 가지 있습니다.

doInBackground가 실제로 완료 될 때 제어하기 위해 콜백 메소드가있는 인터페이스를 사용하는 것이 좋습니다. 이처럼 AsyncTask를 클래스에 추가 할 수 있습니다 :

class AttemptLogin //extends AsyncTask etc { 

    static interface Callback { 
     void onComplete(String response); //could be any data like JsonObject,etc 
    } 

    Callback callback;   

    // in constructor take in instance of interface 
    AtemptLogin(Callback l_callback){ 
     callback = l_callback; 
    } 

    // in do onbackground 

    callback.onComplete(response); 
} 

// From activity 
new AttemptLogin(new AttemptLogin.Callback(
    @Overide 
    onComplete(String response){ 
     //handle response dismiss dialog etc 
    }) 
); 

은 또한 당신이 그것을 참조로 사람들을에 전달하는 더 좋은 생각이 될 수있는 비동기 작업에서 양식 위젯을 참조한다. 귀하의 코드에서 AsyncTask를 3 가지 유형으로 선언하고 있는데, AsyncTask에 대한 설명서를 가져오고 사용하는 방법에 대한 세 가지 일반 정보를 읽습니다. http://developer.android.com/reference/android/os/AsyncTask.html

클릭 액자와 마찬가지로 활동 자체가 있습니다. 이것은 부분적으로 관련이 있지만 웹 서비스가 반환 할 때 이벤트를 처리 할 수 ​​있어야하고 등록 버튼에서 수행하는 것처럼 의도를 실행해야합니다. 현재 doInBackground에서 널 포인터 예외가 발생합니다.

관련 문제