我創建的其他類的全局變量的一類,現在我只想投它這樣的:錯誤鑄造
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
class2 global;
global = (class2)getApplicationContext();
我得到錯誤:
android.app.Application cannot be cast to eu.tools.test_training_home.class2
的class2
:
public class class2 extends Application {
private String name="name1";
private int number =0;
您正試圖將一個對象從Context類轉換爲一個Application對象。它可能是可能的。 – JCoder
對不起,我的意思是「不能」。 – JCoder
我建議你遵循標準的Java命名約定@Testiest。 –