Android:XmlPullParserFactory。newInstance说找不到符号类

时间:2021-05-28 15:19:31

I'm trying to parse XML document using XmlPullParser but I've the following error

我尝试使用XmlPullParser解析XML文档,但我有以下错误。

Gradle: error: cannot find symbol class newInstance

错误:无法找到符号类newInstance

Creating XmlPullParserFactory

创建XmlPullParserFactory

XmlPullParserFactory ppf = new XmlPullParserFactory.newInstance();

XmlPullParserFactory ppf =新的XmlPullParserFactory. newinstance ();

How to configure Gradle to discover XmlPullParser properly?

如何配置Gradle来正确发现XmlPullParser ?

2 个解决方案

#1


6  

XmlPullParserFactory ppf = new XmlPullParserFactory.newInstance();

should be

应该是

XmlPullParserFactory ppf = XmlPullParserFactory.newInstance();

You must use new to invoke constructors, not static methods.

您必须使用new来调用构造函数,而不是静态方法。

#2


1  

You just have to remove the new keyword from your statement that's all.

您只需从语句中删除new关键字即可。

Because new is basically used to create object via calling the constructor of the your class and in this case we are creating a new instance of PullParserFactory using newInstance() method and we are calling this method so we do not need to use this.

因为new主要用于通过调用类的构造函数来创建对象,在本例中,我们使用newInstance()方法创建了一个新的PullParserFactory实例,我们调用了这个方法,所以不需要使用它。

And The factory will always return instances of KXmlParser and KXmlSerializer.

而且工厂总是返回KXmlParser和KXmlSerializer的实例。

#1


6  

XmlPullParserFactory ppf = new XmlPullParserFactory.newInstance();

should be

应该是

XmlPullParserFactory ppf = XmlPullParserFactory.newInstance();

You must use new to invoke constructors, not static methods.

您必须使用new来调用构造函数,而不是静态方法。

#2


1  

You just have to remove the new keyword from your statement that's all.

您只需从语句中删除new关键字即可。

Because new is basically used to create object via calling the constructor of the your class and in this case we are creating a new instance of PullParserFactory using newInstance() method and we are calling this method so we do not need to use this.

因为new主要用于通过调用类的构造函数来创建对象,在本例中,我们使用newInstance()方法创建了一个新的PullParserFactory实例,我们调用了这个方法,所以不需要使用它。

And The factory will always return instances of KXmlParser and KXmlSerializer.

而且工厂总是返回KXmlParser和KXmlSerializer的实例。