本文介绍了Android的工作室:整合奶油刀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现到我的Andr​​oid Studio项目。

然而,当我这样做,我得到 @InjectView 错误无法解析符号InjectView。

我有没有实现奶油刀sucsessfully?

活动code:

 包com.example.rodf.testapp;进口android.support.v7.app.ActionBarActivity;
进口android.os.Bundle;
进口android.view.Menu;
进口android.view.MenuItem;
公共类MainActivity扩展ActionBarActivity {    @InjectView(R.id.tvHelloWorld)的TextView TV1;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);    }
}

布局:

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s的android:layout_width =match_parent
    机器人:layout_height =match_parent机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    机器人:paddingBottom会=@扪/ activity_vertical_margin工具:上下文=MainActivity。>    <的TextView
        机器人:ID =@ + ID / tvHelloWorld
        机器人:文字=@字符串/参考hello world的android:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT/>< / RelativeLayout的>

文件的gradle:

 应用插件:'com.android.application安卓{
    compileSdkVersion 21
    buildToolsVersion21.1.2    defaultConfig {
        的applicationIDcom.example.rodf.testapp
        15的minSdkVersion
        targetSdkVersion 21
        版本code 1
        的versionName1.0
    }
    buildTypes {
        发布 {
            minifyEnabled假
            proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
        }
    }
}依赖{
    编译文件树(导演:'库',包括:['的* .jar'])
    编译com.android.support:appcompat-v7:21.0.3
    //添加黄油刀库
    编译com.jakewharton:奶油刀:6.0.0
}


解决方案

我觉得你的code是不错的,


  1. 尝试通过点击来同步gradle这个


  2. 尝试去文件 - 缓存无效并重新启动您的Andr​​oid工作室


另外,别忘了把 ButterKnife.inject(本); 的onCreate()

I am trying to implement Butterknife into my android studio project.

However when I do so I get an error on @InjectView "cannot resolve symbol InjectView".

Have I not implemented Butterknife sucsessfully?

Activity code:

package com.example.rodf.testapp;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

    @InjectView(R.id.tvHelloWorld) TextView tv1;

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



    }
}

layout:

<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" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

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



</RelativeLayout>

gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.rodf.testapp"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    //adding the butter knife library
    compile 'com.jakewharton:butterknife:6.0.0'
}
解决方案

I think your code is good,

  1. Try to sync your gradle by click

  2. Try to go File -- invalidate Caches and restart your Android studio.

Also, don't forget put ButterKnife.inject(this); in onCreate()

这篇关于Android的工作室:整合奶油刀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 21:55