2 votes

impossibilité d'utiliser la mise en page du coordinateur avec la mise en page des contraintes

J'ai un projet Android qui utilise la mise en page du coordinateur pour concevoir une mise en page. Cela fonctionnait bien jusqu'à ce que je rajoute 'com.android.support.constraint:constraint-layout:1.0.2' aux dépendances.

lorsque j'ouvre cette mise en page particulière en utilisant la mise en page du coordinateur sur mon appareil marshmello, une exception d'exécution se produit.

03-17 11:39:30.247 10261-10261/com.alamkanak.weekview D/AndroidRuntime:     Shutting down VM
03-17 11:39:30.250 10261-10261/com.alamkanak.weekview E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: com.alamkanak.weekview, PID: 10261
                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alamkanak.weekview/com.alamkanak.weekview.sample.BasicActivity}: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2445)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2505)
                                                                        at android.app.ActivityThread.access$1000(ActivityThread.java:153)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:154)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5466)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
                                                                     Caused by: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:543)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
                                                                        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                        at com.alamkanak.weekview.sample.BaseActivity.onCreate(BaseActivity.java:49)
                                                                        at android.app.Activity.performCreate(Activity.java:6303)
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2398)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2505) 
                                                                        at android.app.ActivityThread.access$1000(ActivityThread.java:153) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:154) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5466) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629) 
                                                                     Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout
                                                                        at android.view.LayoutInflater.createView(LayoutInflater.java:649)
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:768)
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:496)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
                                                                        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                        at com.alamkanak.weekview.sample.BaseActivity.onCreate(BaseActivity.java:49) 
                                                                        at android.app.Activity.performCreate(Activity.java:6303) 
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2398) 
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2505) 
                                                                        at android.app.ActivityThread.access$1000(ActivityThread.java:153) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:154) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5466) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629) 
                                                                     Caused by: java.lang.reflect.InvocationTargetException
                                                                        at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                        at android.view.LayoutInflater.createView(LayoutInflater.java:623)
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:768) 
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:496) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
                                                                        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                        at com.alamkanak.weekview.sample.BaseActivity.onCreate(BaseActivity.java:49) 
                                                                        at android.app.Activity.performCreate(Activity.java:6303) 
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2398) 
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2505) 
                                                                        at android.app.ActivityThread.access$1000(ActivityThread.java:153) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:154) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5466) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629) 
                                                                     Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
                                                                        at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:36)
                                                                        at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:185)
                                                                        at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:179)
                                                                        at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                                        at android.view.LayoutInflater.createView(LayoutInflater.java:623) 
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:768) 
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:496) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
                                                                        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                        at com.alamkanak.weekview.sample.BaseActivity.onCreate(BaseActivity.java:49) 
                                                                        at android.app.Activity.performCreate(Activity.java:6303) 
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2398) 
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2505) 
                                                                        at android.app.ActivityThread.access$1000(ActivityThread.java:153) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:154) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5466) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629) 
03-17 11:39:30.254 10261-10261/com.alamkanak.weekview E/MQSEventManagerDelegate: failed to get MQSService.
03-17 11:39:30.286 10261-10261/com.alamkanak.weekview I/Process: Sending signal. PID: 10261 SIG: 9

aidez-moi à me débarrasser de cette exception.

base_d'activité.xml

<android.support.design.widget.CoordinatorLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".BaseActivity"
    android:background="#fff">

    <com.alamkanak.weekview.WeekView
        android:id="@+id/weekView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:eventTextColor="@android:color/white"
        app:textSize="12sp"
        app:hourHeight="60dp"
        app:headerColumnPadding="8dp"
        app:headerColumnTextColor="@color/toolbar_text"
        app:headerRowPadding="12dp"
        app:columnGap="8dp"
        app:noOfVisibleDays="3"
        app:headerRowBackgroundColor="@color/toolbar"
        app:dayBackgroundColor="#05000000"
        app:todayBackgroundColor="#1848adff"
        app:headerColumnBackground="#ffffffff"
        app:todayHeaderTextColor="@color/accent" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:backgroundTint="@color/colorPrimary"
        app:srcCompat="@android:drawable/ic_menu_edit" />

</android.support.design.widget.CoordinatorLayout>

BaseActivity.java

package com.alamkanak.weekview.sample;

import android.graphics.RectF;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentContainer;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.alamkanak.weekview.DateTimeInterpreter;
import com.alamkanak.weekview.MonthLoader;
import com.alamkanak.weekview.WeekView;
import com.alamkanak.weekview.WeekViewEvent;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

/**
 * This is a base activity which contains week view and all the codes necessary to initialize the
 * week view.
 * Created by Raquib-ul-Alam Kanak on 1/3/2014.
 * Website: http://alamkanak.github.io
 */
public abstract class BaseActivity extends AppCompatActivity implements WeekView.EventClickListener, MonthLoader.MonthChangeListener, WeekView.EventLongPressListener, WeekView.EmptyViewLongPressListener {
    private static final int TYPE_DAY_VIEW = 1;
    private static final int TYPE_THREE_DAY_VIEW = 2;
    private static final int TYPE_WEEK_VIEW = 3;
    private int mWeekViewType = TYPE_THREE_DAY_VIEW;
    private static WeekView mWeekView;
    private FloatingActionButton fab;

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

        fab = (FloatingActionButton) findViewById(R.id.fab);

        // Get a reference for the week view in the layout.
        mWeekView = (WeekView) findViewById(R.id.weekView);

        // Show a toast message about the touched event.
        mWeekView.setOnEventClickListener(this);

        // The week view has infinite scrolling horizontally. We have to provide the events of a
        // month every time the month changes on the week view.
        mWeekView.setMonthChangeListener(this);

        // Set long press listener for events.
        mWeekView.setEventLongPressListener(this);

        // Set long press listener for empty view
        mWeekView.setEmptyViewLongPressListener(this);

        // Set up a date time interpreter to interpret how the date and time will be formatted in
        // the week view. This is optional.
        setupDateTimeInterpreter(false);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                showPopup(view);
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        setupDateTimeInterpreter(id == R.id.action_week_view);
        switch (id){
            case R.id.action_today:
                mWeekView.goToToday();
                return true;
            case R.id.action_day_view:
                if (mWeekViewType != TYPE_DAY_VIEW) {
                    item.setChecked(!item.isChecked());
                    mWeekViewType = TYPE_DAY_VIEW;
                    mWeekView.setNumberOfVisibleDays(1);

                    // Lets change some dimensions to best fit the view.
                    mWeekView.setColumnGap((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
                    mWeekView.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
                    mWeekView.setEventTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
                }
                return true;
            case R.id.action_three_day_view:
                if (mWeekViewType != TYPE_THREE_DAY_VIEW) {
                    item.setChecked(!item.isChecked());
                    mWeekViewType = TYPE_THREE_DAY_VIEW;
                    mWeekView.setNumberOfVisibleDays(3);

                    // Lets change some dimensions to best fit the view.
                    mWeekView.setColumnGap((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
                    mWeekView.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
                    mWeekView.setEventTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
                }
                return true;
            case R.id.action_week_view:
                if (mWeekViewType != TYPE_WEEK_VIEW) {
                    item.setChecked(!item.isChecked());
                    mWeekViewType = TYPE_WEEK_VIEW;
                    mWeekView.setNumberOfVisibleDays(7);

                    // Lets change some dimensions to best fit the view.
                    mWeekView.setColumnGap((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics()));
                    mWeekView.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 10, getResources().getDisplayMetrics()));
                    mWeekView.setEventTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 10, getResources().getDisplayMetrics()));
                }
                return true;
        }

        return super.onOptionsItemSelected(item);
    }

    /**
     * Set up a date time interpreter which will show short date values when in week view and long
     * date values otherwise.
     * @param shortDate True if the date values should be short.
     */
    private void setupDateTimeInterpreter(final boolean shortDate) {
        mWeekView.setDateTimeInterpreter(new DateTimeInterpreter() {
            @Override
            public String interpretDate(Calendar date) {
                SimpleDateFormat weekdayNameFormat = new SimpleDateFormat("EEE", Locale.getDefault());
                String weekday = weekdayNameFormat.format(date.getTime());
                SimpleDateFormat format = new SimpleDateFormat(" M/d", Locale.getDefault());

                // All android api level do not have a standard way of getting the first letter of
                // the week day name. Hence we get the first char programmatically.
                // Details: http://stackoverflow.com/questions/16959502/get-one-letter-abbreviation-of-week-day-of-a-date-in-java#answer-16959657
                if (shortDate)
                    weekday = String.valueOf(weekday.charAt(0));
                return weekday.toUpperCase() + format.format(date.getTime());
            }

            @Override
            public String interpretTime(int hour) {
                return hour > 11 ? (hour - 12) + " PM" : (hour == 0 ? "12 AM" : hour + " AM");
            }
        });
    }

    protected String getEventTitle(Calendar time) {
        return String.format("Event of %02d:%02d %s/%d", time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE), time.get(Calendar.MONTH)+1, time.get(Calendar.DAY_OF_MONTH));
    }

    @Override
    public void onEventClick(WeekViewEvent event, RectF eventRect) {
        Toast.makeText(this, "Clicked " + event.getName() + ", Id : " + event.getId(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onEventLongPress(WeekViewEvent event, RectF eventRect) {
        Toast.makeText(this, "Long pressed event: " + event.getName(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onEmptyViewLongPress(Calendar time) {
        Toast.makeText(this, "Empty view long pressed: " + getEventTitle(time), Toast.LENGTH_SHORT).show();
    }

    public static WeekView getWeekView() {
        return mWeekView;
    }

    public void showPopup(View anchorView) {

/*        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        int screenHeight = metrics.heightPixels;
        int screenWidth = metrics.widthPixels;

        final LayoutInflater inflater = getLayoutInflater();
        // MainActivity2.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        final View popupWindow = inflater.inflate(R.layout.create_event,(ViewGroup) findViewById(R.id.createEventPopup));
        final PopupWindow fadePopup = new PopupWindow(popupWindow, screenWidth, screenHeight, false);
        fadePopup.showAtLocation(popupWindow, Gravity.NO_GRAVITY, 0, 0);

        final Button cancel = (Button) popupWindow.findViewById(R.id.CE_button_cancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fadePopup.dismiss();
            }
        });

        fadePopup.setFocusable(true);
        fadePopup.update();
*/

    }

}

Ce sont toutes les bibliothèques que j'ai ajoutées.

  compile 'com.squareup.retrofit2:converter-gson:2.1.0'
  compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
  compile 'io.reactivex:rxandroid:1.0.1'

  compile 'com.android.support:appcompat-v7:24.0.0-beta1'
  compile 'com.android.support:design:24.0.0-beta1'

  compile files('src/main/java/com/alamkanak/weekview/sample/volley.jar')
  compile 'com.android.support.constraint:constraint-layout:1.0.2'

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X