简体   繁体   中英

CollapsingTitleLayout has no zero argument constructor

I keep getting this error when trying to build my project taken from github. ' ' has no zero argument constructor. Gradle build finished with 1 error. Is something with the build gradle. Im just trying to solve a project and im not a android or java programmer, so please bear with me. Any help would be appreciated.

I keep getting this uggly message from logcat--

class se.mpeople.collapsingtitlelayoutmpeople.CollapsingTitleLayout has no zero argument constructor 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2999)

Here is part of the CollapsingTitleLayout.java file.

    package se.mpeople.collapsingtitlelayoutmpeople;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.Toolbar;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.widget.FrameLayout;



public class CollapsingTitleLayout extends FrameLayout {


    // Pre-JB-MR2 doesn't support HW accelerated canvas scaled text so we will workaround it
    // by using our own texture
    private static final boolean USE_SCALING_TEXTURE = Build.VERSION.SDK_INT < 18;

    private static final boolean DEBUG_DRAW = false;
    private static final Paint DEBUG_DRAW_PAINT;
    static {
        DEBUG_DRAW_PAINT = DEBUG_DRAW ? new Paint() : null;
        if (DEBUG_DRAW_PAINT != null) {
            DEBUG_DRAW_PAINT.setAntiAlias(true);
            DEBUG_DRAW_PAINT.setColor(Color.MAGENTA);
        }
    }

    private Toolbar mToolbar;
    private View mDummyView;

    private float mScrollOffset;

    private final Rect mToolbarContentBounds;

    private float mExpandedMarginLeft;
    private float mExpandedMarginRight;
    private float mExpandedMarginBottom;

    private int mRequestedExpandedTitleTextSize;
    private int mExpandedTitleTextSize;
    private int mCollapsedTitleTextSize;

    private float mExpandedTop;
    private float mCollapsedTop;

    private String mTitle;
    private String mTitleToDraw;
    private boolean mUseTexture;
    private Bitmap mExpandedTitleTexture;

    private float mTextLeft;
    private float mTextRight;
    private float mTextTop;

    private float mScale;

    private final TextPaint mTextPaint;
    private Paint mTexturePaint;

    private Interpolator mTextSizeInterpolator;

    public CollapsingTitleLayout(Context context) {
        this(context, null);
    }

    public CollapsingTitleLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

Activity_collapsing_title_layout.xml

?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_height="match_parent"
             android:layout_width="match_parent">

    <!-- Your content, maybe a ListView? -->

    <app.se.mpeople.collapsingtitlelayout.CollapsingTitleLayout
        android:id="@+id/backdrop_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
        app:expandedTextSize="40dp"
        app:expandedMargin="16dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent" />

    </app.se.mpeople.collapsingtitlelayout.CollapsingTitleLayout>

</FrameLayout>

ANDROID Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest package="se.mpeople.collapsingtitlelayoutmpeople"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".CollapsingTitleLayout">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

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

</manifest>

attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <declare-styleable name="CollapsingTitleLayout">
        <attr name="expandedMargin" format="reference|dimension" />
        <attr name="expandedMarginStart" format="reference|dimension" />
        <attr name="expandedMarginBottom" format="reference|dimension" />
        <attr name="expandedMarginEnd" format="reference|dimension" />
        <attr name="expandedTextSize" format="reference|dimension" />
        <attr name="collapsedTextSize" format="reference|dimension" />
        <attr name="android:textAppearance" />
        <attr name="textSizeInterpolator" format="reference" />
    </declare-styleable>

    <declare-styleable name="CollapsingTextAppearance">
        <attr name="android:textSize" />
        <attr name="android:textColor" />
    </declare-styleable>

</resources>

Gradle

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "se.mpeople.collapsingtitlelayoutmpeople"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'
    compile 'com.android.support:cardview-v7:23.2.0'
    compile 'com.android.support:palette-v7:23.2.0'

}

I believe it's trying to tell you to add a no argument constructor.

public CollapsingTitleLayout(){}

The object has other constructors but it doesn't have the no-value constructor above.

    public CollapsingTitleLayout(Context context) {
    this(context, null);
}

public CollapsingTitleLayout(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
}

public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

It seems that your parent class has no default constructor so you can't have an implicit one.

You have to create at least one constructor that calls one of the 'super(...)' possibilities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM