Issue
I am trying to do a location app and am in the trouble shooting phase right now. I am down to my last two problems and they both relate to R. blah blah. It says main is either not a field or cannot be resolved and the same message but with mapview instead of main. Below are my imports and the lines of code where the issue is.
Code:
setContentView(R.layout.main);
mapview = (MapView)findViewById(R.id.mapview);
Imports:
import android.R;
import android.R.layout;
import android.R.id;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
I've tried everything. I know people keep saying to take out android.R but that is where R.layout and R.id are found in the jar files. I have right clicked the folder and validated the code. I have gone to Project/Clean and done that. No luck. Please help? And this is my first post so I'm sorry if its formatted wrong. I thank you in advance for any help you give me. Here is my main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Waiting for location..."
android:id="@+id/lblLocationInfo"
/>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0vFrUOhHMkbahT9zXqiz_DuNVWfPqlEyqcO8ftg"
/>
</LinearLayout>
Solution
unless you are using resources from android you shouldn't need the lines
import android.R;
import android.R.Id;
import android.R.layout;
Remove those lines
R is resolving to androids R and not com.yourpackage.yourproject.R
.
Remove the import if it's not needed. If it is your need to be explicit in your code. ex.
ImageView.setDrawable(android.R.ic_menu_search); //uses an android resource
findViewById(R.id.mapView); //uses your resource file
setContentView(R.layout.activity_main); // must have an activity_main.xml file in YourProject/res/layout
Edit:
changes to your code below:
//import android.R;
//import android.R.layout; //comment or delete these lines
//import android.R.id;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
setContentView(R.layout.activity_main); //changed main to activity_main
mapview = (MapView)findViewById(R.id.mapview);
Edit 2
At the very top of your MainActivity.java it should have a line that starts with package
what does the rest of that line say?
In your AndroidManifest.xml there is also an entry for package what does it say?
Answered By - bytebender