我将全局对象放在ray.global.centa里,代码如下:
- Java code
package ray.global.centa;import android.app.Application;public class Screen extends Application { public int Screen_Width; public int Screen_Heigh; }
然后在另一个package里引用:
- Java code
package ray.app.centa;import android.app.Activity;import android.os.Bundle;import android.util.DisplayMetrics;public class CentaPhoneAppActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ray.global.centa.Screen screen = (ray.global.centa.Screen)getApplicationContext(); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); //screen.Screen_Width = dm.widthPixels; //screen.Screen_Width = dm.heightPixels; }}
一运行结果就杯具了,出错,退出。调试后的错误信息是:Source Not Find
有劳各位大侠出手相助!谢谢!
------解决方案--------------------
manifest中,application设置了name属性了吗?