2014-11-17 2 views
-1

나는 이클립스를 설치했고 새로운 소프트웨어 설치 및 sdk 설정을 통해 단계를 수행했습니다. 그러나 MainActivity.java의 오류는 "R을 변수로 해석 할 수 없습니다"입니다. 이것 좀 도와주세요.Eclipse : Android 코드의 "R은 변수로 해결할 수 없습니다"

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hellp"/> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/This is my first Android Application"/> 

<Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/And this is clickable button!"/> 

그것을 저를 @string/This is my first Android Application를 사용

다음 코드를

package com.home.begingwithandroid; 

import android.os.Bundle; 
import android.support.v7.app.ActionBarActivity; 
import android.view.Menu; 
import android.view.MenuItem; 


public class MainActivity extends ActionBarActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
// Inflate the menu; this adds items to the action bar if it is present. 
getMenuInflater().inflate(R.menu.main, menu); 
return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
// Handle action bar item clicks here. The action bar will 
// automatically handle clicks on the Home/Up button, so long 
// as you specify a parent activity in AndroidManifest.xml. 
int id = item.getItemId(); 
if (id == R.id.action_settings) { 
return true; 
} 
return super.onOptionsItemSelected(item); 
} 
} 

감사

입니다

XML 코드가

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hellp"/> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/This is my first Android Application"/> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/And this is clickable button!"/> 

</LinearLayout> 
+0

고전 오류 ... 참조 : http://stackoverflow.com/questions/7824730/r-cannot-be-resolved-to-a-variable http://stackoverflow.com/questions/16642604/eclipse- 오류 -r- 해결할 수없는 변수 http://stackoverflow.com/questions/2757107/developing-for-android-in-eclipse-r-java-not-generating –

+0

나는 그 (것)들 그러나 아무것도는 저를 위해 작동하고있다 – user3440868

+0

그것을 정확하게 시도하십시오, 그것은 작동해야한다 ... –

답변

0

문제가 XML 파일에있을 때 귀하의 문자열 파일에 This is my first Android Application라는 문자열이 있습니다. 해당 텍스트를 정확하게 표시하려면 @string을 제거하십시오.

+0

가져온 후. 새로운 오류가 발견되었습니다. com.home.begingwithandroid.R 가져 오기를 확인할 수 없습니다. 도와주세요. – user3440868

+0

그러면'xml' 파일에 오류가 있습니다. 오류 로그를 점검하여 문제점을 찾으십시오. –

+0

사실이 책에서이 XML 파일을 작성하고 있습니다. 이 xml 코드를 책의 것과 일치시킵니다. 그러나 오류는 발견되지 않았습니다. 나는이 XML 코드로 질문을 업데이트했다. 오류가 있으면 알려주세요. 감사합니다 – user3440868

관련 문제