2015-11-12 3 views
2

Я получаю ошибку ниже, в основном на Android 4.1 и 4.4:

java.lang.RuntimeException: Unable to create service se.weblink.weblinkunified.services.FloatingWindowService: android.view.InflateException: Binary XML file line #68: Error inflating class <unknown> 
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2406) 
at android.app.ActivityThread.access$1700(ActivityThread.java:134) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1306) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4867) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.view.InflateException: Binary XML file line #68: Error inflating class <unknown> 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:495) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at se.weblink.weblinkunified.services.FloatingWindowService.addViewToWindow(FloatingWindowService.java:122) 
at se.weblink.weblinkunified.services.FloatingWindowService.onCreate(FloatingWindowService.java:92) 
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2396) 
... 10 more 

addViewToWindow функция:

final LayoutInflater layoutInflater = LayoutInflater.from(this); 
    popupWindow = layoutInflater.inflate(R.layout.window_floating_call, null); 

    final WindowManager.LayoutParams params = setupLayoutParams(); 

    final View.OnClickListener clickListener = getViewClickListener(); 
    final View.OnTouchListener touchListener = getTouchListener(params); 
    popupWindow.setOnClickListener(clickListener); 
    popupWindow.setOnTouchListener(touchListener); 

    final View overlayView = popupWindow.findViewById(R.id.overlay_view); 
    overlayView.setOnClickListener(clickListener); 
    overlayView.setOnTouchListener(touchListener); 

    final View topContainer = popupWindow.findViewById(R.id.call_top_container); 

    buttonContainer = (LinearLayout) popupWindow.findViewById(R.id.call_bottom_container); 
    buttonContainer.addView(getActiveCallButtons()); 

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); 
    final Resources resources = getResources(); 

    topContainer.setBackgroundColor(sharedPreferences.getInt(Constants.THEME_COLOR_PRIMARY, resources.getColor(R.color.accent_color_default))); 

    setupCloseButton(); 

    windowManager.addView(popupWindow, params); 
    popupWindow.setTranslationY(Tools.getDensityIndependentSize(-120, resources)); 
    popupWindow.setVisibility(View.GONE); 

И файл XML "window_floating_call":

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="10dp" 
android:paddingRight="10dp"> 

<RelativeLayout 
    android:id="@+id/call_top_container" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp" 
    android:background="@color/accent_color_default" 
    > 
    <ImageView 
     android:id="@+id/contact_image" 
     android:layout_width="54dp" 
     android:layout_height="54dp" 
     android:layout_marginRight="10dp" 
     android:src="@drawable/ic_contact_picture" 
     /> 
    <TextView 
     android:id="@+id/contact_initial_label" 
     android:layout_width="55dp" 
     android:layout_height="55dp" 
     android:gravity="center" 
     android:layout_marginRight="10dp" 
     android:textSize="25dp" 
     android:fontFamily="sans-serif-light"/> 
    <TextView 
     android:id="@+id/incoming_call_label" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="2dp" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/contact_image" 
     android:textColor="@color/text_color_bright" 
     android:text="@string/incoming_call" 
     android:textSize="10sp" 
     android:fontFamily="sans-serif"/> 
    <TextView 
     android:id="@+id/contact_name_label" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/incoming_call_label" 
     android:layout_marginTop="4dp" 
     android:layout_toRightOf="@+id/contact_image" 
     android:textColor="@color/text_color_bright" 
     android:textSize="18sp" 
     android:fontFamily="sans-serif"/> 


    <TextView 
     android:id="@+id/contact_number_label" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/contact_image" 
     android:gravity="top" 
     android:layout_below="@+id/contact_name_label" 
     android:fontFamily="sans-serif-light" 
     android:textSize="14sp" 
     android:textColor="@color/text_color_bright"/> 
    <View 
     android:id="@+id/overlay_view" 
     android:layout_width="match_parent" 
     android:layout_height="54dp"/> 
    <ImageButton 
     android:id="@+id/close_button" 
     android:layout_width="24dp" 
     android:layout_height="24dp" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/ic_action_cancel" 
     android:alpha="0.7" 
     style="@style/Base.Widget.AppCompat.ActionButton"/> 
</RelativeLayout> 
<LinearLayout 
    android:id="@+id/call_bottom_container" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/call_top_container" 
    android:orientation="vertical" 
    android:weightSum="1" 
    > 



</LinearLayout> 

Я не могу понять, что вызывает ошибку. Проблема не возникает на Android 5.1. И я не понимаю, почему этот код не сможет работать на Android 4.1, 4.2, 4.4.

Я ценю, если кто-то может мне помочь. Заранее спасибо!

Забыл включить android.content.res.Resources $ Ошибка NotFoundException. Но исключение говорит о том, что файл ресурсов не является доступным. У меня есть изображение ic_action_cancel во всех других доступных папках (drawable-hdpi, drawable-mdpi и т. Д.), За исключением основной доступной папки (с возможностью рисования). Я попытался добавить файл .png в основную папку, но это не сработало.

+0

, возможно, 4.4 не поддерживает его. –

+0

проблема с вашим стилем (Base.Widget.AppCompat.ActionButton), который вы добавляете в ImageButton. –

ответ

0

Я столкнулся с той же проблемой, что и ваши. Я сначала использовал мой inflateUtils, который пишет сам.

Код:

public static View inflate(int id) { 
    return View.inflate(getContext(), id, null); 
} 

И метод getContext() возвращают applicationContext. И это произошло InflateExcepition.

И теперь я использую View.inflate(context, resId, null), и контекст - это моя деятельность. И это сработало сейчас! надеюсь, что это может вам помочь.

Извините за плохой английский!