0
我有這個異常「java.lang.ClassCastException:android.app.Application無法轉換爲com.utility.TablePlussAndroid」 我不明白爲什麼.. 。非常感謝您的幫助在試圖開發android應用程序時獲取java.lang.ClassCastException
package com.tableplustablet;
private com.utility.TablePlusAndroid session;
public class LoginActivity extends Activity {
// ...
// get session from Application
session = (TablePlusAndroid) this.getApplication(); // <--EXCEPTION
session.setUserKey(userKey);
}
// -------------------------------------------------------------
package com.utility;
import android.app.Application;
//Save User Data in application's context
public class TablePlusAndroid extends Application{
private Long userKey;
private String userName;
private Long currentTableKey;
public Long getCurrentTableKey() {
return currentTableKey;
}
public void setCurrentTableKey(Long currentTableKey) {
this.currentTableKey = currentTableKey;
}
public Long getUserKey(){ return userKey;}
public void setUserKey(Long key){ userKey=key;}
public String getUserName() { return userName; }
public void setUserName(String userName) { this.userName = userName; }
}
你能指出的是給出了這個異常的準確代碼行?這會讓你更容易獲得幫助。 –