我有一个FragmentActivity
由许多元素组成的元素,这些元素会在每个关于该项目的项目上显示一个弹出窗口,我正在以常规方式创建弹出窗口:
LayoutInflater inflater;
View layout;
inflater = (LayoutInflater) MyActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = inflater.inflate(R.layout.my_popup_layout,
(ViewGroup) findViewById(R.id.my_popup));
这种方式在单击任何项目时非常有效,但这只是在单击应用程序时崩溃并引发的一项system services not available exception
:
07-07 11:49:14.905: E/AndroidRuntime(2684): FATAL EXCEPTION: main
07-07 11:49:14.905: E/AndroidRuntime(2684): Process: com.automation.isolace, PID: 2684
07-07 11:49:14.905: E/AndroidRuntime(2684): java.lang.IllegalStateException: System services not available to Activities before onCreate()
07-07 11:49:14.905: E/AndroidRuntime(2684): at android.app.Activity.getSystemService(Activity.java:4532)
07-07 11:49:14.905: E/AndroidRuntime(2684): at com.automation.isolace.MyActivity$3.onClick(Security.java:767)
07-07 11:49:14.905: E/AndroidRuntime(2684): at android.view.View.performClick(View.java:4438)
07-07 11:49:14.905: E/AndroidRuntime(2684): at android.view.View$PerformClick.run(View.java:18422)
07-07 11:49:14.905: E/AndroidRuntime(2684): at android.os.Handler.handleCallback(Handler.java:733)
07-07 11:49:14.905: E/AndroidRuntime(2684): at android.os.Handler.dispatchMessage(Handler.java:95)
07-07 11:49:14.905: E/AndroidRuntime(2684): at android.os.Looper.loop(Looper.java:136)
07-07 11:49:14.905: E/AndroidRuntime(2684): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-07 11:49:14.905: E/AndroidRuntime(2684): at java.lang.reflect.Method.invokeNative(Native Method)
07-07 11:49:14.905: E/AndroidRuntime(2684): at java.lang.reflect.Method.invoke(Method.java:515)
07-07 11:49:14.905: E/AndroidRuntime(2684): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-07 11:49:14.905: E/AndroidRuntime(2684): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-07 11:49:14.905: E/AndroidRuntime(2684): at dalvik.system.NativeStart.main(Native Method)
单击时发生此行为的项目是唯一以编程方式创建的项目:
Button rooms = new Button(MyApplication.getAppContext());
container_layout.addView(rooms);
params = (RelativeLayout.LayoutParams) rooms.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
rooms.setLayoutParams(params);
rooms.setTag(sys_id);
rooms.setTag(R.string.app_name, zone_name.getText());
rooms.setBackgroundResource(R.drawable.a_drawable_button_drawable);
rooms.setText(R.string.rooms);
rooms.setTextColor(Color.WHITE);
rooms.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
rooms.setPadding(5, 3, 5, 3);
rooms.setOnClickListener(on_zone_roomsClick);