Public class MyBean { private ByteArrayEntity myByteArrayEntity; private String someString; // getters and setters } No casting required and much easier to maintain/extend.
This will require a bit more refactoring than is practical at this stage in my project. I will definitely consider this approach in the future, it is sensible. Any suggestions on why this casting is failing, though?
It is really strange. – Tim Mar 25 at 16:34 @Tim It wouldn't really take much refactoring, less than an hour I'd guess. It would also fix your current issue, and prevent similar problems in the future.In order to see why your current code is failing we would have to see all the code where you ever set an object in the array.
I'd guess you are getting an index wrong at some point. But as I said, it's much harder to debug an array of objects than a bean. You'd be much better off just biting the bullet and doing a refactor.
Remember to save a version to source control first! – dave. C Mar 25 at 17:29 I'm still completely stuck as to why the casting doesn't work.
I will use this way... got a long weekend ahead of me. I'm learning so much as I go on this project, it is a shame I hadn't thought of these concepts initially.Thanks. – Tim Mar 25 at 17:42 Nice catch.
I didn't realize he was trying to pass multiple values of differing types. – Matthew Willis Mar 25 at 19:22.
You might use a different type parameterization of AsyncTask so that you don't need to cast. If you're using an anonymous class then: new ArrayTask() { ... So that you can do: @Override protected HttpResponse doInBackground(ByteArrayEntity... byteArrays) { ... dataPhoto = byteArrays2; ... if your arguments are indeed intended to be of type ByteArrayEntity.
This would work but my call at the moment takes an array of objects, because when I make the call, I pass a few strings and and entities and maps and then cast them later on depending on their position in the array. All of them work (the strings and maps) but the ByteArrayEntity won't cast - any ideas? – Tim Mar 25 at 15:45 Yikes.
You really need to do what dave. C says in that case. You should rely on the java type system.
– Matthew Willis Mar 25 at 19:14.
What I then have to do is make a request using an AsyncTask that takes an array of Objects which I later then cast to their various types. However, when attempting to cast my ByteArrayEntity later on, I get a ClassCastException, I was wondering if anyone could explain this? I really need to get this working, but don't really have time currently to reimplement this completely, so any hacks or workarounds would be appreciated.
The whole aim is to take an image from the Android camera, then setEntity of my HttpRequest to a ByteArrayEntity and POST my image to a server where this is then handled.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.