简体   繁体   中英

error “main cannot be resolved or is not a field ”

"MAIN CANNOT RESOLOVED OR NOT IN A FIELD" It gives error in mainactivity at setcontentview "main cannot be resolved or not in field.
This is my code plz help me as i got tired to find a way out plz reomove this error "this is my mainactivity"

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;

    }
}

my manfiestfile

<?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>

and that is my 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>

this call a error in mainactivity in setContentView(R.layout.main); saying that "main cannot not be resoloved or in not a field" i have searched almost every foroum but failed to get through this, plz help me out to solve this error.

Heading

THANKs in Advance

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

您还可以尝试使用activity_main,这是在您使用eclipse创建应用程序时发生的,您将活动名称保留为activity_main(通常有些人不会更改),并且很少有人按照约定进行更改。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM