简体   繁体   English

无法从appEngine套件汇入类别

[英]Trouble importing class from the appEngine package

This is my first try at server-client interactions for an android app. 这是我第一次尝试使用Android应用程序进行服务器-客户端交互。 I wrote this MainActivity.java file for a little app i'm trying to make. 我为我要制作的一个小应用程序编写了这个MainActivity.java文件。 I'm trying to implement the Google App Engine Database to store information for markers on a map. 我正在尝试实现Google App Engine数据库以在地图上存储标记的信息。 I'm basing my addMarkerTask class off of this sample from google. 我基于Google的此示例建立了我的addMarkerTask类。

https://github.com/GoogleCloudPlatform/solutions-mobile-shopping-assistant-backend-java/blob/master/MobileAssistant-Tutorial/Phase1_Snippets/MainActivity.01.java https://github.com/GoogleCloudPlatform/solutions-mobile-shopping-assistant-backend-java/blob/master/MobileAssistant-Tutorial/Phase1_Snippets/MainActivity.01.java

and here is my class 这是我的课

package com.example.rpialmanac;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.json.jackson2.JacksonFactory;


import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

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

    GoogleMap mMap;
    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    final LatLng FIELD = new LatLng(42.730357, -73.679951);
    Marker field = mMap.addMarker(new MarkerOptions().position(FIELD));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
   * AsyncTask for adding a new marker to the database  */
private class addMarkerTask extends AsyncTask<Void, Void, Void> {
    /**
     * Calls appropriate CloudEndpoint to add a new marker to the database.
     *
     * @param params the place where the user is adding a marker
     */
    @Override
    protected Void doInBackground(Void... params) {
      addMarker newMarker = new addMarker();

      // Set the ID of the store where the user is. 
      // This would be replaced by the actual ID in the final version of the code. 
      newMarker.setMarkerName("86 field");
      newMarker.setMarkerType("recreation")
      newMarker.setMarkerLat(42.730357);
      newMarker.setMarkerLong(-73.679951);

      addMarkerEndpoint.Builder builder = new addMarkerEndpoint.Builder(
          AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
          null);

      builder = CloudEndpointUtils.updateBuilder(builder);

      Checkinendpoint endpoint = builder.build();


      try {
        endpoint.insertCheckIn(checkin).execute();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return null;

}
}

} }

However, eclipse is unable to resolve the object addMarker which I know is because I haven't imported the class from my addMarker.java file which is located in my rpiAlmanac-AppEngine package, but eclipse does not recognize the class when I start typing com.example.rpiAlmanac.*. 但是,eclipse无法解析我知道的对象addMarker,因为我还没有从rpiAlmanac-AppEngine包中的addMarker.java文件导入该类,但是当我开始输入com时,eclipse无法识别该类。 .example.rpiAlmanac。*。 Does anyone know if it's possible to import a class from another package? 有谁知道是否可以从另一个包中导入一个类? If there is another way to go about doing this, I would be happy to hear any help. 如果还有其他方法可以解决,我将很高兴听到任何帮助。

Simply add it to your import statements. 只需将其添加到您的导入语句中即可。

import com.example.rpiAlmanac.addMarker;

Note that by convention, you should make a classname start with an uppercase letter. 请注意,按照惯例,您应该使类名以大写字母开头。 ie Addmarker 即Addmarker

By the way, do you have Auto Activation for content assist enabled? 顺便说一句,您是否启用了内容激活自动激活功能? Eclipse -> Preferences -> Java -> Editor -> Content Assist Eclipse->首选项-> Java->编辑器-> Content Assist

Also check if your class is in your build path. 还要检查您的课程是否在构建路径中。 Project -> properties -> Java Build Pathh -> source 项目->属性-> Java构建路径->源

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

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