我正在使用Hamweather Aeris Andorid SDK,我正在尝试实现地图视图组件。当我按照他们的在线教程,我无法渲染AerisMapView,我得到错误:
java.lang.ClassNotFoundException: com.hamweather.aeris.maps.R$layout.
有谁知道这是来自哪里/如何解决?
我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.hamweather.aeris.maps.AerisMapView
android:id="@+id/aerisfragment_map"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</com.hamweather.aeris.maps.AerisMapView>
</LinearLayout>
我的活动:
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
public class MapViewActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview_activity);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
MapFragment fragment = new MapFragment();
fragmentTransaction.add(R.id.frame_container, fragment);
fragmentTransaction.commit();
}
}
最后,片段:
import android.location.*;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.model.LatLng;
import com.hamweather.aeris.communication.AerisCallback;
import com.hamweather.aeris.communication.EndpointType;
import com.hamweather.aeris.location.LocationHelper;
import com.hamweather.aeris.maps.AerisMapView;
import com.hamweather.aeris.maps.AerisMapView.AerisMapType;
import com.hamweather.aeris.maps.MapViewFragment;
import com.hamweather.aeris.maps.interfaces.OnAerisMapLongClickListener;
import com.hamweather.aeris.maps.interfaces.OnAerisMarkerInfoWindowClickListener;
import com.hamweather.aeris.maps.markers.AerisMarker;
import com.hamweather.aeris.model.AerisResponse;
import com.hamweather.aeris.response.EarthquakesResponse;
import com.hamweather.aeris.response.FiresResponse;
import com.hamweather.aeris.response.StormCellResponse;
import com.hamweather.aeris.response.StormReportsResponse;
public class MapFragment extends MapViewFragment implements OnAerisMapLongClickListener, AerisCallback,
OnAerisMarkerInfoWindowClickListener{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.single_tab_site_weather2,
container, false);
mapView = (AerisMapView) view.findViewById(R.id.aerisfragment_map);
mapView.init(savedInstanceState, AerisMapType.GOOGLE);
initMap();
setHasOptionsMenu(true);
return view;
}
/**
* Inits the map with specific setting
*/
private void initMap() {
mapView.moveToLocation(new LatLng(34.7, -86.7), 9);
mapView.setOnAerisMapLongClickListener(this);
mapView.setOnAerisWindowClickListener(this);
}
@Override
public void onResult(EndpointType endpointType, AerisResponse aerisResponse) {
}
@Override
public void onMapLongClick(double v, double v1) {
}
@Override
public void wildfireWindowPressed(FiresResponse firesResponse, AerisMarker aerisMarker) {
}
@Override
public void stormCellsWindowPressed(StormCellResponse stormCellResponse, AerisMarker aerisMarker) {
}
@Override
public void stormReportsWindowPressed(StormReportsResponse stormReportsResponse, AerisMarker aerisMarker) {
}
@Override
public void earthquakeWindowPressed(EarthquakesResponse earthquakesResponse, AerisMarker aerisMarker) {
}
}
此外,这是我在堆栈交换上的第一个Q,所以如果我没有遵守某个约定或礼节,请告诉我,我会尝试解决它。感谢。
答案 0 :(得分:0)
I Managed to get it working. For anyone who has this issue, here were my steps:
I first switched from using the jars to using the gradle dependency. Per their website, add the following to your build.gradle(the module one)
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.android.gms:play-services:4.4.52'
compile 'com.hamweather:aeris-maps-library:1.0.0@aar'
}
Also be sure to add the following, in the andorid tag, which probably already exists in the file:
android {
...some other stuff...
dexOptions{
preDexLibraries = false
}
}
Double check that you have the proper API key permissions for google maps. Then it works. As far as I can tell, it had something to do with using the compiled jar, not the repo version.