有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Azure MobileServiceException:{“消息”:“发生错误”。}

我是azure的新手,所以我用sql数据库(.NET后端)创建了一个ressource组。还要注意,我使用的是Migrations

后端:

我在后端添加了一个类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; }

前端:

这是我的课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 安卓.graphics.PorterDuffColorFilter 安卓.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(安卓.graphics.PorterDuffColorFilter, 安卓.content.res.ColorStateList, 安卓.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in 安卓.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 安卓.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())上。谢谢你的帮助

EDIT:还要注意,数据库访问对样本表TodoItem运行良好,因此错误似乎来自我的类User


共 (1) 个答案

  1. # 1 楼答案

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

    1. User类的属性缺少注释声明,例如属性Id@com.google.gson.annotations.SerializedName("id")
    2. User类应该是POJO类,而不是实现Serializable接口所必需的
    3. 似乎没有必要创建一个新线程来执行插入&;动手术。我不明白这样做的原因

    希望有帮助