我的項目一直運行良好,直到我爲我的微調控制器聲明瞭onItemSelctedListener .. 現在我的項目沒有運行..並且日誌貓顯示以下錯誤...Log cat gibbrish ... spinner,onItemSelectedListner
03-03 01:59:08.465: E/AndroidRuntime(1401):
FATAL EXCEPTION: main
Process: com.example.testqstn, PID: 1401
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.testqstn/com.example.testqstn.MainActivity}:
java.lang.IllegalStateException: System services not available to Activities
before onCreate()
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
at android.app.Activity.getSystemService(Activity.java:4532)
at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:153)
at com.example.testqstn.MainActivity.<init>(MainActivity.java:39)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
現在的點要注意的是
1)在所有沒有被實施的主要活動方式..甚至沒有super.onCreate
現在這是我輸入的代碼..但由於它沒有被執行,id odn知道生根粉它relevence ..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
main();
}
public void main()
{
TextView textyear,textsubject,textschema;
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Roboto/Roboto-Light.ttf");
textyear = (TextView)findViewById(R.id.textyear);
textsubject = (TextView)findViewById(R.id.textsubject);
textschema = (TextView)findViewById(R.id.textscheme);
textyear.setTypeface(typeface);
textsubject.setTypeface(typeface);
textschema.setTypeface(typeface);
year = (Spinner)findViewById(R.id.spinyear);
subject = (Spinner)findViewById(R.id.spinsub);
scheme = (Spinner)findViewById(R.id.spinscheme);
schemetxt = scheme.toString();
buttonSound = MediaPlayer.create(MainActivity.this,R.raw.sound);
btn=(Button)findViewById(R.id.button);
btn.setBackgroundResource(R.drawable.selector);
// set dynamic value change
scheme.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
listYear(schemetxt);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
pdfSelection(v);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
這是列表視圖功能
myAdapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, listYear);
myAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
year.setAdapter(myAdapter1);
究竟什麼是錯誤?在此先感謝..
這是B4我的OnCreate功能
Button btn;
Spinner year , subject , scheme;
String yeartxt = null;
String subtxt = null;
String schemetxt = null;
List<String> listYear;
ArrayAdapter<String> myAdapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, listYear);
MediaPlayer buttonSound;
你有一些代碼的onCreate發佈相同 – Raghunandan
'Gibbrish'之前 - 你的意思是確切的,詳細的說明的運行時錯誤,包括原因? – Simon
well gibbrish給我... :) – Alvin