Reputation: 255
I am learning android and i would like check data by function Log.
Now i have code: http://cecs.wright.edu/~pmateti/Courses/436/Lectures/20110920/SimpleNetworking/src/com/androidbook/simplenetworking/FlickrActivity2.java.txt
This working ok, Log.i also, but i would like add own Log:
XmlPullParserFactory parserCreator = XmlPullParserFactory.newInstance();
XmlPullParser parser = parserCreator.newPullParser();
parser.setInput(text.openStream(), null);
status.setText("Parsing...");
int parserEvent = parser.getEventType();
while (parserEvent != XmlPullParser.END_DOCUMENT) {
//START MY CODE!!!
XmlPullParser.START_TAG
Log.i("Test1", parserEvent);
Log.i("Test2", XmlPullParser.START_TAG);
//END MY CODE!!!
switch(parserEvent) {
case XmlPullParser.START_TAG:
String tag = parser.getName();
if (tag.compareTo("link") == 0) {
String relType = parser.getAttributeValue(null, "rel");
if (relType.compareTo("enclosure") == 0 ) {
String encType = parser.getAttributeValue(null, "type");
if (encType.startsWith("image/")) {
String imageSrc = parser.getAttributeValue(null, "href");
Log.i("Net", "image source = " + imageSrc);
}
}
}
break;
}
parserEvent = parser.next();
}
status.setText("Done...");
but i have error:
The method i(String, String) in the type Log is not applicable for the arguments (String, int)
Why the second parameter is int? How can i check value with Log same as in JavaScript console.log?
Upvotes: 3
Views: 148
Reputation: 28541
Java, unlike Javascript, is a strongly typed language. The compiler checks that you are providing variables of the expected type to a method. In this case, the method Log.i
takes two strings as arguments.
You are trying to print an int and thus need to convert it to a string. This can be done like that for instance:
Log.i("Test2", Integer.toString(XmlPullParser.START_TAG));
Before diving too deep into Android, maybe you should follow a short introduction to the Java language to get the basics right. This will save you time later on.
Upvotes: 5