Quantcast

index() method of Attribute class throwing java.lang.NullPointerException exception

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

index() method of Attribute class throwing java.lang.NullPointerException exception

pranay73
I am using weka api for a programming task on a given dataset. I have stored the attribute names of a dataset in a ArrayList. I want to randomly pick a attribute name from the Arraylist and want to find it's index value.
I wrote below code
String att =(String) attributenamesofarule.get(0);//working fine
int index = data.attribute(att).index(); // throwing error  java.lang.NullPointerException
where as when i wrote
data.attribute("Attribute1").index();// working fine Attribute1 is name of a attribute in my data set

I am not getting the problem.
Please help me it'e urgent

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: index() method of Attribute class throwing java.lang.NullPointerException exception

Eibe Frank-3
It looks like attributenamesofarule.get(0) doesn't actually exist as an attribute name in data. The attribute(String) method in Instances returns null if the attribute name cannot be found.

It's also possible that data is null.

Cheers,
Eibe

On Sat, Jan 7, 2017 at 2:46 PM, pranay73 <[hidden email]> wrote:
I am using weka api for a programming task on a given dataset. I have stored
the attribute names of a dataset in a ArrayList. I want to randomly pick a
attribute name from the Arraylist and want to find it's index value.
I wrote below code
String att =(String) attributenamesofarule.get(0);//working fine
int index = data.attribute(att).index(); // throwing error
java.lang.NullPointerException
where as when i wrote
data.attribute("Attribute1").index();// working fine Attribute1 is name of a
attribute in my data set

I am not getting the problem.
Please help me it'e urgent

Thanks



--
View this message in context: http://weka.8497.n7.nabble.com/index-method-of-Attribute-class-throwing-java-lang-NullPointerException-exception-tp39132.html
Sent from the WEKA mailing list archive at Nabble.com.
_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html


_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: index() method of Attribute class throwing java.lang.NullPointerException exception

pranay73
Hi,
The data is not null and attribute name exists in attributenamesofarule.get(0). I am just taking the attributes names from the weka generated rules on my data set. When I am executing the function by providing the attribute name in a static way it is getting executed.

Thanks

 
Eibe Frank-3 wrote
It looks like attributenamesofarule.get(0) doesn't actually exist as an
attribute name in data. The attribute(String) method in Instances returns
null if the attribute name cannot be found.

It's also possible that data is null.

Cheers,
Eibe

On Sat, Jan 7, 2017 at 2:46 PM, pranay73 <[hidden email]> wrote:

> I am using weka api for a programming task on a given dataset. I have
> stored
> the attribute names of a dataset in a ArrayList. I want to randomly pick a
> attribute name from the Arraylist and want to find it's index value.
> I wrote below code
> String att =(String) attributenamesofarule.get(0);//working fine
> int index = data.attribute(att).index(); // throwing error
> java.lang.NullPointerException
> where as when i wrote
> data.attribute("Attribute1").index();// working fine Attribute1 is name
> of a
> attribute in my data set
>
> I am not getting the problem.
> Please help me it'e urgent
>
> Thanks
>
>
>
> --
> View this message in context: http://weka.8497.n7.nabble.
> com/index-method-of-Attribute-class-throwing-java-lang-
> NullPointerException-exception-tp39132.html
> Sent from the WEKA mailing list archive at Nabble.com.
> _______________________________________________
> Wekalist mailing list
> Send posts to: [hidden email]
> List info and subscription status: https://list.waikato.ac.nz/
> mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~
> ml/weka/mailinglist_etiquette.html
>

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: index() method of Attribute class throwing java.lang.NullPointerException exception

Eibe Frank-3
What I mean is that the string returned by attributenamesofarule.get(0) is not actually present as an attribute name in the dataset. Make sure the result returned by attributenamesofarule.get(0) actually matches one of the attribute names in your data exactly. My guess is that this is not the case at the moment. Perhaps there are extra spaces or something else?

Cheers,
Eibe

On Sun, Jan 8, 2017 at 5:35 AM, pranay73 <[hidden email]> wrote:
Hi,
The data is not null and attribute name exists in
attributenamesofarule.get(0). I am just taking the attributes names from the
weka generated rules on my data set. When I am executing the function by
providing the attribute name in a static way it is getting executed.

Thanks


Eibe Frank-3 wrote
> It looks like attributenamesofarule.get(0) doesn't actually exist as an
> attribute name in data. The attribute(String) method in Instances returns
> null if the attribute name cannot be found.
>
> It's also possible that data is null.
>
> Cheers,
> Eibe
>
> On Sat, Jan 7, 2017 at 2:46 PM, pranay73 <

> pranayr_21@

> > wrote:
>
>> I am using weka api for a programming task on a given dataset. I have
>> stored
>> the attribute names of a dataset in a ArrayList. I want to randomly pick
>> a
>> attribute name from the Arraylist and want to find it's index value.
>> I wrote below code
>> String att =(String) attributenamesofarule.get(0);//working fine
>> int index = data.attribute(att).index(); // throwing error
>> java.lang.NullPointerException
>> where as when i wrote
>> data.attribute("Attribute1").index();// working fine Attribute1 is name
>> of a
>> attribute in my data set
>>
>> I am not getting the problem.
>> Please help me it'e urgent
>>
>> Thanks
>>
>>
>>
>> --
>> View this message in context: http://weka.8497.n7.nabble.
>> com/index-method-of-Attribute-class-throwing-java-lang-
>> NullPointerException-exception-tp39132.html
>> Sent from the WEKA mailing list archive at Nabble.com.
>> _______________________________________________
>> Wekalist mailing list
>> Send posts to:

> Wekalist@.ac

>> List info and subscription status: https://list.waikato.ac.nz/
>> mailman/listinfo/wekalist
>> List etiquette: http://www.cs.waikato.ac.nz/~
>> ml/weka/mailinglist_etiquette.html
>>
>
> _______________________________________________
> Wekalist mailing list
> Send posts to:

> Wekalist@.ac

> List info and subscription status:
> https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette:
> http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html





--
View this message in context: http://weka.8497.n7.nabble.com/index-method-of-Attribute-class-throwing-java-lang-NullPointerException-exception-tp39132p39144.html
Sent from the WEKA mailing list archive at Nabble.com.
_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html


_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Loading...