2012-01-12 69 views
0

當我點擊提交按鈕...當我調試時顯示爲「未找到源」...並在設備中顯示應用程序意外停止工作...來源未找到 - 應用程序意外停止工作

Button btnSubmit = (Button) findViewById(R.id.btnSubmit); 
     btnSubmit.setOnClickListener(new View.OnClickListener() {       
      public void onClick(View view) { 
       //finish(); 
       //Intent DiscIntent = new Intent (view.getContext(), Disclaimer.class); 
       //startActivityForResult(DiscIntent, 0); 
       if(ValidateInformation()) 
       { 
        EditText etUserName = (EditText)findViewById(R.id.txtUserName); 

       if(UserNameAvailability(view, etUserName.getText().toString().trim())) 

我logcat的細節如下...

01-12 16:52:39.664: E/AndroidRuntime(338): Uncaught handler: thread main exiting due to uncaught exception 
01-12 16:52:39.674: E/AndroidRuntime(338): java.lang.NullPointerException: println needs a message 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.util.Log.println(Native Method) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.util.Log.w(Log.java:157) 
01-12 16:52:39.674: E/AndroidRuntime(338): at com.anb.eCalculator.RegisterActivity.UserNameAvailability(RegisterActivity.java:236) 
01-12 16:52:39.674: E/AndroidRuntime(338): at com.anb.eCalculator.RegisterActivity$3.onClick(RegisterActivity.java:73) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.View.performClick(View.java:2364) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.View.onTouchEvent(View.java:4179) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.widget.TextView.onTouchEvent(TextView.java:6541) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.View.dispatchTouchEvent(View.java:3709) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
01-12 16:52:39.674: E/AndroidRuntime(338): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) 
01-12 16:52:39.674: E/AndroidRuntime(338): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.app.Activity.dispatchTouchEvent(Activity.java:2061) 
01-12 16:52:39.674: E/AndroidRuntime(338): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.os.Handler.dispatchMessage(Handler.java:99) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.os.Looper.loop(Looper.java:123) 
01-12 16:52:39.674: E/AndroidRuntime(338): at android.app.ActivityThread.main(ActivityThread.java:4363) 
01-12 16:52:39.674: E/AndroidRuntime(338): at java.lang.reflect.Method.invokeNative(Native Method) 
01-12 16:52:39.674: E/AndroidRuntime(338): at java.lang.reflect.Method.invoke(Method.java:521) 
01-12 16:52:39.674: E/AndroidRuntime(338): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
01-12 16:52:39.674: E/AndroidRuntime(338): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
01-12 16:52:39.674: E/AndroidRuntime(338): at dalvik.system.NativeStart.main(Native Method) 

我UserNameAvailability功能低於

protected boolean UserNameAvailability(View view, final String sUserName) 

{
布爾結果=假;

SoapObject request = new SoapObject(getResources().getString(R.string.targetnamespace), getResources().getString(R.string.usernameavailabilitymethod)); 
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.dotNet = true; 

PropertyInfo piUserName = new PropertyInfo(); 
piUserName.name = "UserName"; 

request.addProperty(piUserName, sUserName); 

HttpTransportSE httpTransport = new HttpTransportSE(getResources().getString(R.string.webserviceurl));     
    try { 
     httpTransport.debug =true; 
     httpTransport.call(getResources().getString(R.string.usernameavailabilitysoapaction), envelope);      
     SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 
     if (!response.toString().equals("false")) { 
      result = true; 

     } 
     else 
     { 
      alertBox("User Name already exists.Please enter different username."); 
     } 

     }catch (Exception exception) { 
     Log.w("UserRegistration - RegisterActivity", exception.getMessage()); 
     } 


     return result; 

}

我的完整的按鈕單擊事件低於

Button btnSubmit = (Button) findViewById(R.id.btnSubmit); 
     btnSubmit.setOnClickListener(new View.OnClickListener() {       
      public void onClick(View view) { 
       //finish(); 
       //Intent DiscIntent = new Intent (view.getContext(), Disclaimer.class); 
       //startActivityForResult(DiscIntent, 0); 
       if(ValidateInformation()) 
       { 
        EditText etUserName = (EditText)findViewById(R.id.txtUserName); 

       if(UserNameAvailability(view, etUserName.getText().toString().trim())) 
       { 
       EditText etFirstName = (EditText)findViewById(R.id.txtFirstName); 
       EditText etLastName = (EditText)findViewById(R.id.txtLastName);   
       EditText etEmail = (EditText)findViewById(R.id.txtEmail);  
       EditText etQuery= (EditText)findViewById(R.id.txtQuery); 
       EditText etTelephone = (EditText)findViewById(R.id.txtTelePhone); 
       EditText etOrganization = (EditText)findViewById(R.id.txtOrganization); 
       EditText etRegion = (EditText)findViewById(R.id.txtRegionCountry); 
       EditText etPassword = (EditText)findViewById(R.id.txtPassword); 
       EditText etConfirmPassword = (EditText)findViewById(R.id.txtConfirmPassword);//Added By Prakash 
       //EditText etUserName1 = (EditText)findViewById(R.id.txtUserName); 



       Bundle bunUserInfo = new Bundle(); 
       bunUserInfo.putString("UserName", etUserName.getText().toString()); 
       bunUserInfo.putString("FirstName", etFirstName.getText().toString()); 
       bunUserInfo.putString("LastName", etLastName.getText().toString()); 
       bunUserInfo.putString("Email", etEmail.getText().toString()); 
       bunUserInfo.putString("Query", etQuery.getText().toString()); 
       bunUserInfo.putString("Telephone", etTelephone.getText().toString()); 
       bunUserInfo.putString("Organization", etOrganization.getText().toString()); 
       bunUserInfo.putString("Region", etRegion.getText().toString()); 
       bunUserInfo.putString("Password", etPassword.getText().toString()); 
       bunUserInfo.putString("ConfirmPassword", etConfirmPassword.getText().toString()); 
       //bunUserInfo.putString("UserName", etUserName1.getText().toString()); 




       Intent goToNextActivity = new Intent(getApplicationContext(), Disclaimer.class); 
       goToNextActivity.putExtras(bunUserInfo); 
       startActivity(goToNextActivity); 
       } 
       else 
       { 
        alertBox("User Name already exists. Please enter different User Name."); 
       } 
      } 

      } 
     }); 
+0

你確定你的整個代碼只是那麼多嗎? – Ghost 2012-01-12 11:36:51

+1

您可能想要發佈函數UserNameAvailability的來源以及發生異常:) – Fge 2012-01-12 11:37:15

+1

您的日誌說您的RegisterActivity類的第236行中,您嘗試記錄沒有任何消息文本的警告消息。 – THelper 2012-01-12 11:39:32

回答

2

我的猜測是,UserNameAvailability某處null參數調用Log.w。

在UserNameAvailability中查找對Log.w的調用,其中標記或消息爲空。

+0

我無法弄清楚...我發佈了我的整個代碼...你可以看看它並說我顯然...對不起...我是新的Android開發 – Prakash 2012-01-12 12:07:32

+1

我覺得exception.getMessage()似乎爲空,而不是使用一些常量字符串或exeption.printStacktrace()。 – Vamsi 2012-01-12 12:25:02

1

改變這一行

Log.w("UserRegistration - RegisterActivity", exception.getMessage()); 

Log.w("UserRegistration - RegisterActivity", "Error message is "+exception.getMessage(), exception); 

這樣,你將永遠有一個消息(和你的日誌堆棧跟蹤),即使exception.getMessage()函數返回null;