从主要活动更改为其他活动时出现错误 - Android
我有一个使用谷歌地图的应用程序 - 直到现在它工作正常。但现在,当我想单击按钮以在地图上添加功能时,我遇到了问题。 我设法在屏幕上可视化按钮,它也可以在单击时工作 - 它可以正确显示吐司。但我的目标是开始一项新活动(拥有自己的布局) - 查找和阅读教程和内容的语气就是我所拥有的:
//the Add Button in the upper right corner
Button addBookmark = (Button) findViewById(R.id.Button);
addBookmark.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View mapView) {
Intent addBookmarkIntent = new Intent(GoogleMapsApp.this, LocationBookmaker.class);
startActivity(addBookmarkIntent);
}
});
此外,我还编辑了清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<activity android:name=".LocationBookmarker"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
...
</manifest>
无论我尝试什么,我总是得到“应用程序 GoogleMapsApp(进程 google.maps.app)已意外停止,请重试。”仅有“强制关闭”选项。
我已经尝试了两天了 - 在互联网上的很多例子中,其他人都说它应该像这样工作。我看不出我的错误在哪里。 也许在意图的开始,或清单或哪里......?
I have an application using the Google maps - until the moment it works fine. But now when I want to click a button in order to add functionality over the map I have problems.
I managed to visualise the button on the screen, also it works on click - it shows a toast correctly. But my aim is to start a new activity (having his own layout) - looking and reading tones of tutorials and stuff here is what I have :
//the Add Button in the upper right corner
Button addBookmark = (Button) findViewById(R.id.Button);
addBookmark.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View mapView) {
Intent addBookmarkIntent = new Intent(GoogleMapsApp.this, LocationBookmaker.class);
startActivity(addBookmarkIntent);
}
});
Also I've edited the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<activity android:name=".LocationBookmarker"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
...
</manifest>
No matter what I try I always get the "The Application GoogleMapsApp (process google.maps.app) has stopped unexpectedly. Please try again." with the only "Force close" option.
I've been trying since two days now - and in a lot of examples in the Internet other say it should be working like this. I cannot see where could be my mistake.
Maybe in the starting of the intent, or the manifest or where...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据例外情况,它正在查找的类是“LocationBookmaker”,但在清单中您有“LocationBookmarker”(注意“r”)。那可能是你的问题。
According to the exception, the class it's looking for is 'LocationBookmaker', but in your manifest you have 'LocationBookmarker' (notice the 'r'). That may be your problem.
我不知道你遇到的问题是什么,但提示是在你的计算机上运行“Dalvik 调试监视器”(ddms),这样你就可以捕获应用程序中的所有异常,并准确地查看错误是什么(大多数错误)时间)。
您可以在 Android 安装的工具目录中找到 ddms,如果您运行 Windows,则它是一个 bat 文件,ddms.bat,您只需从 cmd 运行即可。
/维克托
I don't know what the problem you get is but a tip is to run the "Dalvik Debug Monitor" (ddms) on your computer, with that you can capture all exceptions in your application and see exaclly what the error is (most of the time).
You find the ddms in the tools directory of your android installation, if you run windows its a bat file, ddms.bat, that you just run from cmd.
/Viktor