【问题标题】:error "main cannot be resolved or is not a field "错误“主要无法解析或不是字段”
【发布时间】:2012-10-24 18:41:14
【问题描述】:

“主要无法解决或不在现场” 它在 setcontentview 的 mainactivity 中给出错误“main 无法解析或不在字段中。
这是我的代码,请帮助我,因为我厌倦了寻找出路,请移除此错误 “这是我的主要活动”

package com.exampl.goglemaps;

import android.os.Bundle;
import com.exampl.goglemaps.R;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class MainActivity extends MapActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //fetch the map view from the layout
        MapView mapView = (MapView) findViewById(R.id.mapview);

        //make available zoom controls
        mapView.setBuiltInZoomControls(true);
    }

    @Override
    protected boolean isRouteDisplayed() {

        return false;

    }
}

我的文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exampl.goglemaps"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="14" />

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
      <uses-library android:name="com.google.android.maps" />
    </application>
</manifest>

那是我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

       <com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="Your Google Maps API key"
        android:clickable="true" />
</LinearLayout>

这会调用 setContentView(R.layout.main) 中的 mainactivity 错误;说“主要不能解决或不在一个领域”我几乎搜索了每个论坛但未能通过这个,请帮助我解决这个错误。

标题

提前致谢

【问题讨论】:

  • 在你大喊大叫之前不要使用大写字母。

标签: java android google-maps-api-3 syntax-error


【解决方案1】:

我认为您应该使用R.layout.MainActivity 代替R.layout.main

【讨论】:

    【解决方案2】:

    你也可以试试activity_main 当您使用 eclipse 创建应用程序时会发生这种情况,您将活动名称保留为 activity_main(通常有些人不会更改)并且很少有人根据他们的约定进行更改。

    【讨论】:

      猜你喜欢
      • 2016-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 2011-06-11
      • 2022-01-09
      相关资源
      最近更新 更多