尝试使用 Android Mapview 类时出现问题
我是 Android 菜鸟,所以请耐心等待,如果我的帖子很白痴,请原谅我。 基本上,我试图向 XML 添加一个地图视图,这会导致一些问题,我得到的错误是:
06-30 12:29:04.760: ERROR/AndroidRuntime(320): java.lang.NoClassDefFoundError: package.android.mapclass
据我所知,此调用中发生了错误:
Intent i = new Intent(oldclass.this, mapclass.class);
地图类本身是:
package package.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.google.android.maps.MapView;
import com.google.android.maps.MapActivity;
import android.util.Log;
public class mapclass extends MapActivity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.viewmap);
protected boolean isRouteDisplayed() {
return false;
}
}
这是它获取的位置有趣的是,如果我将其换出
public class mapclass extends MapActivity {
并替换为
public class mapclass extends Activity {
那么它绝对可以正确工作(尽管没有调用 MapActivity)。 清单中引用了地图:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="package.android"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-library android:name="com.google.android.maps" />
<uses-library android:name="com.google.android.maps.MapView" />
<uses-library android:name="com.google.android.maps.MapActivity" />
<application android:icon="@drawable/icon"
android:label="@string/app_name">
我猜我在 xml 中的活动方面做了一些严重错误的事情?我已经尝试过摆弄,但到目前为止没有效果,有人有任何想法吗?
谢谢,
I'm a noob to Android so bear with me and apologies if my post is moronic.
Basically, I'm trying to add a mapview to the XML which is causing a few problems, the error I'm getting is:
06-30 12:29:04.760: ERROR/AndroidRuntime(320): java.lang.NoClassDefFoundError: package.android.mapclass
From what I can tell the error is happening on this call:
Intent i = new Intent(oldclass.this, mapclass.class);
The mapclass itself is:
package package.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.google.android.maps.MapView;
import com.google.android.maps.MapActivity;
import android.util.Log;
public class mapclass extends MapActivity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.viewmap);
protected boolean isRouteDisplayed() {
return false;
}
}
Here's where it gets interesting, if I swap out
public class mapclass extends MapActivity {
and replace it with
public class mapclass extends Activity {
Then it works absolutely correctly (albeit without calling the calling the MapActivity).
There is a reference to the maps in the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="package.android"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-library android:name="com.google.android.maps" />
<uses-library android:name="com.google.android.maps.MapView" />
<uses-library android:name="com.google.android.maps.MapActivity" />
<application android:icon="@drawable/icon"
android:label="@string/app_name">
I'm guessing that I'm doing something horribly wrong with regards to the activity in the xml? I've tried fiddling but so far to no avail, does anyone have any ideas?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
步骤#1:删除第二个和第三个
元素。步骤#2:更改您的包,使其不包含
package
作为名称的一部分,以最大限度地减少保留关键字问题的可能性。步骤#3:删除
行,因为没有此类权限。步骤#4:在安装了 Google 地图的设备或模拟器上运行您的应用程序。
你真正的问题是第四步——前三步只是为了清理一些东西。 FWIW,我还建议您遵循类名的 CamelCase 约定。
Step #1: Remove your second and third
<uses-library>
elements.Step #2: Change your package to not include
package
as part of the name, to minimize odds of reserved-keyword issues.Step #3: Remove your
<uses-permission android:name="android.permission.LOCATION"/>
line, as there is no such permission.Step #4: Run your application on a device or emulator that has Google Maps installed.
Your real problem is Step #4 -- the first three are just to clean things up a bit. FWIW, I also recommend you follow CamelCase conventions for your class names.