2012-03-20 72 views
0

我基本上在做一个教程,但我的程序似乎有错误,似乎来自R文件。我摆脱了自动导入,我的androidManafest.xml也给出了自动生成的错误。我只是想学习建立一个体面的应用程序。任何有助于解决错误的建议将不胜感激。我指出我对这个“我得到错误 - >”的错误。Android R文件问题和manifest.xml问题

我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; 
} 
} 

这里是我的清单xml文件以及

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

什么是错误的正在接收?您可能需要将R文件添加到您的进口列表ex。导入de.vogella.android.tempconvertor.R; – dymmeh 2012-03-20 21:53:03

+2

空白使用权限元素可能会导致AndroidManifest.xml中的错误,解决它并重建项目。 – Egor 2012-03-20 21:54:11

+0

@Egor我试着在应用程序中添加一个空白的使用权限,这会引发错误。可能这是他的manifest.xml错误的原因 – dymmeh 2012-03-20 21:58:15

回答

1

首先,确保你的MyApp字符串在你的res\values\strings.xml

之后,请确保您有可用R档在你的源代码树: [app_root]->gen->de.vogella.android.tempconvertor->R.java

之后,请确保您已列入进口名单的[R资源文件

import de.vogella.android.tempconvertor.R; 
+0

谢谢。我清理它,我的R文件被删除。所以我重建了它。我希望我很快会制作出我的第一个真正的Android应用程序来投放市场。 – Cferrel 2012-03-21 02:13:41

0

也许没有 “APP_NAME” 在res\values\strings.xml

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