none
Cannot Fetch data from azure to android app

    Question

  • Hello

    I have a database in azure, and now I want to retrieve some data into my app but on clicking the button, the text view shows me exception: Mobileserviceexception: error while processing request.

    Here is my code: please guide.

    try {
    // Create the Mobile Service Client instance, using the provided
    // Mobile Service URL and key
    mClient = new MobileServiceClient(
    "url",
    "APPKEY",

    this);

    Button btn = (Button)findViewById(R.id.search_btn);
    final TextView tv = (TextView) findViewById(R.id.tv);

    btn.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    mSportTypeDtls = mClient.getTable("ZMOB_SPORT_TYPE_DTLS", ZMOB_SPORT_TYPE_DTLS.class);
    mSportTypeDtls.where().field("sportId").eq(3).execute(new TableQueryCallback<ZMOB_SPORT_TYPE_DTLS>() {
    @Override
    public void onCompleted(List<ZMOB_SPORT_TYPE_DTLS> result, int count, Exception exception, ServiceFilterResponse response) {
    // System.out.println("hiiiii"+count);
    if(exception!=null){
    tv.setText(exception.toString());
    }
    else{
    StringBuffer sb = new StringBuffer();
    for(ZMOB_SPORT_TYPE_DTLS z:result){
    System.out.println(z.getmSportName());
    sb.append(z.getmSportName());
    }
    tv.setText(sb.toString());
    }
    }
    });

    }
    });

    }
    catch (MalformedURLException e) {
    createAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error");
    }
    }

    Sunday, September 22, 2013 5:53 AM

Answers

  • Just wanted to complete this thread that I figured out my problem long back. The problem was just that I was passing the wrong link for mobile services. I was passing the website url in azure instead of mobile.. 
    • Marked as answer by akshitag Tuesday, November 05, 2013 12:16 AM
    Tuesday, November 05, 2013 12:16 AM

All replies

  • The 'response' parameter to the callback should have more information about the response, and why the exception was returned. If you get the status line (response.getStatus()), or the content (response.getContent()) you should have more information on why the request didn't succeed. You can also check the logs on the portal for the mobile service to see if there is any entry which would explain why the request was rejected.

    Carlos Figueira

    Monday, September 23, 2013 10:28 PM
  • Hey Carlos

    I added these lines:

    mSportTypeDtls.select("sportId", "sportName").execute(new TableQueryCallback<ZMOB_SPORT_TYPE_DTLS>() {
    @Override
    public void onCompleted(List<ZMOB_SPORT_TYPE_DTLS> result, int count, Exception exception, ServiceFilterResponse response) {
    System.out.println("COuNt-->"+mSportTypeDtls.includeInlineCount());
    System.out.println("content-->"+response.getContent());
    System.out.println("status-->"+response.getStatus());

    Its giving me null pointer exception. I changed the query too so that all my rows should be printed but count is empty. nothing is printed with it.

    I just want to test whether I am able to fetch data from the azure or not. Please guide.

    Also, in my table class, I have created an id field as it was mentioned in some tutorial. It runs only with that dummy id field. In my database i have not made that field, only the sportId along with other columns are there. I am pasting both the classes. 

    Here is my entire code:

    //MainActivity.java

    public class MainActivity extends Activity {

    private MobileServiceClient mClient;

    private MobileServiceTable<ZMOB_SPORT_TYPE_DTLS> mSportTypeDtls;

    private ProgressBar mProgressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    try {
    // Create the Mobile Service Client instance, using the provided
    // Mobile Service URL and key
    mClient = new MobileServiceClient(
    "https://sport-ody.azure-mobile.net/",
    "DJCRXwipsSiYqgMhIHofEuawjiGjhn57",

    this);

    //create an adapter to bind the items with the view
    Button btn = (Button)findViewById(R.id.search_btn);
    final TextView tv = (TextView) findViewById(R.id.tv);

    btn.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
    mSportTypeDtls = mClient.getTable("ZMOB_SPORT_TYPE_DTLS", ZMOB_SPORT_TYPE_DTLS.class);

    //mSportTypeDtls.where().field("sportId").eq(3).execute(new TableQueryCallback<ZMOB_SPORT_TYPE_DTLS>() {
    mSportTypeDtls.select("sportId", "sportName").execute(new TableQueryCallback<ZMOB_SPORT_TYPE_DTLS>() {
    @Override
    public void onCompleted(List<ZMOB_SPORT_TYPE_DTLS> result, int count, Exception exception, ServiceFilterResponse response) {
    System.out.println("COuNt-->"+mSportTypeDtls.includeInlineCount());
    System.out.println("content-->"+response.getContent());
    System.out.println("status-->"+response.getStatus());
    if(exception!=null){
    tv.setText(exception.toString());
    }
    else{
    StringBuffer sb = new StringBuffer();
    for(ZMOB_SPORT_TYPE_DTLS z:result){
    System.out.println(z.getmSportName());
    sb.append(z.getmSportName());
    }
    tv.setText(sb.toString());
    }
    }
    });

    }
    });


    //method call to load items from mobile service

    }
    catch (MalformedURLException e) {
    createAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error");
    }
    }

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

    private void createAndShowDialog(Exception exception, String title) {
    createAndShowDialog(exception.toString(), title);
    }
    private void createAndShowDialog(String message, String title) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setMessage(message);
    builder.setTitle(title);
    builder.create().show();
    }

    }

    ------------------------------------------------------------------------------------------------------------------------------

    //my table class

    public class ZMOB_SPORT_TYPE_DTLS {

    @com.google.gson.annotations.SerializedName("id")
    private int mId;

    @com.google.gson.annotations.SerializedName("sportId")
    private int mSportId; //

    @com.google.gson.annotations.SerializedName("sportName")
    private String mSportName;

    @com.google.gson.annotations.SerializedName("sportDesc")
    private String mSportDesc;

    @com.google.gson.annotations.SerializedName("logoFileName")
    private String mLogoFileName;

    @com.google.gson.annotations.SerializedName("logoPath")
    private String mlogoPath;

    @com.google.gson.annotations.SerializedName("creDate")
    private Date mCreDate;

    @com.google.gson.annotations.SerializedName("creUserSNo")
    private String mCreUserSNo;

    @com.google.gson.annotations.SerializedName("sportCategory")
    private String mSportCategory;

    public int getmSportId() {
    return mSportId;
    }

    public void setmSportId(int mSportId) {
    this.mSportId = mSportId;
    }

    public String getmSportName() {
    return mSportName;
    }

    public void setmSportName(String mSportName) {
    this.mSportName = mSportName;
    }

    public String getmSportDesc() {
    return mSportDesc;
    }

    public void setmSportDesc(String mSportDesc) {
    this.mSportDesc = mSportDesc;
    }

    public String getmLogoFileName() {
    return mLogoFileName;
    }

    public void setmLogoFileName(String mLogoFileName) {
    this.mLogoFileName = mLogoFileName;
    }

    public String getMlogoPath() {
    return mlogoPath;
    }

    public void setMlogoPath(String mlogoPath) {
    this.mlogoPath = mlogoPath;
    }

    public Date getmCreDate() {
    return mCreDate;
    }

    public void setmCreDate(Date mCreDate) {
    this.mCreDate = mCreDate;
    }

    public String getmCreUserSNo() {
    return mCreUserSNo;
    }

    public void setmCreUserSNo(String mCreUserSNo) {
    this.mCreUserSNo = mCreUserSNo;
    }

    public String getmSportCategory() {
    return mSportCategory;
    }

    public void setmSportCategory(String mSportCategory) {
    this.mSportCategory = mSportCategory;
    }
    }

    Wednesday, September 25, 2013 4:00 PM
  • Hey

    I added this statement: Log.i("TAG",exception.getCause().getMessage());

    And I am getting error: 400, table does not exist. This means that there is something wrong with table class. Please guide.

    Wednesday, September 25, 2013 4:17 PM
  • Did you create a table called "ZMOB_SPORT_TYPE_DTLS" in your mobile service? That's the value which you passed to the .getTable method:

        mSportTypeDtls = mClient.getTable("ZMOB_SPORT_TYPE_DTLS", ZMOB_SPORT_TYPE_DTLS.class);


    Carlos Figueira

    Wednesday, September 25, 2013 4:21 PM
  • Just wanted to complete this thread that I figured out my problem long back. The problem was just that I was passing the wrong link for mobile services. I was passing the website url in azure instead of mobile.. 
    • Marked as answer by akshitag Tuesday, November 05, 2013 12:16 AM
    Tuesday, November 05, 2013 12:16 AM