Java >为了避免出现ClassCastException,请不要将某些内容强制转换到错误的类。从问题行中删除appIdResponse=(ActionCompletedListener)将有助于消除该异常。但您的代码似乎也存在其他问题。好的。谢谢顺便说一句,我会
Java >为了避免出现ClassCastException,请不要将某些内容强制转换到错误的类。从问题行中删除appIdResponse=(ActionCompletedListener)将有助于消除该异常。但您的代码似乎也存在其他问题。好的。谢谢顺便说一句,我会,java,android,fatal-error,classcastexception,forceclose,Java,Android,Fatal Error,Classcastexception,Forceclose,>为了避免出现ClassCastException,请不要将某些内容强制转换到错误的类。从问题行中删除appIdResponse=(ActionCompletedListener)将有助于消除该异常。但您的代码似乎也存在其他问题。好的。谢谢顺便说一句,我会接受你的回答,但你认为我还应该知道什么?(如果你能告诉我你注意到了什么,我会进一步调查)@user3700521你有ActionCompletedListener-appIdResponse=null然后您有GetappIdResponse-a
>为了避免出现
ClassCastException
,请不要将某些内容强制转换到错误的类。从问题行中删除appIdResponse=(ActionCompletedListener)
将有助于消除该异常。但您的代码似乎也存在其他问题。好的。谢谢顺便说一句,我会接受你的回答,但你认为我还应该知道什么?(如果你能告诉我你注意到了什么,我会进一步调查)@user3700521你有ActionCompletedListener-appIdResponse=null代码>然后您有GetappIdResponse-appIdResponse=(GetappIdResponse)o
这样很容易弄乱类型。@user3700521您可能只需删除ActionCompletedListener appIdResponse=null代码>
ActionCompletedListener appIdResponse = null;
try {
ActionCompletedListener listener = new ActionCompletedListener() {
@Override
public void callback(Object o) {
// O is your response, cast to the type you need
GetappIdResponse appIdResponse = (GetappIdResponse) o;
// Handle response
if (appIdResponse != null) {
variables.login.entityID = ((GetappIdResponse) appIdResponse)
.getappID();
} else {
Toast toast = Toast
.makeText(
getApplication(),
"Could not properly retrieve app data. Please check your network connection",
Toast.LENGTH_LONG);
toast.show();
AlertDialog.Builder builder = new AlertDialog.Builder(
ActivityMain.this);
builder.setMessage(
getResources().getString(R.string.app_id_failure))
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
// return false;
}
}
};
appIdResponse = (ActionCompletedListener) new GetappIdTask(
variables.login, variables.MAC, listener).execute();
06-12 12:21:12.180: W/System.err(3294): java.lang.ClassCastException: com.example.login.wstasks.GetappIdTask cannot be cast to com.example.common.utils.ActionCompletedListener
06-12 12:21:12.180: D/dalvikvm(3294): GC_CONCURRENT freed 478K, 10% free 4666K/5184K, paused 1ms+3ms, total 15ms
06-12 12:21:12.180: W/System.err(3294): at com.example.app.ActivityMain.getapp(ActivityMain.java:713)
06-12 12:21:12.180: W/System.err(3294): at com.example.app.ActivityMain.initializeVariables(ActivityMain.java:928)
06-12 12:21:12.180: W/System.err(3294): at com.example.app.ActivityMain.onCreate(ActivityMain.java:161)
06-12 12:21:12.180: W/System.err(3294): at android.app.Activity.performCreate(Activity.java:5104)
06-12 12:21:12.180: W/System.err(3294): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-12 12:21:12.180: W/System.err(3294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-12 12:21:12.180: W/System.err(3294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-12 12:21:12.180: W/System.err(3294): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-12 12:21:12.180: W/System.err(3294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-12 12:21:12.180: W/System.err(3294): at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 12:21:12.180: W/System.err(3294): at android.os.Looper.loop(Looper.java:137)
06-12 12:21:12.180: W/System.err(3294): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-12 12:21:12.180: W/System.err(3294): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 12:21:12.180: W/System.err(3294): at java.lang.reflect.Method.invoke(Method.java:511)
06-12 12:21:12.180: W/System.err(3294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-12 12:21:12.180: W/System.err(3294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-12 12:21:12.180: W/System.err(3294): at dalvik.system.NativeStart.main(Native Method)
06-12 12:21:12.200: V/TaskManager(3294): In initializeQueue() on MAIN THREAD
06-12 12:21:12.200: D/AndroidRuntime(3294): Shutting down VM
06-12 12:21:12.200: W/dalvikvm(3294): threadid=1: thread exiting with uncaught exception (group=0x41c93930)
06-12 12:21:12.200: E/AndroidRuntime(3294): FATAL EXCEPTION: main
06-12 12:21:12.200: E/AndroidRuntime(3294): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.ActivityMain}: java.lang.NullPointerException
06-12 12:21:12.200: E/AndroidRuntime(3294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-12 12:21:12.200: E/AndroidRuntime(3294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-12 12:21:12.200: E/AndroidRuntime(3294): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-12 12:21:12.200: E/AndroidRuntime(3294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-12 12:21:12.200: E/AndroidRuntime(3294): at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 12:21:12.200: E/AndroidRuntime(3294): at android.os.Looper.loop(Looper.java:137)
06-12 12:21:12.200: E/AndroidRuntime(3294): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-12 12:21:12.200: E/AndroidRuntime(3294): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 12:21:12.200: E/AndroidRuntime(3294): at java.lang.reflect.Method.invoke(Method.java:511)
06-12 12:21:12.200: E/AndroidRuntime(3294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-12 12:21:12.200: E/AndroidRuntime(3294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-12 12:21:12.200: E/AndroidRuntime(3294): at dalvik.system.NativeStart.main(Native Method)
06-12 12:21:12.200: E/AndroidRuntime(3294): Caused by: java.lang.NullPointerException
06-12 12:21:12.200: E/AndroidRuntime(3294): at com.example.app.taskmanager.tasks.TaskFactory.getTaskByName(TaskFactory.java:51)
06-12 12:21:12.200: E/AndroidRuntime(3294): at com.example.app.taskmanager.TaskManager.initializeQueue(TaskManager.java:92)
06-12 12:21:12.200: E/AndroidRuntime(3294): at com.example.app.taskmanager.TaskManager.<init>(TaskManager.java:71)
06-12 12:21:12.200: E/AndroidRuntime(3294): at com.example.app.ActivityMain.keepAlive(ActivityMain.java:479)
06-12 12:21:12.200: E/AndroidRuntime(3294): at com.example.app.ActivityMain.initializeVariables(ActivityMain.java:947)
06-12 12:21:12.200: E/AndroidRuntime(3294): at com.example.app.ActivityMain.onCreate(ActivityMain.java:161)
06-12 12:21:12.200: E/AndroidRuntime(3294): at android.app.Activity.performCreate(Activity.java:5104)
06-12 12:21:12.200: E/AndroidRuntime(3294): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-12 12:21:12.200: E/AndroidRuntime(3294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-12 12:21:12.200: E/AndroidRuntime(3294): ... 11 more
06-12 12:21:12.210: W/System(3294): Ignoring HTTP header field 'WS_AUTH_TOKEN' because its value is null