Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Android Lists and Adapters (2015) Updating the Data Model Finishing the Data Model

Thomas Williams
Thomas Williams
9,090 Points

Struggling to put MainActivity into a new ui package without it causing errors.

I created a new sub package called ui, then as instructed I tried to drag and drop the classes MainActivity and AlertDialogFragment into it as instructed, it then asked do i wish to refactor so I clicked yes and then it came up with the following;

problems detected: Field MainActivity.mTemperatureLabel will be inaccessible from constructor MainActivity_ViewBinding.MainActivity_ViewBinding(T, View) Field MainActivity.mTemperatureLabel will be inaccessible from method MainActivity_ViewBinding.unbind() Field MainActivity.mTimeLabel will be inaccessible from constructor MainActivity_ViewBinding.MainActivity_ViewBinding(T, View) Field MainActivity.mTimeLabel will be inaccessible from method MainActivity_ViewBinding.unbind() Field MainActivity.mIconImageView will be inaccessible from constructor MainActivity_ViewBinding.MainActivity_ViewBinding(T, View) Field MainActivity.mIconImageView will be inaccessible from method MainActivity_ViewBinding.unbind() Field MainActivity.mHumidityValue will be inaccessible from constructor MainActivity_ViewBinding.MainActivity_ViewBinding(T, View) Field MainActivity.mHumidityValue will be inaccessible from method MainActivity_ViewBinding.unbind() Field MainActivity.mSummaryLabel will be inaccessible from constructor MainActivity_ViewBinding.MainActivity_ViewBinding(T, View) Field MainActivity.mSummaryLabel will be inaccessible from method MainActivity_ViewBinding.unbind() Field MainActivity.mPrecipValue will be inaccessible from constructor MainActivity_ViewBinding.MainActivity_ViewBinding(T, View) Field MainActivity.mPrecipValue will be inaccessible from method MainActivity_ViewBinding.unbind()

I then changed the package address in each class by adding .ui which allowed me to refactor the classes without the problems dialog appearing, however errors became highlighted in the code and on trying to run the app the following error messages appeared:

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug] /Users/GroupPay/AndroidStudioProjects/Stormy/app/src/main/java/grouppay/com/stormy/ui/MainActivity.java Error:(45, 16) error: package R does not exist Error:(46, 16) error: package R does not exist Error:(47, 16) error: package R does not exist Error:(48, 16) error: package R does not exist Error:(49, 16) error: package R does not exist Error:(50, 16) error: package R does not exist Error:(45, 40) error: Unable to parse @BindView binding.

java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation element public abstract int butterknife.BindView.value() (Found data of type R.id) at com.sun.tools.javac.model.AnnotationProxyMaker$ValueVisitor$1AnnotationTypeMismatchExceptionProxy.generateException(AnnotationProxyMaker.java:269) at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:84) at com.sun.proxy.$Proxy81.value(Unknown Source) at butterknife.compiler.ButterKnifeProcessor.parseBindView(ButterKnifeProcessor.java:402) at butterknife.compiler.ButterKnifeProcessor.findAndParseTargets(ButterKnifeProcessor.java:275) at butterknife.compiler.ButterKnifeProcessor.process(ButterKnifeProcessor.java:157) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794) at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705) at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91) at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035) at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856) at com.sun.tools.javac.main.Main.compile(Main.java:523) at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129) at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138) at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:46) at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:33) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:104) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:53) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38) at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35) at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25) at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:163) at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:145) at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:93) at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at etc...........................................) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Information:BUILD FAILED Information:Total time: 2.669 secs Information:12 errors Information:0 warnings Information:See complete output in console

In the android manifest I noticed the android:name=".MainActivity" was red so copying someone in the forum I changed it to .ui.MainActivity which removed the highlight. Now the only errors i can see highlighted are R. in the butterknife code eg. @BindView(R.id.timeLabel) TextView mTimeLabel; Saying cannot resolve symbol 'R' I have tried cleaning and rebuilding numerous times throughout trying to fix this but it doesn't seem to help. Almost all of my most frustrating time absorbing problems on this track seem to come from using butterknife, is it really worth it!?

2 Answers

Seth Kroger
Seth Kroger
56,407 Points

The errors are being caused by the current version of ButterKnife. ButterKnife works by code generation, creating a within the same package automatically when you build. You probably should have done the automatic refactoring, then clean/rebuild the project so ButterKnife can regenerate it's files in the new package. Since you've done a manual move, check the manifest and build.gradle files, for references to MainActivity as well as code files of yours that import MainActivity and make sure they point to the new package, then a clean/rebuild should hopefully fix the other issues. Or you might be able to revert the changes you've made if they are still in local history or you're using git version control, and try refactoring again.

Thomas Williams
Thomas Williams
9,090 Points

Thank you Seth, in line with your advice I refactored the MainActivity out of ui package to main package and then refactored it back into the ui package using the automatic refactoring, I thought I had already tried automatically refactoring it to the ui package but clearly not as this time it has worked without any errors showing, once again many thanks.

Suleyman Orazgulyyev
PLUS
Suleyman Orazgulyyev
Courses Plus Student 5,798 Points

Just in case anyone will be struggling with that question, just cut out all the butterknife code you have, move the classes you want to the sub-packages and then just paste it back.

Tomasz Bagiński
Tomasz Bagiński
3,153 Points

Simple comment line with @BindView and next step is move MainActivity to UI package and next uncomment @BindView :)