android – GoogleJsonResponseException:404 Not Found使用谷歌应用程序端点引擎后端

前端之家收集整理的这篇文章主要介绍了android – GoogleJsonResponseException:404 Not Found使用谷歌应用程序端点引擎后端前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我按照下面的教程.

https://developers.google.com/eclipse/docs/running_and_debugging_2_0

它基本上为我现有的应用程序添加了GAE后端.然后,我尝试下面的示例,在本地开发服务器上运行它,然后我得到下面发生的异常

Note result = endpoint.insertNote(note).execute();

叫做.

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found

我的代码如下.

package com.cloudnotes;

import java.io.IOException;
import java.util.Date;

import android.os.AsyncTask;
import android.content.Context;
import com.cloudnotes.noteendpoint.Noteendpoint;
import com.cloudnotes.noteendpoint.model.Note;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.json.jackson.JacksonFactory;


import android.os.Bundle;
import android.app.Activity;

import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

      new EndpointsTask().execute(getApplicationContext());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main,menu);
        return true;
    }

    public class EndpointsTask extends AsyncTask<Context,Integer,Long> {
        protected Long doInBackground(Context... contexts) {

          Noteendpoint.Builder endpointBuilder = new Noteendpoint.Builder(
              AndroidHttp.newCompatibleTransport(),new JacksonFactory(),new HttpRequestInitializer() {
              public void initialize(HttpRequest httpRequest) { }
              });
      Noteendpoint endpoint = CloudEndpointUtils.updateBuilder(
      endpointBuilder).build();
      try {
          Note note = new Note().setDescription("Note Description");
          String noteID = new Date().toString();
          note.setId(noteID);

          note.setEmailAddress("E-Mail Address");      
          Note result = endpoint.insertNote(note).execute();
      } catch (IOException e) {
        e.printStackTrace();
      }
          return (long) 0;
        }
    }
}

解决方法

导致此问题的另一个可能原因是未在appengine-web.xml中设置正确的applicationId:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>APPLICATION_ID_HERE</application>

</appengine-web-app>
原文链接:https://www.f2er.com/android/313817.html

猜你在找的Android相关文章