2014-04-20 10 views
0

그래서 자습서를 따라 여기에 있습니다 : developer site.linearLayout은 R java 파일에 포함되어 있지 않습니다.

내 코드는 아래과 같습니다

import android.os.Bundle; 
import android.app.Activity; 
import android.widget.LinearLayout; 

import com.google.android.gms.ads.AdRequest; 
import com.google.android.gms.ads.AdSize; 
import com.google.android.gms.ads.AdView; 

// A simple {@link Activity} that embeds an AdView. 
public class MainActivity extends Activity { 
    // The view to show the ad. 
    private AdView adView; 

    // Your ad unit id. Replace with your actual ad unit id. 
    private static final String AD_UNIT_ID = "INSERT_YOUR_AD_UNIT_ID_HERE"; 

    // Called when the activity is first created. 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    // Create an ad. 
    adView = new AdView(this); 
    adView.setAdSize(AdSize.BANNER); 
    adView.setAdUnitId(AD_UNIT_ID); 

    // Add the AdView to the view hierarchy. The view will have no size 
    // until the ad is loaded. 
    LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout); 
    layout.addView(adView); 

    // Create an ad request. Check logcat output for the hashed device ID to 
    // get test ads on a physical device. 
    AdRequest adRequest = new AdRequest.Builder() 
     .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 
     .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE") 
     .build(); 

    // Start loading the ad in the background. 
    adView.loadAd(adRequest); 
    } 

    @Override 
    public void onResume() { 
    super.onResume(); 
    if (adView != null) { 
     adView.resume(); 
    } 
    } 

    @Override 
    public void onPause() { 
    if (adView != null) { 
     adView.pause(); 
    } 
    super.onPause(); 
    } 

    // Called before the activity is destroyed. 
    @Override 
    public void onDestroy() { 
    // Destroy the AdView. 
    if (adView != null) { 
     adView.destroy(); 
    } 
    super.onDestroy(); 
    } 
} 

을하지만, 내가 응용 프로그램을 테스트에서 저를 유지하는 하나의 해결되지 않은 오류를 얻고있다. 줄에

LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout); 

linearLayout에 대한 오류가 해결되지 않았습니다. R과 R.id는 괜찮습니다. 내 R.java를 살펴보면 linearLayout이 없다는 것을 알 수 있습니다. R.java가 생성 되었기 때문에 분명히 거기에 넣고 싶지는 않습니다.

저는 아직 Android 개발에 익숙하지 않아이 문제를 해결하는 방법을 모르겠습니다. R.java에 어떻게 포함시킬 수 있습니까? linearLayout을 포함하도록 activity_main.xml과 같은 파일을 편집 해 보았습니다.하지만 할 때 "설치 오류 : 알 수없는 오류가 발생했습니다. 자세한 내용은 logcat을 확인하십시오."라는 메시지가 나타납니다. 나는 그것을 볼 때 어떤 logcat이 나에게 말하려고하는지 알지 못한다. "android.widget.LinearLayout 가져 오기"가 있습니다. 나는 무엇을 해야할지/내가 잘못하고있는 것을 모른다.

+2

리소스 파일에 오류가 있습니까? 또한'activity_main.xml'을 게시하십시오 – Raghunandan

+0

귀하의 linearLayout은 XML에 ID'linearLayout' 속성이 있습니까? – donfuxx

+2

레이아웃 파일을 게시하십시오. –

답변

0

이 문제를 해결하기 위해 어떤 작업을 수행합니다. 예 :

1) LinearLayout의 ID가 linearLayout이 아닌 경우 2) 가져 오기 LinearLayout 클래스 3) 프로젝트를 정리합니다. 4) bin 및 gen 폴더를 삭제 하시겠습니까?

관련 문제