Android Forums

Go Back   These FORUMS ARE DISABLED!! OUR NEW FORUMS ARE AT http://androidforum.com/ > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
 
 
LinkBack Thread Tools Display Modes
Old 06-23-2010, 11:01 AM   #1
New Member
 
Join Date: Jun 2010
Posts: 0
Friends: 0
View amirand926's Profile   View amirand926's Photo Album   View amirand926's Blog   View Social Groups
Hey everyone, I am just wondering how to get around this error "R.id cannot be resolved." I hate spending so much time on these kinds of errors bc they are IDE ones, not so much code. Either way let me know if you know whats up. Here is the code for the files I think you will want to see:

main.java
main.xml
R.java
androidmainfest.xml


R.java is auto-generated I know and I have tried rebuilding and nothing works. I have even deleted the gen folder and then rebuilt. I dont know why I am not getting an ID for the txtinfo View. I added some code that I got to my standard application (added into the main.java) using the Google API as the target so something is mismatched somewhere obviously. I am coding using Eclipse on Windows 7 with everything updated and installed from the AVD manager. Please help if you can, thanks!

************************************************** ***********
************************** main.java **************************
************************************************** ***********

package com.sunynpcs.GPSex;

import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class Main extends Activity implements LocationListener {

/* this class implements LocationListener, which listens for both
* changes in the location of the device and changes in the status
* of the GPS system.
* */

static final String tag = "Main"; // for Log

TextView txtInfo;
LocationManager lm;
StringBuilder sb;
int noOfFixes = 0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

/* get TextView to display the GPS data */
txtInfo = (TextView) findViewById(R.id.txtInfo);

/* the location manager is the most vital part it allows access
* to location and GPS status services */
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
}

@Override
protected void onResume() {
/*
* onResume is is always called after onStart, even if the app hasn't been
* paused
*
* add location listener and request updates every 1000ms or 10m
*/
lm.requestLocationUpdates(LocationManager.GPS_PROV IDER, 1000, 10f, this);
super.onResume();
}

@Override
protected void onPause() {
/* GPS, as it turns out, consumes battery like crazy */
lm.removeUpdates(this);
super.onResume();
}

@Override
public void onLocationChanged(Location location) {
Log.v(tag, "Location Changed");

sb = new StringBuilder(512);

noOfFixes++;

/* display some of the data in the TextView */

sb.append("No. of Fixes: ");
sb.append(noOfFixes);
sb.append('\n');
sb.append('\n');

sb.append("Londitude: ");
sb.append(location.getLongitude());
sb.append('\n');

sb.append("Latitude: ");
sb.append(location.getLatitude());
sb.append('\n');

sb.append("Altitiude: ");
sb.append(location.getAltitude());
sb.append('\n');

sb.append("Accuracy: ");
sb.append(location.getAccuracy());
sb.append('\n');

sb.append("Timestamp: ");
sb.append(location.getTime());
sb.append('\n');

txtInfo.setText(sb.toString());
}

@Override
public void onProviderDisabled(String provider) {
/* this is called if/when the GPS is disabled in settings */
Log.v(tag, "Disabled");

/* bring up the GPS settings */
Intent intent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_S ETTINGS);
startActivity(intent);
}

@Override
public void onProviderEnabled(String provider) {
Log.v(tag, "Enabled");
Toast.makeText(this, "GPS Enabled", Toast.LENGTH_SHORT).show();

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
/* This is called when the GPS status alters */
switch (status) {
case LocationProvider.OUT_OF_SERVICE:
Log.v(tag, "Status Changed: Out of Service");
Toast.makeText(this, "Status Changed: Out of Service",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
Log.v(tag, "Status Changed: Temporarily Unavailable");
Toast.makeText(this, "Status Changed: Temporarily Unavailable",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.AVAILABLE:
Log.v(tag, "Status Changed: Available");
Toast.makeText(this, "Status Changed: Available",
Toast.LENGTH_SHORT).show();
break;
}
}

@Override
protected void onStop() {
/* may as well just finish since saving state in not important for this toy app */
finish();
super.onStop();
}
}

************************************************** ***********
************************** 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="@string/hello"
/>
</LinearLayout>


************************************************** ***********
************************** R.java **************************
************************************************** ***********

/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/

package com.sunynpcs.GPSex;

public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}





************************************************** ***********
******************** androidmainfest.xml ***********************
************************************************** ***********


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

<!-- I added the permission below -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCAT ION" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
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>
<uses-sdk android:minSdkVersion="7" />

</manifest>
amirand926 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
 

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Phone boots, then ERROR Bracketology Droid 2 06-04-2010 09:31 AM
Beginner Android GUI ajj_dev Android Development, Answers, Tutorials, and Code Snippets 0 05-26-2010 08:46 PM
Android Beginner sohguanh Android Chat 0 04-18-2010 11:00 AM
Error messages. :/ sevastemarie Droid Eris 0 01-03-2010 07:36 PM
Connection error? dtwalkerfl HTC Smart Mobility 8 12-02-2009 07:23 AM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 05:14 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2012 TalkAndroid.com. All rights reserved.