Reputation: 167
I am trying to send some data to Azure from my Android app. I am using the example provided by Azure when setting up a Mobile Service. I have no errors in the code but when I try and load an activity on a button click the app crashes. The activity I am trying to load has the Azure interaction code on the onCreate method.
UPDATE
This works on other android devices but when I try and run it on a Samsung Galaxy S3 Mini runnning Android version 4.1.2 it crashes.
Register.java
package com.example.martin.ivebeenthere;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;
import com.microsoft.windowsazure.mobileservices.MobileServiceClient;
import com.microsoft.windowsazure.mobileservices.http.ServiceFilterResponse;
import com.microsoft.windowsazure.mobileservices.table.TableOperationCallback;
import java.net.MalformedURLException;
public class Register extends AppCompatActivity {
private MobileServiceClient mClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
try {
mClient = new MobileServiceClient(
"AZURE ACCOUNT",
"AZURE KEY",
this
);
} catch (MalformedURLException e) {
e.printStackTrace();
}
Item item = new Item();
item.Text = "Awesome item";
mClient.getTable(Item.class).insert(item, new TableOperationCallback<Item>() {
public void onCompleted(Item entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
// Insert succeeded
} else {
// Insert failed
}
}
});
}
public void onClickbtnRegister(View view)
{
startActivity(new Intent(Register.this, Login.class));
Toast.makeText(getApplicationContext(), "Successfully Registered",
Toast.LENGTH_LONG).show();
}
}
Item.java
package com.example.martin.ivebeenthere;
/**
* Created by Martin on 31/03/2016.
*/
public class Item {
public String Id;
public String Text;
}
Logcat
04-06 10:28:31.570 15331-15331/com.example.martin.ivebeenthere E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.google.gson.GsonBuilder
at com.microsoft.windowsazure.mobileservices.MobileServiceClient.createMobileServiceGsonBuilder(MobileServiceClient.java:192)
at com.microsoft.windowsazure.mobileservices.MobileServiceClient.<init>(MobileServiceClient.java:179)
at com.microsoft.windowsazure.mobileservices.MobileServiceClient.<init>(MobileServiceClient.java:158)
at com.example.martin.ivebeenthere.Register.onCreate(Register.java:30)
at android.app.Activity.performCreate(Activity.java:5047)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
at android.app.ActivityThread.access$700(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
Upvotes: 1
Views: 136
Reputation: 8035
Do you have com.google.code.gson in your dependencies?
Look in dependencies list in build.gradle and ensure you have the following:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.3'
compile 'com.google.guava:guava:18.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.microsoft.azure:azure-mobile-android:3.1.0'
compile (group: 'com.microsoft.azure', name: 'azure-notifications-handler', version: '1.0.1', ext: 'jar')
}
Upvotes: 1