0

我正在使用常用UI元素的碎片。實施一個簡單的POC來檢查它的工作情況。但是,當我integerating我的主要項目給它運行時錯誤(崩潰)Android碎片整合/路徑問題

這裏是我的Androidmainfiest.xml

<activity 
      android:name="com.draw.map.TestActivity" 
      android:label="@string/title_activity_test" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

我的片段XML:fragment_text_view_bottom_slider.xml

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


     <RelativeLayout 
     android:id="@+id/bottom_slider" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 

     <RelativeLayout 
      android:id="@+id/register_main" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:visibility="visible" > 

      <RelativeLayout 
       android:id="@+id/register_inner" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_toLeftOf="@+id/slider_button" 
       android:background="#ECEDF2" 
       android:onClick="goToProfile" 
       android:visibility="visible" > 

       <ImageView 
        android:id="@+id/dummy_image" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:onClick="goToProfile" 
        android:src="@drawable/dp" /> 

       <RelativeLayout 
        android:id="@+id/text_block" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerVertical="true" 
        android:layout_marginLeft="2dp" 
        android:layout_toRightOf="@+id/dummy_image" > 

        <TextView 
         android:id="@+id/register_text1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/bottom_slider_register1" /> 

        <TextView 
         android:id="@+id/register_text2" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/register_text1" 
         android:text="@string/bottom_slider_register2" /> 
       </RelativeLayout> 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/rlSlideAlert" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_toLeftOf="@+id/slider_button" 
       android:background="#ECEDF2" 
       android:visibility="gone" > 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:background="#50555C" 
        android:gravity="right" > 

        <TextView 
         android:id="@+id/bottom_slider_alert_text" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="left" 
         android:gravity="left" 
         android:text="WEH is totally blocked" 
         android:textAlignment="textStart" 
         android:textColor="#FFFFFF" 
         android:textSize="20dp" /> 

        <ImageView 
         android:id="@+id/slider_button" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:onClick="slideButtonOnClick" 
         android:src="@drawable/alert_1" /> 
       </LinearLayout> 
      </RelativeLayout> 

      <ImageView 
       android:id="@+id/slider_button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:onClick="slideButtonOnClick" 
       android:src="@drawable/menu_button" /> 
     </RelativeLayout> 

     <LinearLayout 
      android:id="@+id/menu_main" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/register_main" 
      android:gravity="center_horizontal" 
      android:orientation="horizontal" 
      android:visibility="gone" > 

      <ImageView 
       android:id="@+id/imageView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="goToProfile" 
       android:src="@drawable/dp" /> 

      <ImageView 
       android:id="@+id/imageView3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="reportOnClick" 
       android:src="@drawable/report" /> 

      <ImageView 
       android:id="@+id/route_button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/route_tapover" /> 

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

      <ImageView 
       android:id="@+id/other_icon" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="closeBottomMenu" 
       android:src="@drawable/close_button" /> 
     </LinearLayout> 
    </RelativeLayout> 
</RelativeLayout> 

我的片段的java文件:TextViewBottomSlider.java

public class TextViewBottomSlider extends Fragment{ 

    View view; 

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

     // Inflate the layout for this fragment 
     view = inflater.inflate(R.layout.fragment_text_view_bottom_slider, 
           container, false); 
     // intilizeUIElements(); 
     return view; 
    } 
} 

我的活動xml:activi ty_test.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".TestActivity" > 

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

    <fragment 
     android:id="@+id/bottom_slider_fragment" 
     android:name="com.draw.map.TextViewBottomSlider" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     tools:layout="@layout/fragment_text_view_bottom_slider" /> 

</RelativeLayout> 

我的活動文件:TestActivity.java

public class TestActivity extends FragmentActivity { 

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

} 

我的logcat:

08-24 06:05:12.714: E/AndroidRuntime(5355): FATAL EXCEPTION: main 
08-24 06:05:12.714: E/AndroidRuntime(5355): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.draw.map/com.draw.map.TestActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class fragment 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.os.Handler.dispatchMessage(Handler.java:99) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.os.Looper.loop(Looper.java:123) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at java.lang.reflect.Method.invokeNative(Native Method) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at java.lang.reflect.Method.invoke(Method.java:521) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at dalvik.system.NativeStart.main(Native Method) 
08-24 06:05:12.714: E/AndroidRuntime(5355): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class fragment 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.app.Activity.setContentView(Activity.java:1647) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at com.draw.map.TestActivity.onCreate(TestActivity.java:12) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  ... 11 more 
08-24 06:05:12.714: E/AndroidRuntime(5355): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.draw.map-1.apk] 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.view.LayoutInflater.createView(LayoutInflater.java:466) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 
08-24 06:05:12.714: E/AndroidRuntime(5355):  ... 20 more 

已包括在我的項目的其他庫文件: * Facebook的Android SDK中 *谷歌播放服務 *安卓支持jar 4

感謝您的時間

+0

首先檢查 「TextViewBottomSlider」 級是com.draw.map包... – Piyush

+0

是它在draw.map包中 –

+0

你的min sdk是什麼?併發布完整的清單 – Raghunandan

回答

1

檢查您的進口報表。

正如你說你的MIN SDK vesion是8

論文語句將無法正常工作;

import android.app.Fragment; 
import android.app.FragmentManager; 
import android.app.FragmentTransaction; 

到碎片從SDK vesion支持8需要導入這些語句

import android.support.v4.app.Fragment; 
    import android.support.v4.app.FragmentManager; 
    import android.support.v4.app.FragmentTransaction;