Some how I broke butterknife - android

Some how I managed to break something in my eclipse setup that is breaking butterknife for any new views I try to inject. The "old" views still seem to be fine.
This one works:
#InjectView(R.id.sign_out_button)
Button signOutButton;
this one does not
#InjectView(R.id.map_button)
Button mapButton;
When I add the new field I get this in the generated java file under .apt_generated
view = finder.findRequiredView(source, 0, "field 'mapButton'");
vs this for the "old" field
view = finder.findRequiredView(source, 2131165280, "field 'signOutButton' and method
note the 0 vs 2131165280
The error message I get is map_button cannot be resolved or is not a field
And indeed if I look under gen/my_package/R.java there is no entry for map_button, but there is one for sign_out_button.
I have tried cleaning the project and restarting the ide many times. Anyone have any ideas as to what might be wrong?
Solved
Turns out this was a really dumb mistake. I had not added the button to the xml file. Butterknife helps with the code injection but you still need to add the button to the layout file.

Related

wamy project's R.java file is causing and error and when ever i fix it eclipse removes the changes i made

this is causing the error
public static final class id {
public static final int timeToSend=0x7f080021;
public static final int timeToSend,=0x7f080023;
}
whenever I remove the second and save the file eclipse changes it back. I tried changing it while eclipse is not running and yet when I opened eclipse it changed the file back. I don't have any duplicates in layout to cause the problem. I tried cleaning the project and it didn't work.
turns out I wrote android:layout_alignBottom="#+id/timeToSend," instead of android:layout_alignBottom="#+id/timeToSend" that's why it nade a duplicate with the comma. sorry for the trouble
Maybe it's because you have an XML element with the android:id="#+id/timeToSend," ?
Android ID's cannot have any special characters in them. So android:id="#+id/timeToSend, would be wrong due to the fact that it has a comma. All you have to do is find that ID and rename it.
It's not recommended to edit the R.java file because it generates itself based on all the ID's you have created. The only way to edit it is to get rid of the ID's that you have declared in XML, otherwise, every time you clean the project, they regenerate.
Something that I always try when R.java is giving me problems is rebuilding the project.
You should be able to find the option under Project and then Clean.
That's only if rebuilding it hasn't worked.
Good luck and I hope this helps!

Tip Calculator App Issues

I've been working on the 'Tip Calculator' app for Android and I have a couple of questions.
I'm supposed to (in the process of creating the GUI) use some EditTexts to allow the user to enter the bill amount and read the calculated total bill. In the version I have, there is no EditText anywhere in the Visual Layout Editor, only CheckText. Are these the same?
Whenever I try to edit the Java code for the app, as per the book I have, I keep getting the message:
Thus and such is never used
For example, with
private static final String BILL_TOTAL = "BILL_TOTAL';
or anything from the import Android list, other than the one referring to a bundle. I'm Not sure how to resolve this. I have some experience with C and C++, but Java is new to me.
The warning that tells you that a variable or method or import is not used can be ignored, especially if you just haven't gotten to using it yet. It's a warning and not an error, so your app should compile regardless.
I don't know what you're using to build your layout (eclipse? I use Intellij Idea), but to add an EditText, you can edit the layout file by hand. Add a line similar to:
<EditText android:id="#+id/myEditText android:width="FILL_PARENT" android:height="WRAP_CONTENT"/>
As a general rule, I like to edit these things by hand. Then, when something breaks or doesn't work as I expect it to, I have some grasp of what's in there, and so I can usually fix it. The value gained by learning how to create a layout by hand easily offsets the value of the time that you'll save.
Good luck.

Unable to find components using the findViewById method in Android

I'm attempting to create an Activity and unfortunately every time I want to grab one of my XML components it gives me a RunTimeException (NullPointer).
Anytime I use code such as:
TextView tv = (TextView) findViewById(R.id.myView); //I get the exception
The same happens for any components I attempt to find with that method. I can't quite figure out why. I know it isn't due to the Activity not being in the Manifest because it's the only Activity in the test app I made. (The one set up by default).
Oddly I can still use setContentView(R.id.myView). It just doesn't seem to want to find anything when using the findViewById method.
Info that might be of use:
I am currently using NetBeans as my IDE.
I have done multiple 'clean and builds' as was suggested in another question. Android -findViewById question
Has anyone run into this issue before? If so, what was the solution?
If need be, I can provide sample code of when this is happening.
Don't pass in a view ID to setContentView, pass in a layout resource ID:
setContentView(R.layout.layout_name);
If you still have problems, post your layout file.
It is very sure that you R.java is not properly generated.
Delete R.Java in netbeans IDE and Re-build the project.
Hope it resolves your query.

ImageView Id not being created in R file

Quite new to Android dev so there is a good chance I made a dumb mistake. But for some reason I cant reference a ImageView I created in a second Activity using the findViewById method. When I went and checked the 'R' file I could see that an Id was not created for all 3 ImageViews I am trying to reference that is in the same activity.
What could the possible reason be for this? Could it be something to do with data I put in the Manifest file? My java class? Because my syntax for the containing activity is 100%....
I'm suspecting is has something to do with the new activity/manifest. How can all the ImageViews in the same Activity not be referenced...?
Clean the project and try again. To clean you project Project -> Clean select your project and clean. Some time it happens while developing the project. I've faced many times.

How can I get Android to resolve XML resources?

I'm doing Example 3 on the Notepad tutorial on developer.android.com.
It's time to run my code, but I can't even compile, because I have errors on lines that call R.layout.*something* or R.string.*something*. Every error is of the type...
"something cannot be resolved or is not a field."
...which signals to me that maybe I named something wrong or forgot to name it in the XML. So I check my XML files and do a little cleanup. Everything seems to be normal. No red Xs.
I go back to the class, where I see what looks odd to me. In two separate lines that call to two separate elements in the same layout file, one yields an error and one doesn't:
mTitleText = (EditText) findViewById(R.id.title); // no error
mBodyText = (EditText) findViewById(R.id.body); // error: "body cannot be resolved or is not a field"
Again, Eclipse isn't showing me any errors on the XML file:
What might I have done wrong that some of the resources are resolving in the code and some aren't? Is this something Eclipse can sort out, similar to Project -> Clean...?
If it makes any difference, I picked Android 2.1 as a build target. And I am importing android.R.
Thanks in advance for any help.
try removing the R import lines altogether
Instead of importing android.R try importing com.android.demo.notepad3.R

Categories

Resources