简体   繁体   中英

@InjectView doesn't works on Android Studio

I'm building an Android app using Android Studio. I decided to use an external library to draw a custom progress bar.

I've a problem with ButterKnife injection's library. Pratically, when I launch the app, I receive this exception:

Process: com.robertot.timereport, PID: 16449
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.robertot.timereport/com.robertot.timereport.pages.MainActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.robertot.timereport/com.robertot.timereport.pages.MainActivity}: java.lang.RuntimeException: Unable to inject views for com.robertot.timereport.pages.MainActivity@64b1fd48
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)

Instead, this is my code:

public class MainActivity extends FragmentActivity
{

    @InjectView(R.id.google_progress)
    GoogleProgressBar googleProgressBar;

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

        ButterKnife.inject(this);   // CRASH HERE

        //....
    }

}

What am I doing wrong?

Check if your @InjectView s has correct type.

I've used ImageView instead of LinearLayout .

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