Azure MobileServiceException:{" message":"发生了错误。"}

时间:2016-06-11 17:44:30

标签: java c# android azure

我是azure的新手,所以我创建了一个带有sql数据库(.NET后端)的资源组。另请注意,我使用的是Migrations

BACKEND:

我在后端添加了一个类User

public class User: EntityData
{
    [Required, StringLength(128)]
    public String pseudo { get; set; }
    public String name { get; set; }
    public String familyName { get; set; }
    public String email { get; set; }
    public String hobbies { get; set; }
    public String favoriteTrips { get; set; }
    public String comment { get; set; }
    public String password { get; set; }
    public String img { get; set; }
    public float note { get; set; }
    public int bday { get; set; }
    public List<String> languages { get; set; }
}

我将课程添加到我的上下文中:

public SbSet<User> User { get; set; }

FRONTEND:

这是我的班级User

public class User implements Serializable {
    public String Id;
    public String pseudo, name, familyName, email, hobbies, favoriteTrips, comment;
    public float note;
    public int bday;
    public ArrayList<String> languages;
    public String img;
    public String password;

    // Constructors and Methods
}

以下是我尝试访问数据库的方法:

Runnable r = new Runnable()
{
    @Override
    public void run() {
        try {
            mClient = new MobileServiceClient(SERVER_LINK, this);
            // insert the user
            User user = new User(...)
            User user2 = mClient.getTable(User.class).insert(user).get();
            System.out.println("Inserted user with ID = " + user2.getId());

            // get all users
            List<User> users = mClient.getTable(User.class).execute().get();
            System.out.println("List length : " + users.size());
            for (User u: users)
            {
                System.out.println(u.getId() + ": " + u.getPseudo());
            }
        } catch (Exception e) {
            System.out.println("FAILED AGAIN !!!!!!!!!!!!!!!!!!!!!!!!!!");
            e.printStackTrace();
        }
    }
};

Thread t = new Thread(r);
t.start();

结果:

    06-11 02:24:38.793 13739-13739/t2g.com.travel2gather W/System: ClassLoader referenced unknown path: /data/app/t2g.com.travel2gather-1/lib/x86
    06-11 02:24:39.189 13739-13739/t2g.com.travel2gather W/System: ClassLoader referenced unknown path: /data/app/t2g.com.travel2gather-1/lib/x86
    06-11 02:24:39.393 13739-13745/t2g.com.travel2gather W/art: Suspending all threads took: 48.807ms
    06-11 02:24:40.029 13739-13739/t2g.com.travel2gather W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
    06-11 02:24:40.290 13739-13778/t2g.com.travel2gather D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

    [ 06-11 02:24:40.291 13739:13739 D/         ]
    HostConnection::get() New Host Connection established 0xabfea2e0, tid 13739


    [ 06-11 02:24:40.333 13739:13778 D/         ]
    HostConnection::get() New Host Connection established 0xb40dcf00, tid 13778
    06-11 02:24:40.342 13739-13778/t2g.com.travel2gather I/OpenGLRenderer: Initialized EGL, version 1.4
    06-11 02:24:40.366 13739-13778/t2g.com.travel2gather W/EGL_emulation: eglSurfaceAttrib not implemented
    06-11 02:24:40.366 13739-13778/t2g.com.travel2gather W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb40a0be0, error=EGL_SUCCESS
    06-11 02:24:40.408 13739-13745/t2g.com.travel2gather W/art: Suspending all threads took: 67.225ms
    06-11 02:24:40.431 13739-13768/t2g.com.travel2gather W/art: Verification of void com.squareup.okhttp.internal.http.HttpEngine.sendRequest() took 242.139ms
    06-11 02:24:40.450 13739-13749/t2g.com.travel2gather I/art: Background partial concurrent mark sweep GC freed 8675(1549KB) AllocSpace objects, 2(40KB) LOS objects, 39% free, 2MB/3MB, paused 4.360ms total 160.861ms
    06-11 02:24:41.376 13739-13767/t2g.com.travel2gather I/System.out: FAILED AGAIN !!!!!!!!!!!!!!!!!!!!!!!!!!
    06-11 02:24:41.376 13739-13767/t2g.com.travel2gather W/System.err: java.util.concurrent.ExecutionException: com.microsoft.windowsazure.mobileservices.MobileServiceException: {"message":"An error has occurred."}
    06-11 02:24:41.376 13739-13767/t2g.com.travel2gather W/System.err:     at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:299)
    06-11 02:24:41.376 13739-13767/t2g.com.travel2gather W/System.err:     at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:286)
    06-11 02:24:41.376 13739-13767/t2g.com.travel2gather W/System.err:     at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116)
    06-11 02:24:41.376 13739-13767/t2g.com.travel2gather W/System.err:     at t2g.com.travel2gather.NavDrawer$1.run(NavDrawer.java:95)
    06-11 02:24:41.376 13739-13767/t2g.com.travel2gather W/System.err:     at java.lang.Thread.run(Thread.java:818)
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err: Caused by: com.microsoft.windowsazure.mobileservices.MobileServiceException: {"message":"An error has occurred."}
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err:     at com.microsoft.windowsazure.mobileservices.http.MobileServiceConnection$1.onNext(MobileServiceConnection.java:128)
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err:     at com.microsoft.windowsazure.mobileservices.MobileServiceClient$15.handleRequest(MobileServiceClient.java:1499)
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err:     at com.microsoft.windowsazure.mobileservices.http.MobileServiceConnection.start(MobileServiceConnection.java:113)
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err:     at com.microsoft.windowsazure.mobileservices.http.RequestAsyncTask.doInBackground(RequestAsyncTask.java:78)
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err:     at com.microsoft.windowsazure.mobileservices.http.RequestAsyncTask.doInBackground(RequestAsyncTask.java:35)
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
    06-11 02:24:41.377 13739-13767/t2g.com.travel2gather W/System.err:  ... 1 more
    06-11 02:36:13.521 13739-13745/t2g.com.travel2gather W/art: Suspending all threads took: 8.356ms

我不明白这个错误来自哪里......它发生在第一个.get()insert(user).get()execute().get())上。谢谢你的帮助。

编辑:另请注意,数据库访问可以与示例表TodoItem一起使用,因此看起来错误来自我的班级User

1 个答案:

答案 0 :(得分:0)

根据您的Android代码和不清楚的异常信息,我认为有一些疑点,您可以参考tutorialsample仔细检查。

  1. User类的属性缺少注释声明,例如属性@com.google.gson.annotations.SerializedName("id")的{​​{1}}。
  2. Id类应该是POJO类,不是实现User接口所必需的。
  3. 似乎没有必要创建一个新线程来执行插入&amp;得到操作。我不明白这样做的原因。
  4. 希望它有所帮助。