- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序有问题,其中包括 osmdroid。每次我尝试在我的设备上运行该应用程序并触摸 map 时,该应用程序都会崩溃,并且出现此错误:
2018-10-02 14:11:45.191 19645-19645/com.message_drop.messagedrop E/InputEventReceiver: Exception dispatching input event.
2018-10-02 14:11:45.191 19645-19645/com.message_drop.messagedrop E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
2018-10-02 14:11:45.196 19645-19645/com.message_drop.messagedrop E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean org.osmdroid.views.overlay.Overlay.onTouchEvent(android.view.MotionEvent, org.osmdroid.views.MapView)' on a null object reference
at org.osmdroid.views.overlay.DefaultOverlayManager.onTouchEvent(DefaultOverlayManager.java:214)
at org.osmdroid.views.MapView.dispatchTouchEvent(MapView.java:1050)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:552)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1959)
at android.app.Activity.dispatchTouchEvent(Activity.java:3530)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:505)
at android.view.View.dispatchPointerEvent(View.java:12082)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5325)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5109)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4623)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4676)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4642)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4769)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4650)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4826)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4623)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4676)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4642)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4650)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4623)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7222)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7196)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7157)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7379)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:193)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:379)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:7377)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
2018-10-02 14:11:45.196 19645-19645/com.message_drop.messagedrop D/AndroidRuntime: Shutting down VM
2018-10-02 14:11:45.201 19645-19645/com.message_drop.messagedrop E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.message_drop.messagedrop, PID: 19645
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean org.osmdroid.views.overlay.Overlay.onTouchEvent(android.view.MotionEvent, org.osmdroid.views.MapView)' on a null object reference
at org.osmdroid.views.overlay.DefaultOverlayManager.onTouchEvent(DefaultOverlayManager.java:214)
at org.osmdroid.views.MapView.dispatchTouchEvent(MapView.java:1050)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2611)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:552)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1959)
at android.app.Activity.dispatchTouchEvent(Activity.java:3530)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:505)
at android.view.View.dispatchPointerEvent(View.java:12082)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5325)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5109)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4623)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4676)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4642)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4769)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4650)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4826)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4623)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4676)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4642)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4650)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4623)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7222)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7196)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7157)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7379)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:193)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:379)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:7377)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
我不知道如何处理这个错误,我希望有人能帮助我。我已经在互联网上寻找解决方案,但没有找到任何解决方案。如果您需要更多代码,请告诉我。
这是我的 MainActivity.java:
public class MainActivity extends AppCompatActivity implements LocationListener, View.OnClickListener {
MapView mapView;
MyLocationNewOverlay myLocationOverlay;
private static final String TAG = "MainActivity";
String content = "a";
String author = "b";
Double latitude = 53.2;
Double longitude = 11.5;
private ItemizedIconOverlay<OverlayItem> messagesOverlay;
private List<OverlayItem> items = new ArrayList<>();
private long totalNumberChilds;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//set up the mapView and show the MyLocationOverlay
mapView = findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
mapView.getController().setZoom(5);
myLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(getApplicationContext()), mapView);
myLocationOverlay.enableMyLocation();
mapView.getOverlays().add(messagesOverlay);
mapView.getOverlays().add(myLocationOverlay);
GeoPoint point = this.myLocationOverlay.getMyLocation();
if(point==null){
return;
} else {
mapView.getController().animateTo(point);
}
//initialize the Overlay for the Messages
messagesOverlay = new ItemizedIconOverlay<OverlayItem>(items, getResources().getDrawable(R.drawable.briefumschlag), null, this);
//messagesOverlay.addItem(new OverlayItem(author, "", new GeoPoint(latitude, longitude)));
//declare the database variables in onCreate
//NOTE: Unless you are signed in, this will not be useable.
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
// Read from the database
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
messagesOverlay.removeAllItems();
Toast.makeText(MainActivity.this, "yesss", Toast.LENGTH_LONG).show();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
//Message message = new Message();
//String author1 = ds.child("messageAuthor").getValue(String.class);
/*String content1 = ds.child("messageContent").getValue(String.class);
Double latitude1 = ds.child("messageLatitude").getValue(Double.class);
Double longitude1 = ds.child("messageLongitude").getValue(Double.class);
messagesOverlay.addItem(new OverlayItem("by" + author1, "", new GeoPoint(latitude1, longitude1)));*/
}
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
}
});
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.testButton) {
addMessage();
}
}
public void addMessage() {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
String id = myRef.push().getKey();
Message message = new Message(author, content, latitude, longitude);
myRef.child(id).setValue(message);
Toast.makeText(this, "Message added", Toast.LENGTH_LONG).show();
}
@Override
public void onLocationChanged(Location location) {
GeoPoint point = new GeoPoint(location);
if(point==null){
return;
} else {
mapView.getController().animateTo(point);
}
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}
我的 LoginActivity.java:
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
private FirebaseAuth mAuth;
FirebaseAuth.AuthStateListener mAuthListener;
private EditText tfEmail, tfPassword;
private static final String TAG = "LoginActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
tfEmail = findViewById(R.id.tfEmail);
tfPassword = findViewById(R.id.tfPassword);
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
//User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in" + user.getUid());
Toast.makeText(LoginActivity.this, "Successfully signed in with:" + user.getEmail(),
Toast.LENGTH_SHORT).show();
} else {
//User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
Toast.makeText(LoginActivity.this, "Successfully signed out.", Toast.LENGTH_SHORT).show();
}
}
};
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.btnSignIn) {
String email = tfEmail.getText().toString();
String password = tfPassword.getText().toString();
if (!email.equals("") && !password.equals("")) {
mAuth.signInWithEmailAndPassword(email, password);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
} else {
Toast.makeText(this, "Please fill in all fields!", Toast.LENGTH_SHORT).show();
}
} else if (v.getId() == R.id.btnSignOut) {
mAuth.signOut();
Toast.makeText(this, "Signing Out...", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
mAuth.addAuthStateListener(mAuthListener);
}
@Override
protected void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
}
我的消息.java:
public class Message {
String messageAuthor;
String messageContent;
Double messageLatitude;
Double messageLongitude;
public Message() {
}
public Message(String messageAuthor, String messageContent, Double messageLatitude, Double messageLongitude) {
this.messageAuthor = messageAuthor;
this.messageContent = messageContent;
this.messageLatitude = messageLatitude;
this.messageLongitude = messageLongitude;
}
public String getMessageAuthor() {
return messageAuthor;
}
public String getMessageContent() {
return messageContent;
}
public Double getMessageLatitude() {
return messageLatitude;
}
public Double getMessageLongitude() {
return messageLongitude;
}
public void setMessageAuthor(String messageAuthor) {
this.messageAuthor = messageAuthor;
}
public void setMessageContent(String messageContent) {
this.messageContent = messageContent;
}
public void setMessageLatitude(Double messageLatitude) {
this.messageLatitude = messageLatitude;
}
public void setMessageLongitude(Double messageLongitude) {
this.messageLongitude = messageLongitude;
}
}
我的 activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<org.osmdroid.views.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</org.osmdroid.views.MapView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:id="@+id/testButton"
android:text="add"
/>
</FrameLayout>
和我的 activity_login.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">
<EditText
android:id="@+id/tfEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Email"/>
<EditText
android:id="@+id/tfPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Password"/>
<Button
android:id="@+id/btnSignIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Sign In"
android:onClick="onClick"/>
<Button
android:id="@+id/btnSignOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Sign Out"
android:onClick="onClick"/>
</LinearLayout>
我应该提到的一件事是,在我添加 LoginActivity 类之前, map 工作得非常好。
最佳答案
仔细检查您的 onCreate 方法:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//set up the mapView and show the MyLocationOverlay
mapView = findViewById(R.id.mapview);
//... shortened ...
mapView.getOverlays().add(messagesOverlay); // <== here you are adding null, the messagesOevrlay variable is not yet initialized
mapView.getOverlays().add(myLocationOverlay);
//..shortened...
// here you are creating the instance
messagesOverlay = new ItemizedIconOverlay<OverlayItem>(items, getResources().getDrawable(R.drawable.briefumschlag), null, this);
您应该在调用 getOverlays().add()
之前移动创建实例的行,或者移动 getOverlays().add(messagesOverlay)
下。
关于java - Osmdroid -NullPointerException : Attempt to invoke virtual method 'boolean org. osmdroid.views.overlay.Overlay.onTouchEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52608335/
我有以下代码: Public Delegate Sub SetStatusBarTextDelegate(ByVal StatusText As String) Private Sub SetStat
在调用 Invoke-RestMethod 时使用 Powershell,例如: Invoke-RestMethod -Method Get -Uri "https://google.com/api/
我正在尝试将 Winform 应用程序转换为控制台应用程序。 Winform 应用程序有一个委托(delegate)处理程序。如何在 console 应用程序中编写相同的功能? this.Invoke
在 WPF 中,Dispatcher.Invoke 和直接在控件实例上调用的 Invoke 有什么区别。据我了解,调度程序负责处理线程的消息,Control.Invoke 是否会继续调用 Dispat
我正在研究性能监控系统,它可以将其例程注入(inject)现有程序集。为此,我试图了解 dalvik 代码的工作原理。 下面是我要完成的工作的示例。输入类可能如下所示: class MyClass{
我正在使用 powershell 命令来执行脚本和 cmdlet。因此,在执行 cmdlet 时,我使用了 powershell.invoke,而在执行脚本时,我使用了 pipeline.invoke
有人能解释一下 Invoke-Expression $test 之间的区别吗?和 Invoke-Expression -Command $test ? 变量测试是: $test = "notepad
我有四个类,即 MapperOne、ReducerOne、MapperTwo、ReducerTwo。我想要其中的一个链。 MapperOne-->ReducerOne-->输出文件生成,输入到Mapp
我正在阅读 Java ForkJoin 框架。不直接在 ForkJoinTask 的实现上调用 invoke()(例如 RecursiveTask),而是实例化 ForkJoinPool 有什么额外的
我在调用 Invoke-SqlCmd 时遇到问题,因为它包含第二个 Invoke-SqlCmd 调用: function Get-Foo { $query=` @" WITH data AS (
有人知道如何解决这个问题吗?我创建了一个客户端来使用网络服务。客户端代码为: package cliente; import java.util.List; import handler.Header
我希望使用 P/Invoke 来允许我的 C# 程序集与 native C 库互操作;这需要是跨平台的(即 Mono),因此不能使用混合模式程序集。我想知道使用不安全的 P/invoke 调用并在不安
一般来说,我对使用 Invoke-RestMethod/Invoke-WebRequest 比较陌生 - 我认为这是以下问题的重要背景。 我正在调用如下电话: $Headers = @{ "A
在 Jenkins 的一个自由风格项目(不是说 Maven2/3 项目)中,我有两个可能的构建步骤: 调用 Maven 3 调用顶级 Maven 目标 在不同的安装中,我有不同的组合(有些两者都有,有
这是完整的错误: e: C:\Users\HP\AndroidStudioProjects\MoneyManager\app\src\main\java\com\cruxrepublic\moneym
我正在编写 jQuery 插件并将它们与 AJAX 集成。我正在减少脂肪并专注于基础知识: (function($) { function MyPlugin(el, options) {
有人可以建议我如何处理这条消息吗? CA1060 Move P/Invokes to NativeMethods class Because it is a P/Invoke method, 'UCo
在java中我们可以“用类名调用一个静态方法”也可以“用一个对象调用一个静态方法”java中“用类名调用静态方法”和“用对象调用静态方法”有什么区别? 最佳答案 没有区别,但建议以静态方式调用 sta
尝试从对话框中的 EditText 获取 Edit Text 的值,但一次又一次地出现此错误 Attempt to invoke virtual method 'android.text.Editab
我正在开发一款扑翼应用程序。在出现此错误之前,读取和写入FireStore数据库没有任何问题,但随后突然出现错误(如下所示),并阻止我读取或写入数据库。我一直在寻找答案,但不幸的是,我找不到任何可以解
我是一名优秀的程序员,十分优秀!