繁体   English   中英

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

[英]Azure MobileServiceException: {“message”:“An error has occurred.”}

我是azure的新手,所以我创建了一个带有sql数据库( .NET后端)的资源组。 另请注意,我正在使用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 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

根据您的android代码和不清楚的异常信息,我认为有一些可疑点,您可以参考教程示例进行仔细检查。

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

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM