简体   繁体   中英

Trouble importing class from the appEngine package

This is my first try at server-client interactions for an android app. I wrote this MainActivity.java file for a little app i'm trying to make. I'm trying to implement the Google App Engine Database to store information for markers on a map. I'm basing my addMarkerTask class off of this sample from google.

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.*. 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

By the way, do you have Auto Activation for content assist enabled? Eclipse -> Preferences -> Java -> Editor -> Content Assist

Also check if your class is in your build path. Project -> properties -> Java Build Pathh -> source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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