MY mENU


Showing posts with label Errors. Show all posts
Showing posts with label Errors. Show all posts

Thursday, 2 May 2013

Error: Your content must have a ListView whose id attribute is android.R.id.list


When you are creating A ListVIew Item in Android and want to display your selected item on Toast message. When you are running that app and if you get an error like below.

"Your content must have a ListView whose id attribute is android.R.id.list"

For the above problem answer is.

If your are using ListActivity then you must have ListView in your xml of layout and must be id of 

ListView is android.R.id.list

So must add listview in your layout like below code
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/android:list" />

In The Java Code it’l be get like this.

lv = (ListView) findViewById(android.R.id.list);

Sunday, 23 September 2012

unclosed string literal


String literals must be enclosed in quotation marks.1 This error occurs if you fail to
terminate the literal with quotation marks. Fortunately, the syntax of JAVA requires
that a string literal appear entirely on one line so the error message appears on the
same line as the mistake. If you need a string literal that is longer than a single line,
create two or more literals and concatenate them with +:

String longString = "This is first half of a long string " + "and this is the second half.";

ECLIPSE: String literal is not properly closed by a double-quote. In ECLIPSE you
can write a string literal of arbitrary length and the environment will break the string
and insert the + automatically.
1A literal is a source-code representation of a value; most literals are of primitive types like int or char, but there are also literals of type String and the literal null of any reference type.

Saturday, 22 September 2012

Expected Error in Java


. . . expected
The syntax of JAVA is very specific about the required punctuation. This error occurs,
for example, if you forget a semicolon at the end of a statement or don’t balance parentheses:
if (i > j // Error, unbalanced parentheses
max = i // Error, missing semicolon
else
max = j;
Unfortunately, this syntax error is not necessarily caught precisely at the point of the
mistake so you must carefully check the preceding characters in the line or even in a
previous line in order to find the problem.
ECLIPSE:
Syntax error, insert ") Statement" to complete IfStatement.
Syntax error, insert ";" to complete Statement
ECLIPSE is more informative as to the precise syntax error encountered.

Friday, 21 September 2012

Syntax Error in Java


Frequently, a single small mistake will cause the compiler to issue a cascade of messages. For example, in the following code, we forgot to write the closing brace of the method f:
class MyClass {
void f() {
int n = 10;
// Error, closing brace is missing
void g() {
int m = 20;
}
}
An attempt to compile the program results in three error messages:

MyClass.java:5: illegal start of expression
void g() {
^
MyClass.java:8: ’;’ expected
}
^
MyClass.java:9: ’}’ expected
^
Do not invest any effort in trying to fix multiple error messages! Concentrate on fixing the first error and then recompile. ECLIPSE is much better at diagnosing this error and produces only one message: Syntax error, insert "}" to complete MethodBody.