ClassCastException: java.lang.String cannot be cast to - classcastexception

I have an activity in my App that browses Facebook Page albums. It used to work fine but now when I click on it, the App force closes. I haven't made any changes to it at all. Could anyone please help me fix this problem.
The Log message:
java.lang.ClassCastException: java.lang.String cannot be cast to
$AlbumSelectedListener.onItemSelected(FacebookAlbumDemoActivity.java:181)
And Below is the line 181
public class AlbumSelectedListener implements OnItemSelectedListener
{
public void onItemSelected(AdapterView<?> parent,View view,int pos,long id)
{
((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
// Line 181 below
selectedAlbum=(AlbumItem)spinnerSelectAlbum.getItemAtPosition(pos);
updateAlbum();
}
}
Where spinnerSelectAlbum is private Spinner spinnerSelectAlbum; And selectedAlbum is private AlbumItem selectedAlbum;
The AlbumItem class:
package com.fb.facebookalbumdemo;
public class AlbumItem{
private String id;
private String name;
private String description;
public AlbumItem(String id,String name,String description){
this.id=id;
this.name=name;
this.description=description;
}
public String getId(){
return id;
}
public void setId(String id){
this.id=id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public String getDescription(){
return description;
}
public void setDescription(String description){
this.description=description;
}
#Override
public String toString(){
//returning name because that is what will be displayed in the Spinner control
return(this.name);
}
}
After going through all the classes, apparently something is wrong with these two lines in string.xml. After some search on google apparently they have changed the way we retrieve the Albums and Photos from facebook. Is that so? The version of Graph API has changed. Because I haven't changed anything at all in any of the Apps (with graph API) and all of them have stopped working.
<string name="facebook_url_albums">graph.facebook.com/myFBid/albums</string>;
<string name="facebook_url_photos">graph.facebook.com/[ALBUMID]/photos</string>;

Related

infinispan 9.4 - Listeners and event filter

I'm trying to use Listeners with filters in a distributed cache with two instances of Infinispan 9.4.0 and Hot Rod Client. When I try to put a new entry in cache, I get the following exception:
[Server:instance-one] 13:09:57,468 ERROR [stderr] (HotRod-ServerHandler-4-2) Exception in thread "HotRod-ServerHandler-4-2" org.infinispan.commons.CacheException: ISPN000936: Class 'com.cm.broadcaster.infinispan.entity.EntityDemo' blocked by deserialization white list. Adjust the configuration serialization white list regular expression to include this class.
This is the cache configuration:
<distributed-cache name="entityCache" remote-timeout="3000" statistics-available="false">
<memory>
<object size="20" strategy="LRU" />
</memory>
<compatibility enabled="true"/>
<file-store path="entity-store" passivation="true"/>
<indexing index="NONE"/>
<state-transfer timeout="60000" chunk-size="1024"/>
</distributed-cache>
This is my demo class:
public class EntityDemo implements Serializable {
private static final long serialVersionUID = 1L;
private long id;
private String name;
private String value;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
The EventFilterFactory:
#NamedFactory(name="entity-event-filter-factory")
public class EntityEventFilterFactory implements CacheEventFilterFactory {
#Override
public CacheEventFilter<String, EntityDemo> getFilter(Object[] params) {
return new EntityEventFilter(params);
}
}
The EventFilter:
public class EntityEventFilter implements Serializable, CacheEventFilter<String, EntityDemo> {
private static final long serialVersionUID = 1L;
private final long filter;
public EntityEventFilter(Object[] params) {
this.filter = Long.valueOf(String.valueOf(params[0]));
}
#Override
public boolean accept(String key, EntityDemo oldValue, Metadata oldMetadata, EntityDemo newValue, Metadata newMetadata, EventType eventType) {
if (eventType.isCreate()) {
if (oldValue.getId() % filter == 0)
return true;
}
return false;
}
}
My test code:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.addServers("localhost:11222");
RemoteCacheManager rcm = new RemoteCacheManager(cb.build());
RemoteCache<String, EntityDemo> rc = rcm.<String,
EntityDemo>getCache("entityCache");
rc.addClientListener(new CustomListener(), new Object[]{"1"}, null);
EntityDemo e = new EntityDemo();
e.setId(1);
e.setName("Demo");
e.setValue("Demo");
rc.put("1", e);
The listener:
#ClientListener(filterFactoryName="entity-event-filter-factory")
public class CustomListener {
#ClientCacheEntryCreated
public void entryCreated(ClientCacheEntryCreatedEvent<String> event) {
System.out.println("Entry created!");
System.out.println(event.getKey());
}
}
I have looked about white list for serialization, but I have found nothing.
I tried changing object in memory configuration for binary and disabling compatibility, but then I get a new exception:
[Server:instance-one] 13:56:42,131 ERROR [org.infinispan.interceptors.impl.InvocationContextInterceptor] (HotRod-ServerHandler-4-2) ISPN000136: Error executing command PutKeyValueCommand, writing keys [WrappedByteArray{bytes=[B0x01012903033E0131, hashCode=1999574342}]: java.lang.ClassCastException: java.lang.String cannot be cast to com.cm.broadcaster.infinispan.entity.EntityDemo
Can anyone help me with this?
Have you tried this? Passing the -Dinfinispan.deserialization.whitelist.classes property to the server.
http://infinispan.org/docs/stable/upgrading/upgrading.html#deserialization_whitelist

No converter found capable of converting from type [java.lang.String] to type [org.springframework.data.solr.core.geo.Point]

I am trying to use spring-data-solr in order to access to my Solr instance through my Spring boot application. I have the following bean class:
#SolrDocument(solrCoreName = "associations")
public class Association implements PlusimpleEntityI {
#Id
#Indexed
private String id;
#Indexed
private String name;
#Indexed
private Point location;
#Indexed
private String description;
#Indexed
private Set<String> tags;
#Indexed
private Set<String> topics;
#Indexed
private Set<String> professionals;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Point getLocation() {
return location;
}
public void setLocation(Point location) {
this.location = location;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<String> getTags() {
return tags;
}
public void setTags(Set<String> tags) {
this.tags = tags;
}
public Set<String> getTopics() {
return topics;
}
public void setTopics(Set<String> topics) {
this.topics = topics;
}
public Set<String> getProfessionals() {
return professionals;
}
public void setProfessionals(Set<String> professionals) {
this.professionals = professionals;
}
}
I have implemented the following repository in order to access to the related information:
public interface AssociationsRepository extends SolrCrudRepository<Association, String> {
}
I have created a configuration class which looks like the following one:
#Configuration
#EnableSolrRepositories(basePackages = {"com.package.repositories"}, multicoreSupport = true)
public class SolrRepositoryConfig {
#Value("${solr.url}")
private String solrHost;
#Bean
public SolrConverter solrConverter() {
MappingSolrConverter solrConverter = new MappingSolrConverter(new SimpleSolrMappingContext());
solrConverter.setCustomConversions(new CustomConversions(null));
return solrConverter;
}
#Bean
public SolrClientFactory solrClientFactory () throws Exception {
return new MulticoreSolrClientFactory(solrClient());
}
#Bean
public SolrClient solrClient() throws Exception {
return new HttpSolrClient.Builder(solrHost).build();
}
#Bean
public SolrOperations associationsTemplate() throws Exception {
SolrTemplate solrTemplate = new SolrTemplate(solrClient());
solrTemplate.setSolrConverter(solrConverter());
return solrTemplate;
}
}
Unfortunately, when I try to read an association from my Solr instance I got the following error:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [org.springframework.data.solr.core.geo.Point]
I don't understand why it is not able to find a converter if I have explicitly defined it in the solrTemplate() method.
This is my POM definition:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
Thank you for your help.
EDIT:
I've also tried with different BUILD-RELEASEs but they are highly unstable and I've found a lot of errors using them.
Alessandro, as you can see directly in the GeoConverters class on GitHub, the implemented converters are only for:
org.springframework.data.geo.Point
and not for:
org.springframework.data.solr.core.geo.Point
Simply use this class and you don't even need a custom converter for this. Spring Data for Solr will perform the conversion for you.
I'm using a slightly patched version of the 3.0.0 M4, but I'm pretty sure this solution should apply seamlessly also to your case.

Spring-data-solr config

i met a problem in Studying with Spring data solr,this is my Configuration Class:
#Configuration
#EnableSolrRepositories(basePackages={"cn.likefund.solr.repository"}, multicoreSupport=true)
public class SolrContext {
static final String SOLR_HOST = "http://192.168.11.157:8080/solr";
#Bean
public SolrClient solrClient() {
return new HttpSolrClient(SOLR_HOST);
}
}
and this is my Repository:
package cn.likefund.solr.repository;
import java.util.List;
import org.springframework.data.solr.repository.SolrCrudRepository;
import cn.likefund.solr.model.Activity;
public interface ActivityRepository extends SolrCrudRepository<Activity, String>{
List<Activity> findByName(String name);
}
when I start the application,the message in console is this
error
When I delete the method findByName in the repository,the application start with no problem, i just want to the method findByName worked,anybody know what should i do with this problem?
here is the Activity Class:
#Entity
#SolrDocument(solrCoreName ="core_activity")
public class Activity implements Serializable{
private static final long serialVersionUID = 1566434582540525979L;
#Id
#Field(value = "id")
private String id;
#Field(value = "CREATEDT")
private String createdt;
#Indexed
#Field(value = "NAME")
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCreatedt() {
return createdt;
}
public void setCreatedt(String createdt) {
this.createdt = createdt;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
So, obviously the CrudRepository is not created .
when you delete the findByName, can you manually query your repo ? (just to be sure the problem comes from the method, and not the SOLR schema)
have you tried to annotate annotate the method to explicitly set the query ? Something like
#Query("NAME:?0")
List findByName(String name);

Espresso match selected spinner text

Following the answer here, I try to check whether a certain spinner text is selected. The spinner appears in a dialog, so I tried:
onView(withId(R.id.package_spinner)).inRoot(isDialog()).check(matches(withSpinnerText(containsString("sachet"))));
However this does not work and I get the following error message:
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError:
'with text: a string containing "sachet"' doesn't match the selected
view.
Expected: with text: a string containing "sachet"
Got: "AppCompatSpinner{id=2131624039, res-name=package_spinner, visibility=VISIBLE, width=620, height=75, has-focus=false,
has-focusable=true, has-window-focus=true, is-clickable=true,
is-enabled=true, is-focused=false, is-focusable=true,
is-layout-requested=false, is-selected=false,
root-is-layout-requested=false, has-input-connection=false, x=0.0,
y=75.0, child-count=1}"
Does "is-selected=false" mean, that the spinner it found is not selected? This is running on a real device (not emulator) with API 18. During the Espresso run and also when testing manually, the spinner is correctly set to "sachet". Why does Espresso have a problem with it?
Not sure whether this is relevant, but the spinner is for objects of type:
public class PackageType {
private int id;
private String name;
private final Context ctx;
public PackageType(Context context) { this.ctx=context; }
public PackageType(String name, Context context) {
super();
this.ctx = context;
setName(name);
}
// setters
public void setId(int i) { this.id = i; }
public void setName(String u) {
this.name = u;
}
// getters
public int getId() { return id; }
public String getName() { return name; }
}
and the spinner adapter looks like:
class SpinnerPackageTypeAdapter extends ArrayAdapter<PackageType> {
private final List<PackageType> packageTypes;
private final Context mContext;
public SpinnerPackageTypeAdapter(Context context, int resource, List<PackageType> packageTypes) {
super(context, resource, packageTypes);
this.mContext = context;
this.packageTypes = packageTypes;
}
public PackageType getItem(int position) { return packageTypes.get(position); }
public long getItemId(int position) { return position; }
// this is for the passive state of the spinner
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// use dynamically created TextView, but could reference custom layout
TextView label = new TextView(mContext);
label.setTextColor(Color.BLACK);
label.setTextSize(mContext.getResources().getDimension(R.dimen.list_row_font_size));
label.setGravity(Gravity.CENTER);
label.setText(getItem(position).getName());
return label;
}
// this is for the chooser dropped down spinner
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView label = (TextView) View.inflate(mContext,R.layout.row_spinner,null);
label.setText(getItem(position).getName());
return label;
}
}
I found the problem. In class PackageType I had to override the toString() method as (of course other versions are possible as long as "name" is in there):
#Override
public String toString() {
return "PackageType [id=" + id + ", name=" + name + "]";
}

Arraylist can't add element

Why isn't this working for me?
public class Band {
public void addMember(Musician musician) {
musicians.add(musician);
System.out.println("Muscian: " + musician + "was successfully added");
}
}
public static void main(String[] args) {
Band Beatles = new Band("Beatles");
Beatles.addMember("John Lennon");
}
public class Musician {
private String name;
public Musician(String name, Instrument instrument) {
this.name = name;
Instrument Guitar = instrument;
}
public void play() {
}
}
Beatles.addMember("John Lennon");
should be
Beatles.addMember(new Musician("John Lennon", new Instrument(new Guitar()));
I suspect, without seeing your actual Instrument class, based on your comment that this line should work.
The problem is that you are treating some objects as Strings. You need to create the object out of the class that defines it first.