2013-10-01 2 views
2

비슷한 주제가 stackoverflow에서 발견되었지만 나에게 도움이되지 못했습니다. 조각을 사용하는 Google지도가 표시되고 다른 조각을 가져 와서 다시 돌아 오면 충돌이 발생합니다. 즉, Google지도는 한 번만 표시되고 작동이 중단됩니다. 여기에 코드가 있습니다. 바이너리 XML 파일 라인 # 20 : 오류 팽창 클래스 단편 나는 예외를 catch 할 때android.view.InflateException : 이진 XML 파일 줄 # 20 : 클래스 조각을 부 풀릴 때 오류가 발생했습니다.

public class MapTabMainFragment extends BaseFragment { 
    private AdView adView; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 

     View view = null; 
     try { 
      view = inflater.inflate(R.layout.fragment_map_main, container, 
        false); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

     initComponents(view); 
     initValues(); 
     initListeners(); 

     return view; 
    } 

    public void initComponents(View view) { 
     adView = (AdView) view.findViewById(R.id.adView1); 
    } 

    public void initValues() { 
     AdRequest re = new AdRequest(); 
     adView.loadAd(re); 
    } 

    public void initListeners() { 

    } 
} 

public class BaseFragment extends Fragment { 

    public BottomTabActivity mActivity; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     mActivity = (BottomTabActivity) this.getActivity(); 
    } 

    public boolean onBackPressed() { 
     return false; 
    } 

    public void onActivityResult(int requestCode, int resultCode, Intent data) { 

    } 
} 

, 그것은

android.view.InflateException이다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/WhiteColor" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/header" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="@dimen/data_listview_margin_top" > 

     <fragment 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="@dimen/data_listview_margin_bottom" 
      class="com.google.android.gms.maps.SupportMapFragment" /> 
     <!--class="com.cyrilmottier.polaris2.maps.SupportMapFragment" --> 

     <com.google.ads.AdView 
      android:id="@+id/adView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      app:adSize="SMART_BANNER" 
      app:adUnitId="ca-app-pub-9766031373541061/3761995838" 
      app:loadAdOnCreate="true" 
      app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" > 
     </com.google.ads.AdView> 
    </RelativeLayout> 

</LinearLayout> 
+0

오류는 XML 파일에 있습니다. 게시 할 수 있습니까? – Szymon

+0

@Szymon - XML ​​파일 – user2291109

답변

0
// try this way 

public class MapTabMainFragment extends FragmentActivity { 

    private AdView adView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.fragment_map_main); 
     adView = (AdView) findViewById(R.id.adView1); 
     AdRequest re = new AdRequest(); 
     adView.loadAd(re); 

    } 

} 
1

나는 유래에 대한 연구 후 자신을 해결했습니다. 중첩 조각 문제와 관련이 있습니다. XML에서 맵 조각을 제거하고 프레임을 배치 한 다음 프래그먼트를 프로그래밍 방식으로 추가합니다. 그것은 매력처럼 작동합니다. 모든 노력에 감사드립니다.

+0

을 게시했습니다.이 질문에 대한 답을 선택하십시오. – Emmanuel

+0

코드도 공유하십시오. – VenomVendor

+0

@ user2291109 코드를 공유하십시오. 나도 필요해. –

0

당신은 그것이 실제로 BaseFragment 클래스에서 생성되기 전에 활동에 액세스하려고 ... 대신

mActivity = (BottomTabActivity) this.getActivity(); 

은 "onActivityCreated"방법을 무시하고 거기 할 ...

@Override 
public void onActivityCreated(Bundle savedInstanceState) 
{ 
    mActivity = (BottomTabActivity) this.getActivity(); 
} 
0

애플리케이션의 AndroidManifest.xml 파일을 편집하고 요소 내에 다음 선언을 추가하십시오. 앱이 컴파일 된 버전의 Google Play가 삽입됩니다.

<meta-data 
    android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version" /> 

-> 이것은 내 문제를 해결합니다.

3

XML에서 중첩 된 조각을 가질 수 없습니다. 코드에서해야합니다. 가장 좋은 방법은 FrameLayout을 만들고 런타임에 조각으로 바꾸는 것입니다.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/inquiryLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".InquiryFragment" > 

<FrameLayout 
    android:id="@+id/contentFrame" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" > 

</FrameLayout> 
</RelativeLayout> 

지금 코드는 간단하다 :

public class InquiryFragment extends Fragment { 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     View v = inflater.inflate(R.layout.inquiry_fragment, container, false); 

     Plan1Fragment frag = new Plan1Fragment(); 
     getChildFragmentManager().beginTransaction() 
      .replace(R.id.contentFrame, frag).commit(); 

     return v; 
    } 

} 

을 그리고 그것 뿐이다

다음과 같이 XML은 가정하자.

0

xmlns:android="http://schemas.android.com/apk/res/android"을 선형 레이아웃 태그에 넣는 대신 <com.google.android.gms.ads.AdView 태그에 넣으십시오. 아래와 같이

<com.google.android.gms.ads.AdView 
 
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
 
     android:id="@+id/adView1" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignParentBottom="true" 
 
     app:adSize="SMART_BANNER" 
 
     app:adUnitId="ca-app-pub-9766031373541061/3761995838" 
 
     app:loadAdOnCreate="true" 
 
     app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />

을 추가 지원 방문을 위해이 Link

관련 문제