2014-10-05 43 views
0

这是我第一次尝试在android应用的服务器 - 客户端交互中使用。我为我想要制作的一个小应用程序编写了这个MainActivity.java文件。我正在尝试实施Google App Engine数据库,以在地图上存储标记的信息。我将我的addMarkerTask类从Google的这个示例中提取出来。从appEngine包导入课程时遇到问题

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

,这里是我的课

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; 

} 
} 

}

但是,日食是无法解决的对象addMarker我知道是因为我还没有从导入的类我addMarker.java文件位于我的rpiAlmanac-AppEngine包中,但是当我开始输入com.example.rpiAlmanac。*时,eclipse无法识别该类。有谁知道是否可以从另一个软件包中导入一个类?如果还有其他方法可以做到这一点,我会很乐意听到任何帮助。

回答

0

只需将其添加到您的进口报表。

import com.example.rpiAlmanac.addMarker; 

请注意,按照惯例,您应该使一个类名以大写字母开头。即Addmarker

顺便说一下,你有自动激活内容帮助启用? Eclipse - > Preferences - > Java - > Editor - > Content Assist

还要检查你的类是否在你的构建路径中。项目 - >属性 - > Java Build Pathh - >源代码

+0

谢谢!我知道它承认另一个包。唯一的错误,我仍然有eclipse无法解决Addmarkerendpoint.Builder(我改变了命名约定)谷歌示例使用相同的行他们的Checkin类,所以我不知道我从哪里得到错误从 – Alex 2014-10-05 19:51:10

+0

@ Alex仔细检查样本中的包和类名。例如,MainActivity具有“import com.google.samplesolutions.mobileassistant.checkinendpoint.Checkinendpoint;”但在实际的src中只能看到com.google.samplesolutions.mobileassistant.CheckInEndpoint。也许他们的样品已经过时了。 – user1258245 2014-10-07 09:37:25

+0

我也注意到了。我不确定我是否错过了某些东西,或者谷歌是否真的错过了版本库中的一个类。我会继续研究它。 – Alex 2014-10-08 20:19:38