butterknife 8.8.1 错误 ';'期待
butterknife 8.8.1 error ';' excpect
我遇到了一个错误';' expectd
,并检查了事件日志中的日志记录Executing tasks: [:app:assembleDebug]
,最后它向我显示了Gradle build finished with 1 error(s)
。
我不知道如何解决这个问题,请帮助我。谢谢~
错误信息
[Messages window]
Error:(56, 53) Error: ';' expectd
Information:BUILD FAILED in 0s
Information:1 error
Information:0 warnings
Information:See complete output in console
[事件日志window]
17:14 Executing tasks: [:app:assembleDebug]
17:15 Gradle build finished with 1 error(s) in 506ms
**全球build.gradle**
buildscript {
repositories {
google()
jcenter()
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
**模块build.gradle**
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.test.www"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//butterknife
javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//butterknife
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
**布局activity_main.xml**
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.www.activity.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp">
<Button
android:id="@+id/btnOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Open"
android:layout_weight="1"
android:layout_marginLeft="10dp"/>
<Button
android:id="@+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Close"
android:layout_weight="1"
android:layout_marginRight="10dp" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
** 主要活动 **
package com.test.www.activity;
import android.arch.lifecycle.OnLifecycleEvent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.yanhui.www.switchlamp.R;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
private static final String IDENTITY_TAG = "MainActivity";
@BindView(R.id.btnOpen)
Button btnOpen;
@BindView(R.id.btnClose)
Button btnClose;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
@OnClick (R.id.btnOpen) public void startSomething() {
Toast.makeText(MainActivity.this, "startSomething", Toast.LENGTH_SHORT).show();
}
@OnClick (R.id.btnClose) public void endSomething() {
Toast.makeText(MainActivity.this, "endSomething", Toast.LENGTH_SHORT).show();
}
}
}
无法通过 assembleDebug,显示错误 ';' expected
。 @BindView 还行,@OnClick 犯了个错误,我没找到解决方法
您在 MainActivity
的 onCreate()
回调中定义了函数。尝试像这样将它们移出:
public class MainActivity extends AppCompatActivity {
private static final String IDENTITY_TAG = "MainActivity";
@BindView(R.id.btnOpen)
Button btnOpen;
@BindView(R.id.btnClose)
Button btnClose;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
@OnClick(R.id.btnOpen)
public void startSomething() {
Toast.makeText(MainActivity.this, "startSomething", Toast.LENGTH_SHORT).show();
}
@OnClick(R.id.btnClose)
public void endSomething() {
Toast.makeText(MainActivity.this, "endSomething", Toast.LENGTH_SHORT).show();
}
}
我遇到了一个错误';' expectd
,并检查了事件日志中的日志记录Executing tasks: [:app:assembleDebug]
,最后它向我显示了Gradle build finished with 1 error(s)
。
我不知道如何解决这个问题,请帮助我。谢谢~
错误信息
[Messages window]
Error:(56, 53) Error: ';' expectd
Information:BUILD FAILED in 0s
Information:1 error
Information:0 warnings
Information:See complete output in console
[事件日志window]
17:14 Executing tasks: [:app:assembleDebug]
17:15 Gradle build finished with 1 error(s) in 506ms
**全球build.gradle**
buildscript {
repositories {
google()
jcenter()
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
**模块build.gradle**
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.test.www"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//butterknife
javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//butterknife
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
**布局activity_main.xml**
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.www.activity.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp">
<Button
android:id="@+id/btnOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Open"
android:layout_weight="1"
android:layout_marginLeft="10dp"/>
<Button
android:id="@+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Close"
android:layout_weight="1"
android:layout_marginRight="10dp" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
** 主要活动 **
package com.test.www.activity;
import android.arch.lifecycle.OnLifecycleEvent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.yanhui.www.switchlamp.R;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
private static final String IDENTITY_TAG = "MainActivity";
@BindView(R.id.btnOpen)
Button btnOpen;
@BindView(R.id.btnClose)
Button btnClose;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
@OnClick (R.id.btnOpen) public void startSomething() {
Toast.makeText(MainActivity.this, "startSomething", Toast.LENGTH_SHORT).show();
}
@OnClick (R.id.btnClose) public void endSomething() {
Toast.makeText(MainActivity.this, "endSomething", Toast.LENGTH_SHORT).show();
}
}
}
无法通过 assembleDebug,显示错误 ';' expected
。 @BindView 还行,@OnClick 犯了个错误,我没找到解决方法
您在 MainActivity
的 onCreate()
回调中定义了函数。尝试像这样将它们移出:
public class MainActivity extends AppCompatActivity {
private static final String IDENTITY_TAG = "MainActivity";
@BindView(R.id.btnOpen)
Button btnOpen;
@BindView(R.id.btnClose)
Button btnClose;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
@OnClick(R.id.btnOpen)
public void startSomething() {
Toast.makeText(MainActivity.this, "startSomething", Toast.LENGTH_SHORT).show();
}
@OnClick(R.id.btnClose)
public void endSomething() {
Toast.makeText(MainActivity.this, "endSomething", Toast.LENGTH_SHORT).show();
}
}