Cferrel
Cferrel

Reputation: 321

Android R file issues and the manifest.xml problems

I am basically doing a tutorial but my program seems to have errors that seem to come from the R file. I have got rid of the auto import and my androidManafest.xml is also giving errors that that's automatically generated. I am just trying to learn to build a decent app. Any helpful advise on fixing the errors will be appreciated. I pointed to the lines i have error with this" i get error -> ".

my convert.java

    package de.vogella.android.tempconvertor;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class Convert extends Activity {
 private EditText text;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
 i get error ->   setContentView(R.layout.main);
 i get error ->   text = (EditText) findViewById(R.id.EditText01);

 }

 // This method is called at button click because we assigned the name to the
 // "On Click property" of the button
 public void myClickHandler(View view) {
  switch (view.getId()) {
 i get error ->   case R.id.Button01:
  i get error ->   RadioButton celsiusButton = (RadioButton) findViewById(R.id.RadioButton01);
 i get error ->    RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.RadioButton02);
   if (text.getText().length() == 0) {
    Toast.makeText(
      this,
      "Please enter a valid number", Toast.LENGTH_LONG).show();
    return;
   }

   float inputValue = Float.parseFloat(text.getText().toString());
   if (celsiusButton.isChecked()) {
    text.setText(String
      .valueOf(convertFahrenheitToCelcius(inputValue)));
   } else {
    text.setText(String
      .valueOf(convertCelciusToFahrenheit(inputValue)));
   }
   // Switch to the other button
   if (fahrenheitButton.isChecked()) {
    fahrenheitButton.setChecked(false);
    celsiusButton.setChecked(true);
   } else {
    fahrenheitButton.setChecked(true);
    celsiusButton.setChecked(false);
   }
   break;
  }
 }

 // Converts to celcius
 private float convertFahrenheitToCelcius(float fahrenheit) {
  return ((fahrenheit - 32) * 5 / 9);
 }

 // Converts to fahrenheit
 private float convertCelciusToFahrenheit(float celsius) {
  return ((celsius * 9) / 5) + 32;
 }
}

Here is my manifest xml file as well

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

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission />

    <application
        android:icon="@drawable/ic_launcher"
     i get error ->     android:label="@string/app_name" >
        <activity
            android:name=".Convert"
       i get error ->       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>

Upvotes: 0

Views: 288

Answers (2)

Pavel Dudka
Pavel Dudka

Reputation: 20944

First of all, make sure you have MyApp string in your res\values\strings.xml

After that, make sure you have R file available in your source tree: [app_root]->gen->de.vogella.android.tempconvertor->R.java

After that, make sure you have included your R resource file in import list

import de.vogella.android.tempconvertor.R;

Upvotes: 1

zapl
zapl

Reputation: 63955

Maybe there is no "app_name" in res\values\strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">MyApp</string>
</resources>

Upvotes: 0

Related Questions