私は問題に直面しています、ListActivity
私が推測する呼び出し中に、それはシステム機能が以前は機能していなかったことを教えてくれますonCreate
。私はそれonCreate
が(私のコードによれば)呼ばれているのを見ますがIllegalStateException
、それは私にこれまで扱ったことのないを与えています。ちなみに、私はを使用してSherlockListActivity
います。これが私のコードです:
public class MenuActivity extends SherlockListActivity {
ListView scroll;
int time;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
scroll = this.getListView();
this.setListAdapter(new MyAdapter());
}
public View find(int x){
return findViewById(x);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
switch (position){
case (0):{
Toast.makeText(getApplicationContext(), "Hello you just chose \"Splash\"", Toast.LENGTH_SHORT).show();
}break;
case (1):{
Toast.makeText(getApplicationContext(), "Its another one here !", Toast.LENGTH_SHORT).show();
}break;
case (2):{
Toast.makeText(getApplicationContext(), String.valueOf(id) +" and "+ position, Toast.LENGTH_SHORT).show();
}break;
}
}
public void showToast(String toast){
Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();
}
}
class MyAdapter extends ArrayAdapter<String>{
LayoutInflater inf = LayoutInflater.from(this.getContext());
public MyAdapter() {
super(new MenuActivity() , 0 ,stringArray);
// TODO Auto-generated constructor stub
}
public static String[] stringArray= new String[]{"Splash" , "Another Example" , "Future Checkable"};
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null){
inf.inflate(R.layout.normal_row, parent , false);
}
switch(position){
case(0):
convertView = (LinearLayout) inf.inflate(R.layout.row_switch, parent,false);
break;
}
return super.getView(position, convertView, parent);
}
}
そして私のスタックトレース:
12-09 16:19:45.144: E/AndroidRuntime(28754): FATAL EXCEPTION: main
12-09 16:19:45.144: E/AndroidRuntime(28754): java.lang.RuntimeException: Unable to start activity ComponentInfo{seaskyways.testingproject/seaskyways.testingproject.MenuActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.os.Handler.dispatchMessage(Handler.java:99)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.os.Looper.loop(Looper.java:137)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-09 16:19:45.144: E/AndroidRuntime(28754): at java.lang.reflect.Method.invokeNative(Native Method)
12-09 16:19:45.144: E/AndroidRuntime(28754): at java.lang.reflect.Method.invoke(Method.java:511)
12-09 16:19:45.144: E/AndroidRuntime(28754): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-09 16:19:45.144: E/AndroidRuntime(28754): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-09 16:19:45.144: E/AndroidRuntime(28754): at dalvik.system.NativeStart.main(Native Method)
12-09 16:19:45.144: E/AndroidRuntime(28754): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.app.Activity.getSystemService(Activity.java:4463)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:128)
12-09 16:19:45.144: E/AndroidRuntime(28754): at seaskyways.testingproject.MyAdapter.<init>(MenuActivity.java:82)
12-09 16:19:45.144: E/AndroidRuntime(28754): at seaskyways.testingproject.MenuActivity.onCreate(MenuActivity.java:26)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.app.Activity.performCreate(Activity.java:5104)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-09 16:19:45.144: E/AndroidRuntime(28754): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-09 16:19:45.144: E/AndroidRuntime(28754): ... 11 more