상황 : 함수가 스레드를 호출하여 서버에 데이터를 보냅니다. 이 스레드는 ObjectInputStream()을 사용하여 서버에서 결과를 얻기 위해 또 다른 스레드를 생성합니다.Android : FutureTask를 MyClass로 캐스팅 할 수 없습니다.
마지막으로,이 개체는 생성 된 스레드에 의해 호출 함수에 반환됩니다.
참고 : 스레드는 입니다. 호출 가능이고 은입니다.
문제는 : 나는 예외가 "FutureTask는을 MyClassName 캐스팅 할 수 없습니다."
웹에서이 문제에 대한 해결책을 찾지 못했습니다. 어떤 제안?
클라이언트 코드 :
public synchronized Object invoke(Object proxy, Method m, Object[] args) throws Throwable
{
try {
// Lots of if-else statements
//.........
else if (m.toString().contains("getPosition"))
{
if (!offload){
Log.d("DProxy","Sprite Redirection takes place here 6 "+m.invoke(v, args).toString());
//System.out.println("PROXY Tick Argument is ");
return m.invoke(v, args);
}
else
{
//Code to create THREAD on the Endpoint
if (endpoint !=null)
{
if (!serialized)
{
System.out.println("serializing via proxy itself 11");
this.endpoint.serialize(obj);
serialized = true;
}
Object[] args1 = new Object[args.length+1];
for (i=0;i<args.length;i++)
args1[i]=args[i];
args1[i]= m.toString();
// ** Error is thrown at this line below**
Vec2 tmp = (Vec2) this.endpoint.onClick(args1);
return tmp;
//return null;
}
else
System.out.println("Endpoint is NULL");
}
}
의 onclick() 메소드.
public synchronized Object onClick(Object[] args) {
try {
latch.await();
ctr++;
Log.d("CLIENT","Sending Param to Client "+args[args.length-1].toString()+" "+ctr);
objectOutputStream.writeBoolean(false);
// TEMP Commented
objectOutputStream.flush();
objectOutputStream.reset();
objectOutputStream.writeObject(args);
Callable<Object> worker = (Callable<Object>) new ClientThread(thisSocket,ctr);
return executor.submit(worker);
}catch (Exception e)
{
Log.e("ENDPOINT Exception",e.toString());
}
Log.e("ENDPOINT","Returning blank Object");
return new Object();
}
class ClientThread implements Callable <Object>{//Runnable {
private int ctr;
public ClientThread(Socket socket, int ctr)
{
this.ctr = ctr;
}
public synchronized Object call() {
Vec2 res1 = null;
Double res2=null;
Object res = null;
try {
Log.v("CLIENT","Attempting to receive results from Server "+ctr);
res = objectInputStream.readObject();
if (res instanceof Vec2)
{
res1 = (Vec2) res;
Log.v("CLIENT", "Object received Vec2 "+ctr);
}
else if (res instanceof Double)
{
res2 = (Double) res;
Log.v("CLIENT", "Object received Double "+ctr);
}
else
if(res==null)
Log.v("CLIENT", "Object received is NULL "+ctr);
else
Log.v("CLIENT", "Object received of UNKNOWN Type "+ctr);
} catch (UnknownHostException e1) {
Log.e("CLIENT receive error 1",e1.toString());
} catch (IOException e1) {
Log.e("CLIENT receive error 2",e1.toString());
}
catch (Exception e)
{
Log.e("CLIENT receive error 3",e.toString());
}
if (res1 !=null)
return res1;
else
if (res2!=null)
return res2;
else
return res;
}
//}
}
은 FutureTask를 확장하는 MyClassName입니까? – donfuxx
코드 예제를 게시하면 질문에 대답하기가 더 쉬울 것입니다. – MikeL
don, no. Michael, 소스 코드를 원본 게시물에 추가했습니다. MyClassName은 실제로 Vec2입니다. – Abhishek