- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
无论我做什么,我的代码似乎都会在 getMap() 处崩溃。我几乎在所有地方都尝试过调整我的代码。我以前创建过这个应用程序,但由于计算机崩溃,我不得不重建。我的一些代码。现在它崩溃了。我的主要代码:
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class FishFishSpotActivity extends Activity{
public static final String XCORD = "xcord";
public static final String YCORD = "ycord";
public static final String NOTE = "note";
public static final String SAVED = "saved";
public static final String ID = "id";
TextView XCord= null;
TextView YCord= null;
TextView Note= null;
int Id = 0;
Boolean Saved = null;
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fish_fish_spot);
initializeMap();
}
protected void onStart(){
map.isMyLocationEnabled();
}
@Override
protected void onResume() {
super.onResume();
}
public boolean onCreateOptionsMenu(Menu menu){
return false;
}
public void onMapClick(LatLng point){
map.addMarker(new MarkerOptions().position(point));
}
public void onMarkerClick(Marker marker){
}
public static void SpotSaved(boolean saved, String A){
}
private void initializeMap()
{
if (map == null) {
map = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (map == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
}
这是我的manafist:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Nick.fishfishspot"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19" />
<permission
android:name="com.Nick.fishfishspot.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.Nick.fishfishspot.permission.MAPS_RECEIVE"/>
<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"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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.maps.v2.API_KEY"
android:value="key is here"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.Nick.fishfishspot.FishFishSpotActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.Nick.fishfishspot.FishFishSpotActivity$PlaceholderFragment" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="go" />
<EditText
android:id="@+id/x_cord"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/y_cord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/x_cord"
android:layout_alignBottom="@+id/x_cord"
android:layout_toLeftOf="@id/button1"
android:layout_toRightOf="@+id/x_cord"
android:ems="10" />
这是错误:
05-05 22:44:53.390: E/AndroidRuntime(24604): FATAL EXCEPTION: main
05-05 22:44:53.390: E/AndroidRuntime(24604): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Nick.fishfishspot/com.Nick.fishfishspot.FishFishSpotActivity}:java.lang.NullPointerException
05-05 22:44:53.390: E/AndroidRuntime(24604): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2304)
05-05 22:44:53.390: E/AndroidRuntime(24604): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
05-05 22:44:53.390: E/AndroidRuntime(24604): at android.app.ActivityThread.access$700(ActivityThread.java:165)
05-05 22:44:53.390: E/AndroidRuntime(24604): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
05-05 22:44:53.390: E/AndroidRuntime(24604): at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 22:44:53.390: E/AndroidRuntime(24604): at android.os.Looper.loop(Looper.java:137)
05-05 22:44:53.390: E/AndroidRuntime(24604): at android.app.ActivityThread.main(ActivityThread.java:5450)
05-05 22:44:53.390: E/AndroidRuntime(24604): at java.lang.reflect.Method.invokeNative(Native Method)
05-05 22:44:53.390: E/AndroidRuntime(24604): at java.lang.reflect.Method.invoke(Method.java:525)
05-05 22:44:53.390: E/AndroidRuntime(24604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
05-05 22:44:53.390: E/AndroidRuntime(24604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
05-05 22:44:53.390: E/AndroidRuntime(24604): at dalvik.system.NativeStart.main(Native Method)
05-05 22:44:53.390: E/AndroidRuntime(24604): Caused by: java.lang.NullPointerException
05-05 22:44:53.390: E/AndroidRuntime(24604): at com.Nick.fishfishspot.FishFishSpotActivity.initializeMap(FishFishSpotActivity.java:76)
05-05 22:44:53.390: E/AndroidRuntime(24604): at com.Nick.fishfishspot.FishFishSpotActivity.onCreate(FishFishSpotActivity.java:38)
05-05 22:44:53.390: E/AndroidRuntime(24604): at android.app.Activity.performCreate(Activity.java:5369)
05-05 22:44:53.390: E/AndroidRuntime(24604): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
05-05 22:44:53.390: E/AndroidRuntime(24604): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
05-05 22:44:53.390: E/AndroidRuntime(24604): ... 11 more
最佳答案
你不见了
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
在 list 的应用标签中
getMap()
可以返回 null。您可以在初始化 GoogleMap
对象之前检查 google play 服务的可用性
A GoogleMap can only be acquired using getMap() when the underlying maps system is loaded and the underlying view in the fragment exists. This class automatically initializes the maps system and the view; however you cannot be guaranteed when it will be ready because this depends on the availability of the Google Play services APK. If a GoogleMap is not available, getMap() will return null.
此外,tools:context="com.Nick.fishfishspot.FishFishSpotActivity$PlaceholderFragment"
提示您在 Activity 中初始化您的 MapFragment
属于 fragment 。
如果您想在 fragment 中放置 map ,则需要扩展 MapFragment
或在 fragment 布局中使用 MapView
。
Android - android.view.InflateException: Binary XML file line #8: Error inflating class fragment
关于java - 每当我调用 getMap() 时,我都会收到 nullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23485662/
我有两个方法@GetMapping和@GetMapping("/{id}") @RestController("/user"){ public class UserRestController { @
我想将编码添加到映射 Controller 的响应中。但是由于某种原因出现了编译错误。只需要一个值数组 如何在响应中添加编码? 最佳答案 @GetMapping("/cards", produces
有时可能会发生这样的情况:数据库中什么都没有,方法 .findAll() 没有任何内容可显示并返回空主体。我知道我有这个函数的返回类型“List”,并且我不能直接返回字符串,但是如果列表为空,我如何以
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 7 年前。 我知道周围有很多类似的帖子,但没
我正在尝试为 @GetMapping 创建多条路线。例如,localhost:8080/tasks 和 localhost:8080/tasks/?status=... 所以我创建了如下几个方法。 C
Image for clarification我是 Spring MVC 的新手,我正在 Maven 上做这个项目。我试图导入 @GetMapping 但它没有被导入。可能是什么问题?有人可以帮我吗?
我只是创建一个 map 项目并执行此代码。但是有 getMap() 错误。我尝试了一些来自互联网的示例代码,但 getMap() 函数中也存在同样的错误。代码是: private Google
private GoogleMap mMap; 我从 MainActivity 开始一个类似的 Activity : @SuppressWarnings("StatementWithEmptyBody
我正在尝试使用堆栈溢出答案之一的交互式信息窗口。 链接如下: interactive infowindow 但是我在代码中使用 getMap() 时遇到错误。虽然我尝试使用 getMapAsync 但
我试图在不依赖 application.properties 中的 server.contextPath 的情况下创建我的路由 这是一个例子: @PreAuthorize("hasRole('ROLE
这个问题在这里已经有了答案: Cannot resolve method getMap() (2 个答案) 关闭 4 年前。 我对这段代码有疑问,“无法解析方法 getMap()。我没有找到问题出在
我正在尝试让一个 map fragment 在我的应用程序中工作,但在尝试获取我的 GoogleMap 对象时仍然出现错误。 FragmentWithMap.java import android.M
将 Leaflet 添加到我的 AngularJS 应用程序后: 并进行设置: // Initialise the feature group to store editable layers va
在我的 Controller 中,@GetMapping 的以下使用有效: @GetMapping(value = "/new") public String newEssay(){ retu
我有以下 Controller : @RestController @RequestMapping("/api/{brand}") public class CarController { pri
我使用处理程序从支持 map fragment 中获取 GoogleMap。我真的迷路了,几天来一直在努力修复它。 map 加载正常,但我怀疑它返回的是空值。我知道可能有一些不好的做法,但这不是我的问
我在 Spring boot 中遇到了 @GetMapping 的问题。 关于我的 @GetMapping 函数,在从数据库中获取所有数据时,它没有在此模型上序列化我的 id: //User.java
在尝试创建 GoogleMap 对象(它返回 null)时,我在让 .getMap() 工作时遇到了很多麻烦,我环顾四周,发现人们也遇到了类似的问题,但无法从他们那里找到任何帮助。在当前的实现中,我如
在尝试了几乎所有方法之后,我似乎无法在不提取空对象引用的情况下获取 map 。我试图将一个 google mapfragment 膨胀成一个 fragment ,但是每次我这样做时我总是保留一个 ge
这个问题在这里已经有了答案: Cannot resolve method getMap() (2 个答案) 关闭 4 年前。 我有一个在手机上运行良好的 GPS 应用程序。但是,我看到有人在生产中出
我是一名优秀的程序员,十分优秀!