Java Android R文件问题和manifest.xml问题
我基本上是在做教程,但我的程序似乎有错误,似乎来自R文件。我已经摆脱了自动导入,我的androidManafest.xml也给出了自动生成的错误。我只是想学习建立一个像样的应用程序。如有任何关于纠正错误的有用建议,将不胜感激。我用“我得到错误->”指出了我有错误的行 我的convert.javaJava Android R文件问题和manifest.xml问题,java,android,r.java-file,Java,Android,R.java File,我基本上是在做教程,但我的程序似乎有错误,似乎来自R文件。我已经摆脱了自动导入,我的androidManafest.xml也给出了自动生成的错误。我只是想学习建立一个像样的应用程序。如有任何关于纠正错误的有用建议,将不胜感激。我用“我得到错误->”指出了我有错误的行 我的convert.java package de.vogella.android.tempconvertor; import android.app.Activity; import android.os.Bundle;
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>
android:label=“@string/app_name”>
android:label=“@string/app_name”>
可能res\values\strings.xml中没有“app\u name”
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MyApp</string>
</resources>
MyApp
首先,确保您的res\values\strings.xml文件中有MyApp字符串
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MyApp</string>
</resources>
之后,确保源代码树中有可用的R文件:
[app_root]->gen->de.vogella.android.tempconvertor->R.java
之后,确保已将R资源文件包括在导入列表中
import de.vogella.android.tempconvertor.R;
您收到的错误有哪些?您可能只需要将R文件添加到导入列表中,例如import de.vogella.android.tempconvertor.R;空白使用权限元素可能会导致AndroidManifest.xml中的错误,解决它并重建项目。@ EGOR我尝试在我的应用程序中添加一个空白的使用权限,这将引发一个错误。很可能这就是他的manifest.xml错误的原因,谢谢。我清理了它,我的R文件被删除了。所以我重建了它。我希望我能很快在市场上推出第一款真正的android应用程序。