- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Android 新手,正在开发一个包含 GoogleMap V2 和标记的项目。它显示了谷歌地图上的一些位置及其详细信息。如果用户点击 map 上的任何标记,它会像往常一样显示带有点击标记详细信息的 MarkerInfoWindow。
当我第一次运行该项目时,一切都很好并且工作正常。当我按下应用程序中的菜单按钮(设备菜单按钮)时,Android 会像往常一样退出我的应用程序并返回主屏幕。
但是,当我恢复我的应用程序(从菜单屏幕上点击应用程序图标)并点击 map 上的任何标记时,我的应用程序崩溃了。并给我一个错误。
如果我按下后退按钮(设备后退按钮)直到返回主屏幕退出应用程序,并且当我像往常一样使用图标恢复应用程序时,一切正常,不会崩溃或出现任何错误。
我的应用程序有什么问题?为什么当用户使用菜单按钮退出我的应用程序时我的应用程序崩溃,而当用户使用后退按钮退出时为什么不崩溃?
我知道我的英语很糟糕。但是,我尽力了。感谢您的理解。
我的错误;
01-15 13:18:05.678 3090-3090/com.xxx.xxxapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa62e3288)
01-15 13:18:05.678 3090-3090/com.xxx.xxxapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.xxx.xxxapp.MarkerInfoWindowAdapter.getInfoContents(MarkerInfoWindowAdapter.java:25)
at com.google.android.gms.maps.GoogleMap$13.g(Unknown Source)
at com.google.android.gms.maps.internal.d$a.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.maps.internal.p.b(SourceFile:112)
at com.google.maps.api.android.lib6.c.h.a(Unknown Source)
at com.google.maps.api.android.lib6.c.h.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.h.b(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.j.c(Unknown Source)
at com.google.maps.api.android.lib6.c.al.c(Unknown Source)
at com.google.maps.api.android.lib6.c.aj.g(Unknown Source)
at com.google.maps.api.android.lib6.c.al.h(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.h.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.o.aw.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.o.bf.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.o.be.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.o.bu.d(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.o.ak.onSingleTapConfirmed(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.i.g.onSingleTapConfirmed(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.i.i.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
这是我的 MainActivity 类;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
FragmentManager manager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
manager = getSupportFragmentManager();
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
// For each of the sections in the app, add a tab to the action bar.
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(
actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
// When the given tab is selected, switch to the corresponding page in
// the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
}
这是我的自定义标记信息类;
package com.xxx.xxxapp;
public class Markers {
public String mAdi;
public String mAdres;
public String mTelefon;
public String mFace;
public String mWeb;
public boolean mGeceAcik;
public boolean mMember;
public boolean mBarinak;
public Double mLatitude;
public Double mLongtitude;
public Markers(String mAdi, String mAdres, String mTelefon, String mFace, String mWeb, boolean mBarinak, boolean mGeceAcik, boolean mMember, Double mLatitude, Double mLongtitude) {
this.mAdi = mAdi;
this.mAdres = mAdres;
this.mTelefon = mTelefon;
this.mFace = mFace;
this.mWeb = mWeb;
this.mGeceAcik = mGeceAcik;
this.mMember = mMember;
this.mLatitude = mLatitude;
this.mLongtitude = mLongtitude;
this.mBarinak = mBarinak;
}
public boolean ismBarinak() {
return mBarinak;
}
public void setmBarinak(boolean mBarinak) {
this.mBarinak = mBarinak;
}
public String getmAdi() {
return mAdi;
}
public void setmAdi(String mAdi) {
this.mAdi = mAdi;
}
public String getmAdres() {
return mAdres;
}
public void setmAdres(String mAdres) {
this.mAdres = mAdres;
}
public String getmTelefon() {
return mTelefon;
}
public void setmTelefon(String mTelefon) {
this.mTelefon = mTelefon;
}
public String getmFace() {
return mFace;
}
public void setmFace(String mFace) {
this.mFace = mFace;
}
public String getmWeb() {
return mWeb;
}
public void setmWeb(String mWeb) {
this.mWeb = mWeb;
}
public boolean ismGeceAcik() {
return mGeceAcik;
}
public void setmGeceAcik(boolean mGeceAcik) {
this.mGeceAcik = mGeceAcik;
}
public boolean ismMember() {
return mMember;
}
public void setmMember(boolean mMember) {
this.mMember = mMember;
}
public Double getmLatitude() {
return mLatitude;
}
public void setmLatitude(Double mLatitude) {
this.mLatitude = mLatitude;
}
public Double getmLongtitude() {
return mLongtitude;
}
public void setmLongtitude(Double mLongtitude) {
this.mLongtitude = mLongtitude;
}
}
这是我的 MapFragment 类;
package com.xxx.xxxapp;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class HaritaFragment extends Fragment implements LocationListener {
private static GoogleMap mGoogleMap;
public static HashMap<Marker, Markers> mMarkersHashMap;
private ArrayList<Markers> mMyMarkersArray = new ArrayList<Markers>();
private Map<Marker, Markers> allMarkersMap = new HashMap<Marker, Markers>();
private LatLng latLng;
private Double lat;
private Double lng;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_harita, container, false);
}
@Override
public void onResume() {
super.onResume();
// Getting Google Play availability status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity().getBaseContext());
if (status != ConnectionResult.SUCCESS) { // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, getActivity(), requestCode);
dialog.show();
} else { // Google Play Services are available
setsVetMarkers();
setUpMap();
plotMarkers(mMyMarkersArray);
}
}
private void setsVetMarkers(){
// Initialize the HashMap for Markers and MyMarker object
mMarkersHashMap = new HashMap<Marker, Markers>();
//public Markers(String mAdi, String mAdres, String mTelefon, String mFace, String mWeb, boolean mBarinak, boolean mGeceAcik, boolean mMember, Double mLatitude, Double mLongtitude)
mMyMarkersArray.add(new Markers(
"PetVetam",
"Emirhan cad.",
"0532-555-5555",
"https://www.facebook.com",
"http://www.xxxx.com",
false,
true,
true,
Double.parseDouble("41.05484176"),
Double.parseDouble("29.00497913")));
mMyMarkersArray.add(new Markers("marina", "Muallim Naci Cad. N:49 D:3 Ortaköy Mah.", "0212-265-0000","YOK" ,
"YOK", true, false, true, Double.parseDouble("41.048846"), Double.parseDouble("29.027924")));
mMyMarkersArray.add(new Markers("Animate Vetamats", "Duygu Sk No:2 Levent", "0212-000000","https://www.facebook.com/pages/Animate-Veteriner/562263330470083" ,
"http://www.animate.com.tr", false, false, false, Double.parseDouble("41.094460"), Double.parseDouble("28.998754")));
}
private void plotMarkers(ArrayList<Markers> markers)
{
if(markers.size() > 0)
{
for (Markers myMarker : markers)
{
// Create user marker with custom icon and other options
MarkerOptions markerOption = new MarkerOptions().position(new LatLng(myMarker.getmLatitude(), myMarker.getmLongtitude()));
if (myMarker.ismGeceAcik()){
markerOption.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
}
else if (myMarker.ismBarinak()){
markerOption.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET));
}
Marker currentMarker = mGoogleMap.addMarker(markerOption);
mMarkersHashMap.put(currentMarker, myMarker);
allMarkersMap.put(currentMarker, myMarker);
mGoogleMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
}
}
}
private void setUpMap(){
mGoogleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();
mGoogleMap.setMyLocationEnabled(true);
// Get the location manager
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the location provider -> use
// default
//Criteria criteria = new Criteria();
//String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
// Initialize the location fields
//Location eğer varsa mapi usercurrent location ile yaratıyor.
if (location != null) {
onLocationChanged(location);
latLng = new LatLng(lat, lng);
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
//Location yoksa default value ve zoom value ile yaratıyor.
}else{
latLng = new LatLng(41.048846, 29.027924);
Toast.makeText(getActivity(),getActivity().getString(R.string.location_error_message),Toast.LENGTH_LONG).show();
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));
}
//OnClick Info Window Listener...
mGoogleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
//Set your InfoWindow Click Events...
Markers selectedMarkerInfo = allMarkersMap.get(marker);
Intent intent = new Intent(getActivity(),DetailActivity.class);
intent.putExtra("adi",selectedMarkerInfo.getmAdi());
intent.putExtra("adres",selectedMarkerInfo.getmAdres());
intent.putExtra("web",selectedMarkerInfo.getmWeb());
intent.putExtra("face",selectedMarkerInfo.getmFace());
intent.putExtra("tel",selectedMarkerInfo.getmTelefon());
intent.putExtra("lat",selectedMarkerInfo.getmLatitude().toString());
intent.putExtra("lng",selectedMarkerInfo.getmLongtitude().toString());
intent.putExtra("gece",selectedMarkerInfo.ismGeceAcik());
intent.putExtra("member",selectedMarkerInfo.ismMember());
intent.putExtra("barinak",selectedMarkerInfo.ismBarinak());
startActivity(intent);
}
});
}
@Override
public void onLocationChanged(Location location) {
lat = (Double) (location.getLatitude());
lng = (Double) (location.getLongitude());
}
}
还有 MarkerInfoWindowAdapter 类;
package com.xxx.xxxapp;
import android.view.View;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.Marker;
public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter
{
public MarkerInfoWindowAdapter()
{
}
@Override
public View getInfoWindow(Marker marker)
{
return null;
}
@Override
public View getInfoContents(Marker marker)
{
Markers myMarker = HaritaFragment.mMarkersHashMap.get(marker);
marker.setTitle(myMarker.getmAdi());
marker.setSnippet(myMarker.getmAdres());
return null;
}
}
有AndroidManifest.xml;
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.xxxapp" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/API_KEY" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DetailActivity"
android:label="@string/title_activity_detail"
android:screenOrientation="portrait" >
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xxx.xxxapp.MainActivity" />
</activity>
<activity
android:name=".ListVets"
android:label="@string/title_activity_list_vets"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xxx.xxxapp.MainActivity" />
</activity>
</application>
</manifest>
最佳答案
好的。我解决了这个问题。
我试图在setsVetMarkers()方法中初始化Markers和MyMarker对象的HashMap,当我初始化HashMap时,上面的问题就解决了。
就像setsVetMarkers方法中的那样;
// Initialize the HashMap for Markers and MyMarker object
mMarkersHashMap = new HashMap<Marker, Markers>();
我在顶部重新创建并初始化;
public static HashMap<Marker, Markers> mMarkersHashMap = new HashMap<Marker, Markers>();
问题已解决。我不想删除这个问题,也许它对某人有帮助。但这确实是一个具体的问题。如果某个管理员想要删除这个问题,对我来说没问题。
关于java - 当用户从菜单屏幕返回应用程序时,Marker InfoWindowAdapter 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27964720/
我正在尝试在我的 map View 中为特定标记使用“setInfoWindowAdapter”属性,但是对于“标记 2”,由于某种原因(标记 2),标题下方似乎出现了一些不需要的空间(见附件截图)。
我有一个奇怪的问题我设计了一个应用程序,用户可以在 Google map 版本 2 上看到某个点 我像这样使用 InfoWindowAdapter : public class PopupAdapte
所以,我已经为我的 Google map 设置了 infowindowadapter,但问题是,当我点击第一个标记时,它会正确显示信息,但是当我点击第二个标记时,它会显示信息从第一个开始,所以 inf
我在尝试将 Volley 的 NetworkImageView 与 Google Maps API v2 的 InfoWindow 结合使用时遇到问题。 我的标记显示了一个信息窗口,其中包含从互联网上
我正在向基于 Android Google Maps API v2 的 map fragment 添加具有自定义布局的 InfoWindowAdapter。我在从 getInfoWindow() 返回
我是 Android 新手,正在开发一个包含 GoogleMap V2 和标记的项目。它显示了谷歌地图上的一些位置及其详细信息。如果用户点击 map 上的任何标记,它会像往常一样显示带有点击标记详细信
大家好,我是 Android 的初学者,但我想做的是在我按下 map 中的 infoWindowAdapter 时开始一项新 Activity 。代码看起来很简单,但它不起作用,我不知道为什么。你能帮
我正在尝试在 google maps android 中使用自定义 InfoWindow 显示几个点(兴趣点)。我的问题是我不能在不同的点上放置不同的信息。我在更新弹出布局的 TextView 内容时
我正在尝试在“InfoWindowAdapter”中显示来自 url 的图像 ,我有以下代码,但没有显示图像 .... mMap = getMap(); mMap.setInfoWindowAdapt
我正在尝试利用 InfoWindowAdapter 为 InfoView 提供自定义内容。我正在从我的 Web 服务中拉下 JSONArray 并添加标记,但我没有看到如何通过标记将详细信息传递给回调
我正在使用 Google Maps Api,并希望在单击标记时在 InfoWindow 中显示图像。我实现了它,但是 Picasso 有一个问题。当我单击标记时,会显示 infoWindow 并且 i
我正在尝试在我的标记信息中添加一些图像按钮。尽管按钮已添加到 View 中,但我无法点击它们。当我尝试单击它时,它会单击整个 View 。我的代码我们在下面给出。 主 Activity .java p
我有一个 Google Maps V2,在我的 setUpMap() 方法中,我将 GoogleMap 附加到一个 infoWindowAdapter,如下所示: ClusterManager ren
我有一个在 map 上显示带有标记的地点的应用程序,我自定义了信息窗口以显示创建的地点的内容、标题、描述和图片,这些数据是通过内容提供商访问的,我的问题一切顺利直到我从数据库中删除一条记录,应用程序才
我正在尝试使用 Glide 将自定义图像加载到 Google map 信息窗口。我将 Activity 上下文传递给适配器(请参阅下面的代码)。但我既没有看到图像也没有看到错误。 我做错了什么? cl
很惊讶我已经找不到答案了,但是我在使用 Google map 的信息窗口做一些非常简单的事情时遇到了问题。我想创建一个自定义信息窗口,其中包含三段文本,其中一段具有可自定义的颜色(取决于文本,但最好在
您好,我正在开发带有自定义弹出窗口的谷歌地图演示应用程序。请建议我如何处理 TextView 和 ImageView 点击句柄。我无法获得 Activity 。下面是我的代码。 class Popup
我是一名优秀的程序员,十分优秀!