Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在Android Studio中与Android应用程序通信Google数据存储_Java_Android_Google App Engine_Google Cloud Datastore - Fatal编程技术网

Java 无法在Android Studio中与Android应用程序通信Google数据存储

Java 无法在Android Studio中与Android应用程序通信Google数据存储,java,android,google-app-engine,google-cloud-datastore,Java,Android,Google App Engine,Google Cloud Datastore,我正在尝试创建一个android应用程序,它与Google应用程序引擎交互,以加载和保存Google数据存储中的实体。我想我有一个正确的配置,但我不知道我是否可以上传我的应用程序来测试它,它只是永远挂起,然后给我这个错误: SEVERE: Endpoints configuration not updated. The app returned an error when the Google Cloud Endpoints server attempted to communicate wi

我正在尝试创建一个android应用程序,它与Google应用程序引擎交互,以加载和保存Google数据存储中的实体。我想我有一个正确的配置,但我不知道我是否可以上传我的应用程序来测试它,它只是永远挂起,然后给我这个错误:

SEVERE: Endpoints configuration not updated.  The app returned an error when the Google Cloud Endpoints server attempted to communicate with it.
但是,如果我更改了版本号,即使在收到此消息后,新版本也会在线显示在我的控制台中。我已经阅读了谷歌在数据存储上的所有文档,无法找出问题所在。我已经有这个问题一个月了,还没有找到解决办法。我在某处读到,如果应用程序包含错误,它将不会被上传,因此我将包括我的所有代码。我也不知道我在做什么,甚至不知道我是否在正确的轨道上,为什么这不起作用,所以如果你注意到任何愚蠢的事情,你应该告诉我。提前谢谢你,如果你能帮我解决这个问题,你将是我的英雄和上帝

这是我的终点:

package com.polo.backend.endpoints;

/**
* Created by sagesmith on 4/16/16.
*
* Is used to interact with the server
*/

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.api.server.spi.response.ConflictException;
import com.google.api.server.spi.response.NotFoundException;

import com.googlecode.objectify.Ref; 

import com.polo.backend.services.ObjcfyService;
import com.polo.backend.entities.Event;
import com.polo.backend.entities.User;

import java.util.List;

import javax.inject.Named;

 /**
  *
  */
  @Api(
    name = "userEndpoint",
    version = "v1",
    namespace = @ApiNamespace(
            ownerDomain = "backend.polo.com",
            ownerName = "backend.polo.com",
            packagePath = ""
    )
)
public class UserEndpoint {
    /**
     * Registers the two entities used in this class
     */
     public UserEndpoint(){
        ObjcfyService.register(User.class);
        ObjcfyService.register(Event.class);
     }

     @ApiMethod(name = "insertUser")
     /**
      * Inserts a new {@code User} into the data store
      */
     public void insertUser(User user) throws ConflictException, NotFoundException{
         if(getUser(user.getUsername()) != null){
             throw new ConflictException("Object already exists");
         }
     }

     /**
      *
      * @param user
      * @throws NotFoundException
      */
      @ApiMethod(name = "updateUser")
      public void updateUser(User user) throws NotFoundException{
          if(getUser(user.getUsername()) != null) {
              ObjcfyService.objectify().save().entity(user).now();
          }
      }

      /**
       *
       * @param username
       * @throws NotFoundException
       */
       @ApiMethod(name = "removeUser")
       public void removeUser(@Named("username") String username) throws NotFoundException{
           User record = getUser(username);
           if(record != null){
               ObjcfyService.objectify().delete().entity(record).now();
           }

       }

       /**
        *
        * @param username
        * @return
        * @throws NotFoundException
        */
        @ApiMethod(name = "getUser")
        public User getUser(@Named("username") String username) throws NotFoundException{
            User user = ObjcfyService.objectify().load().type(User.class).id(username).now();
            if(user != null) {
                List<Ref<User>> friendRefs = user.getFriendRefs();
                List<Ref<Event>> repeatingEventRefs = user.getRepeatingEventRefs();
                List<Ref<Event>> nonRepeatingEventRefs = user.getNonRepeatingEventRefs();

                for (Ref<User> friendRef : friendRefs) {
                    user.addFriend(friendRef.get());
                }

                for (Ref<Event> repeatingEventRef : repeatingEventRefs) {
                    user.addRepeatingEvent(repeatingEventRef.get());
                }

                for (Ref<Event> nonRepeatingEventRef : nonRepeatingEventRefs) {
                    user.addNonRepeatingEvent(nonRepeatingEventRef.get());
                }
            } else{
                throw new NotFoundException("User not found");
        }

        return user;
    }
}
以及我的目标服务:

package com.polo.backend.services;

/**
 * Created by sagesmith on 4/16/16.
 */
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.ObjectifyService;

public class ObjcfyService {
    public static void register(Class<?> eClass){
        ObjectifyService.register(eClass);
    }

    public static Objectify objectify(){
        return ObjectifyService.ofy();
    }

    public static ObjectifyFactory objectifyFactory(){
        return ObjectifyService.factory();
    }
}
package com.polo.backend.services;
/**
*由sagesmith于2016年4月16日创建。
*/
导入com.googlecode.objectify.objectify;
导入com.googlecode.objectify.objectify工厂;
导入com.googlecode.objectify.ObjectifyService;
公共类对象服务{
公共静态无效寄存器(eClass类){
ObjectifyService.register(电子课堂);
}
公共静态Objectify Objectify(){
返回ObjectifyService.ofy();
}
公共静态ObjectifyFactory ObjectifyFactory(){
return ObjectifyService.factory();
}
}
这是我的appengine-web.xml,我用我的appid替换了appid,原因很明显:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>my_id</application>
    <version>1</version>
    <threadsafe>true</threadsafe>

    <system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>

我的身份证
1.
真的

这是我的web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
    <servlet>
        <servlet-name>SystemServiceServlet</servlet-name>
        <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
        <init-param>
            <param-name>services</param-name>
            <param-value>com.polo.backend.endpoints.UserEndpoint</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>SystemServiceServlet</servlet-name>
        <url-pattern>/_ah/spi/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

SystemServiceServlet
com.google.api.server.spi.SystemServiceServlet
服务
com.polo.backend.endpoints.UserEndpoint
SystemServiceServlet
/_ah/spi/*
index.html

最后,这里是我用来与Android应用程序中的数据存储进行通信的异步任务,我再次用我的应用程序ID替换了我的应用程序ID:

package com.polo.client;

import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.extensions.android.json.AndroidJsonFactory;

import com.polo.StaticAssets;
import com.polo.activity.Home;
import com.polo.backend.userEndpoint.UserEndpoint;
import com.polo.backend.userEndpoint.model.User;

import java.io.IOException;
/**
 * Created by sagesmith on 4/17/16.
 */
public class UserAsyncTask extends AsyncTask<Void, Void, User>{
    private static UserEndpoint userApiService = null;
    private Home context;
    private String username;

    /**
     *
     * @param context
     */
    public UserAsyncTask(Home context){
        this.context = context;
        username = StaticAssets.getUserName(context);
    }

    /**
     *
     * @param params
     * @return
     */
    @Override
    protected User doInBackground(Void... params){
        if(userApiService == null){
            UserEndpoint.Builder builder = new UserEndpoint.Builder(
                AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(),
                null
            )
            .setRootUrl("https://my_id.appspot.com/_ah/api/");

            userApiService = builder.build();
        }

        User user = null;

        try{
            user = userApiService.getUser(username).execute();
        } catch (IOException e){
            Log.e("User not found", e.getMessage());
        }

        return user;
    }

    /**
     *
     * @param result
     */
    @Override
    protected void onPostExecute(User result) {
        if(result!=null)
            Toast.makeText(context, result.getFirstName(), Toast.LENGTH_LONG).show();
    }
}
package com.polo.client;
导入android.os.AsyncTask;
导入android.util.Log;
导入android.widget.Toast;
导入com.google.api.client.extensions.android.http.AndroidHttp;
导入com.google.api.client.extensions.android.json.AndroidJsonFactory;
导入com.polo.StaticAssets;
导入com.polo.activity.Home;
导入com.polo.backend.userEndpoint.userEndpoint;
导入com.polo.backend.userEndpoint.model.User;
导入java.io.IOException;
/**
*由sagesmith于2016年4月17日创建。
*/
公共类UserAsyncTask扩展了AsyncTask{
私有静态UserEndpoint userApiService=null;
私人住宅环境;
私有字符串用户名;
/**
*
*@param上下文
*/
公共用户异步任务(主上下文){
this.context=上下文;
username=StaticAssets.getUserName(上下文);
}
/**
*
*@param params
*@返回
*/
@凌驾
受保护的用户doInBackground(无效…参数){
if(userApiService==null){
UserEndpoint.Builder=新建UserEndpoint.Builder(
AndroidHttp.newCompatibleTransport(),
新的AndroidJsonFactory(),
无效的
)
.setRootUrl(“https://my_id.appspot.com/_ah/api/");
userApiService=builder.build();
}
User=null;
试一试{
user=userApiService.getUser(username.execute();
}捕获(IOE异常){
Log.e(“未找到用户”,e.getMessage());
}
返回用户;
}
/**
*
*@param结果
*/
@凌驾
受保护的void onPostExecute(用户结果){
如果(结果!=null)
Toast.makeText(上下文,result.getFirstName(),Toast.LENGTH_LONG.show();
}
}

查看完整的错误消息会有所帮助,该消息建议:

有关详细信息,请参阅部署疑难解答文档:

文档建议首先检查日志中的“/”ah/spi/BackendService.getApiConfigs”。如果我尝试根据示例部署端点后端,我会在日志中看到以下内容:

javax.servlet.ServletContext log: unavailable
java.lang.reflect.InvocationTargetException
    at com.google.appengine.runtime.Request.process-b693af604777a85a(Request.java)
    ...
Caused by: java.lang.StackOverflowError
    ...
    com.googlecode.objectify.impl.translate.ClassTranslatorFactory.create(ClassTranslatorFactory.java:49)
    ...
此错误仅在调用
ObjectifyService.register(class)
时发生,嗯

当Objectify尝试注册类并导致StackOverflower错误时,您的
User
类中有一些内容会导致无限递归:

@Nullable public List<User> friends = new ArrayList<>();

做出这些更改后,我可以部署Endpoints应用程序而不会出现任何错误。

我问了一位同事,他认为这与app.yamlYup的Java等价物有关。这就是我的问题\@Entity public class Person{@Id Long Id;Ref referedby;//was just Person referedby;}谢谢你的帖子
javax.servlet.ServletContext log: unavailable
java.lang.reflect.InvocationTargetException
    at com.google.appengine.runtime.Request.process-b693af604777a85a(Request.java)
    ...
Caused by: java.lang.StackOverflowError
    ...
    com.googlecode.objectify.impl.translate.ClassTranslatorFactory.create(ClassTranslatorFactory.java:49)
    ...
@Nullable public List<User> friends = new ArrayList<>();
@Nullable public List<Ref<User>> friends = new ArrayList<>();
@Entity
public class Event {
  @Id private Long id;
  ...