2012-07-11 187 views
0

我試圖讓Salesforce的REST API與Android和新到Android編程工作,隨後將樣品代碼與SFDC http://wiki.developerforce.com/page/Getting_Started_with_the_Mobile_SDK_for_Android#Authentication連接與Android Salesforce的REST API - NullPointerException異常@ AsyncRequestCallback

我試圖讓來自SFDC的幾條記錄並將它們顯示在android應用程序中,看起來像是在「client.sendAsync(sfRequest,new AsyncRequestCallback())發出異步調用時拋出NullPointerException」。

我看過一些類似的網上問題,但沒有幫助我,希望如果有人會指出我在正確的方向排查此問題,非常感謝

public class GetAccountsActivity extends Activity { 

    private PasscodeManager passcodeManager; 

    private String soql; 
    private String apiVersion; 
    private RestClient client; 
    private TextView resultText; 
    private RestRequest sfRequest; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     // Get Api Version 
     apiVersion = getString(R.string.api_version); 
     //Create Query 
     soql = "select id, name from Account limit 10"; 

     // Setup view 
     setContentView(R.layout.get_accounts_activity); 
     ((TextView) findViewById(R.id.Acc_Title)).setText(apiVersion); 
     // Passcode manager 

     passcodeManager = ForceApp.APP.getPasscodeManager(); 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 

    //Get SFClient 
     // Login options 
     String accountType = ForceApp.APP.getAccountType(); 
     LoginOptions loginOptions = new LoginOptions(
       null, // login host is chosen by user through the server picker 
       ForceApp.APP.getPasscodeHash(), 
       getString(R.string.oauth_callback_url), 
       getString(R.string.oauth_client_id), 
       new String[] {"api"}); 

     new ClientManager(this, accountType, loginOptions).getRestClient(this, new RestClientCallback() { 
      @Override 
      public void authenticatedRestClient(RestClient client) { 
       if (client == null) { 
        ForceApp.APP.logout(GetAccountsActivity.this); 
        return; 
       } 
       GetAccountsActivity.this.client = client; 
      } 
     }); 
      //Get Rest Object to query 
      try { 
       sfRequest = RestRequest.getRequestForQuery(apiVersion, soql); 
       //Use SF Rest Client to send the request 
       client.sendAsync(sfRequest, new AsyncRequestCallback(){ 
        @Override 
        public void onSuccess(RestRequest request, RestResponse response){ 
        //Check responses and display results 
        // EventsObservable.get().notifyEvent(EventType.RenditionComplete); 
        }//end onSuccess 

        @Override 
        public void onError(Exception exception) { 
         //printException(exception); 
         EventsObservable.get().notifyEvent(EventType.RenditionComplete);     
        }//End Exception for Async Method 
       }); 
      }catch (UnsupportedEncodingException e) { 
       //printHeader("Could Send Query request"); 
       //printException(e); 
       return; 
      } 
    } 
} 

在這裏輸入的代碼

+0

感謝您的問題,但我想知道您是如何在您的應用程序中導入ForceApp的,請您分享一些有用的信息。提前感謝。 – 2014-02-18 07:15:59

回答

0

要調用從的onResume client.sendAsync(),但客戶沒有設置直到authenticatedRestClient回調被調用,您需要將您的sendAsync呼叫轉移到authenticatedRestClient回調。

+0

感謝那個superfella。這工作。 – bluesky 2012-07-11 20:21:35

相關問題