How to use Android magazine

I am studying Android and I would like to check the data on the Log function.

Now I have the code: http://cecs.wright.edu/~pmateti/Courses/436/Lectures/20110920/SimpleNetworking/src/com/androidbook/simplenetworking/FlickrActivity2.java.txt

This works fine, Log.i also, but I would like to add my 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 got error:

Method i (String, String) in type Log is not applicable for Arguments (String, int)

Why is the second parameter an int? How can I check the value using Log in the same way as in JavaScript console.log?

+3


source to share


1 answer


Java, unlike Javascript, is a strongly typed language. The compiler verifies that you are supplying variables of the expected type to the method. In this case, the method Log.i

takes two strings as arguments.

You are trying to print an int and therefore must convert it to a string. This can be done as follows:



Log.i("Test2", Integer.toString(XmlPullParser.START_TAG));

      

Before diving deep into Android, you should probably follow a short introduction to the Java language to get the basics right. This will save you time later.

+5


source







All Articles