As i'm new to android, i really couldn't understand the errors or execptions shown in the android DDMS,I'm using Eclipse ..
Can anyone please share some very frequent exceptions that appear in DDMS and how to handle them......
We should explain exceptions here for you? Maybe you should try to read the name of the exception... most of them are named understandable. And the very first thing you should do to learn about exceptions is to read their documentation: the very famous one for example: http://developer.android.com/reference/java/lang/NullPointerException.html
If that didnt help, try to search with google or here on StackOverflow...
If you opened any xml files, this error shoud occur. Close all xml files of your application.
I'm not certain but I'm also having the same problem. I believe it occurs when you try to call something that is out of context. For example if you tried to call
TextView myTextView= (TextView)findViewById(R.id.myTextView);
when you had set a contentView as something that did not contain 'myTextView'
Hope this helps!
I think this type of error occurred when you have edited the .xml file and rebuild the project.
If you have opened any xml files, save all the .xml files and Close all xml files of your application.
and run the project. this way i run my application when this type of error occurred.
Related
I have a problem with my layout text code. Instead of displaying the code I wrote, it shows a bunch of weird symbols like :
"IHDR 0 0 �1
I thought this issue had to do with the file encoding, but I changed the global encoding to UTF-8 and still doesn´t show the code I wrote.
All suggestions are welcome. Thanks in advance.
Late answer but it will help others:
You need to delete catches folder located in:
C:\Users\user\.AndroidStudio3.5\system\caches
Make sure android studio is closed before you delete, then after deletion you can launch it and it creates a new catch folder that solves your problem,
I learn android with sample apps from textbook. In the given sample source R.string.something is recognized:
However, in my own EXACT source code, same R.strings are not recognized- highlighted as errors:
Does anyone know how to fix it?
I've had this many time with eclipse, and it was not a setup / code problem on my side. Generally, cleaning, rebuilding and sometime even stopping and restarting eclipse solved it. And yes, it's a pain in the neck ...
Try a clean of your project, if that does nothing then click on the problems tab and see if there's any build related issues, you may be missing a required jar or something!
These are following reason possible.
1-: You import android.R;
2-: Any error in xml files.
3-: Please check you String.xml file may be any error or declare a string more then two time.
I assume you are new to Android.
If so, there are two ways of using text strings in Buttons, textviews and so on:
1) Hardcoded string - you put the text you want in quotation marks (""), for example:
yourTextview.setText("Hardcoded string");
2) You can call the text from your String resources (res/values/strings.xml).
That is a much better approach seeing is is easier to translate, make changes and so on.
In your strings.xml file you can create all your string values, and call them from there.
Like in you example, if in your strings.xml file you have for example:
<string name="delete">This is String resource</string>
you can then call the string from there, like so :
yourTextview.setText(R.string.delete);
Hope this helps!
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.
I am getting error with the generated java file. But the code is fine and good . Can any one give suggestion.
thanks in advance.
Based on your image it appears that you are getting an error with the element with id of "enter", try changing the id of that element to something more descriptive and the error might go away.
You don't say which error you are getting. Usually you can resolve errors in R.java by removing it, and letting Eclipse regenerate it. If you still are getting the same error, you can try to rename the controls with the offending id.
If you wish further assistance, you need to say which error you are getting.
I'm working through a book samples programs and i get the same problem whether I create and type the code or whether i download the code already typed, so i'm thinking it's a setup problem.
I get this error in each each class:
setContentView(R.layout.menu) where the "R" is underlined in red and the code won't compile. If i add import android.r like "QuickFix" suggests, the red line goes away from the "R", but then the red line appears under "menu" (in this example). The same behavior occurs in each of the 5 classes that make up the project.
I do have matching layouts for "menu" etc. And (to the best of my knowledge) I registered them as Application Nodes in the manifest file.
It's driving me nuts. Thanks for any suggestions.
You are not supposed to import android.R as it won't resolve your resources. Just remove that import and try to compile again.
If you are working off a tutorial then also check to have the same resources as in the tutorial and also if you decide to name thing different then keep that in mind an reference them by your names.
The R class is generated by Android and contains IDs for all resources in your res folder. Go to your AndroidManifest and locate the package= attribute on manifest. R is in this namespace. So if the namespace is com.yourpackage.blah, you'll want to import com.yourpackage.blah.R;
The problem was that for some reason Eclipse was not autogenerating the gen/R.java file. I don't know why. One time it did generate the file, and a after Project..Clean and Build All everything resolved. Thanks for the input.
Also make sure your file names under res, eg drawables, are OK. I had a file name with capital letter and that prevented the creation of R with the same reference errors that you got. I did not check the error messages and it took me a good 10-20 mns to find this out.
Sometimes this happens to me.
It usually happens that I have been working with some xml element, and before clicking to a java document to hit "run" i just hit "run" while on the xml. I don't really know what happens when you "run" an xml, but it makes this horible file called some_xml_name.out.xml.
DELETE THIS FILE!
This file is the reason why you get so many R related errors, since the Resources library is never really created, or something like that.
That is my advice, without actually seeing the error you're getting in the console.