java - 安卓应用程序错误

标签 java android

我的 xml 代码是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.google.android.maps.MapView
                 android:id="@+id/mapView"

                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:enable="true"
                 android:clickable="true"
                 android:apiKey="0THdCiXY7jaJ9Br1ZQahFE4Lu1xTv1hAiVJBvxQ"
                 />
</RelativeLayout>

list 是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.google.haha"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>


    <application android:icon="@drawable/icon" android:label="@string/app_name">
      <uses-library android:name="com.google.android.maps"/>  
        <activity android:name=".NewActivity"
                  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>

这是主要代码:

package com.google.haha;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.app.Activity;
import android.os.Bundle;

public class NewActivity extends MapActivity {
    /** Called when the activity is first created. */

    MapController mControl;
    GeoPoint GeoP;
    MapView mapV;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       mapV=(MapView)findViewById(R.id.mapView);
       mapV.displayZoomControls(true);
       mapV.setBuiltInZoomControls(true);
       double lat=21.00;
       double longi=79.00;
       GeoP=new GeoPoint((int)(lat*1E6),(int)(longi*1E6));

       mControl=mapV.getController();
       mControl.animateTo(GeoP);
       mControl.setZoom(12);


    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}

一切都很好,但我在网上遇到错误:

mapV=(MapView)findViewById(R.id.mapView);

id 字段无法识别。

最佳答案

尝试清理并重建您的项目,因为这个问题有时会出现在 Eclipse IDE 上,您的 MapView 的 id 在您的 R.java 文件中无法识别:

项目==>清理==>选择您的项目并点击确定

关于java - 安卓应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6397703/

相关文章:

java - 无法返回 Cursor 对象 - close() 从未明确称为错误

Java Sockets - 将数据从服务器发送到客户端

android - Android 方法跟踪上的权限被拒绝消息

android - VectorDrawable 作为 NativeScript 中的图像源

java - 通过将元素设置为 null 来释放数组中的空间?

java - createBufferStrategy 不能作为变量?

android - Phonegap 启动画面和图标的完整列表

java - Android 应用程序因代码错误而崩溃,不理解 logcat 消息

android - (异常资源 $NotFoundException))ListView.layoutChildren() 行 : 1596

java - JAXB 2.1 绑定(bind)自定义选项