我基本上在做一個教程,但我的程序似乎有錯誤,似乎來自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>
什麼是錯誤的正在接收?您可能需要將R文件添加到您的進口列表ex。導入de.vogella.android.tempconvertor.R; – dymmeh 2012-03-20 21:53:03
空白使用權限元素可能會導致AndroidManifest.xml中的錯誤,解決它並重建項目。 – Egor 2012-03-20 21:54:11
@Egor我試着在應用程序中添加一個空白的使用權限,這會引發錯誤。可能這是他的manifest.xml錯誤的原因 – dymmeh 2012-03-20 21:58:15