1

我正在尝试制作一个列表视图,当我单击一个项目时,我想打开另一个类。第二类实际上是从原始文件夹中打开文件。

我的课是

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;


public class Cod_rutier extends MainActivity2A {

     private ListView lv1;

     private String lv_arr[]={"CAP.1: Dispozitii generale",
                "CAP.2: Vehiculele",
                "CAP.3: Conducatorii de vehicule",
                "CAP.4: Semnalizarea rutiera",
                "CAP.5: Reguli de circulatie",
                "CAP.6: Infractiuni si pedepse",
                "CAP.7: Raspunderea contraventionala",
                "CAP.8: Cai de atac impotriva procesului-verbal de constatare a contraventiei",
                "CAP.9: Atributii ale unor ministere si ale altor autoritati ale administratiei publice",
                "CAP.10: Dispozitii finale"};
        /** Called when the activity is first created. */
     /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.legislatie);

            lv1=(ListView)findViewById(R.id.listView1);

            // By using setAdpater method in listview we an add string array in list.

            lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr));


            lv1.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
              final TextView mTextView = (TextView)view;
              switch (position) {
                case 0:
                 Intent newActivity0 = new Intent(Cod_rutier.this, Legislatie1.class);     
                 startActivity(newActivity0);
                break;
                case 1:
                 Intent newActivity1 = new Intent(Cod_rutier.this,  Legislatie2.class);     
                 startActivity(newActivity1);
                break;
                case 2 :
                 Intent newActivity2 = new Intent(Cod_rutier.this,  Legislatie3.class);     
                 startActivity(newActivity2);
                break;
                case 3:
                 Intent newActivity3 = new Intent(Cod_rutier.this, Legislatie4.class);     
                 startActivity(newActivity3);
                break;
                default:
              }

          }
        });

        }}

我把它放到清单文件中,但是当我运行它时,应用程序停止了。这是我的日志猫

03-16 18:58:35.373: E/AndroidRuntime(828): FATAL EXCEPTION: main
03-16 18:58:35.373: E/AndroidRuntime(828): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vreaucarnet/com.example.vreaucarnet.Cod_rutier}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
03-16 18:58:35.373: E/AndroidRuntime(828):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-16 18:58:35.373: E/AndroidRuntime(828):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-16 18:58:35.373: E/AndroidRuntime(828):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-16 18:58:35.373: E/AndroidRuntime(828):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-16 18:58:35.373: E/AndroidRuntime(828):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-16 18:58:35.373: E/AndroidRuntime(828):  at android.os.Looper.loop(Looper.java:123)
03-16 18:58:35.373: E/AndroidRuntime(828):  at android.app.ActivityThread.main(ActivityThread.java:4627)
03-16 18:58:35.373: E/AndroidRuntime(828):  at java.lang.reflect.Method.invokeNative(Native Method)
03-16 18:58:35.373: E/AndroidRuntime(828):  at java.lang.reflect.Method.invoke(Method.java:521)
03-16 18:58:35.373: E/AndroidRuntime(828):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-16 18:58:35.373: E/AndroidRuntime(828):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-16 18:58:35.373: E/AndroidRuntime(828):  at dalvik.system.NativeStart.main(Native Method)
03-16 18:58:35.373: E/AndroidRuntime(828): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
03-16 18:58:35.373: E/AndroidRuntime(828):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:172)
03-16 18:58:35.373: E/AndroidRuntime(828):  at android.app.Activity.requestWindowFeature(Activity.java:2719)
03-16 18:58:35.373: E/AndroidRuntime(828):  at com.example.vreaucarnet.Cod_rutier.onCreate(Cod_rutier.java:33)
03-16 18:58:35.373: E/AndroidRuntime(828):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-16 18:58:35.373: E/AndroidRuntime(828):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-16 18:58:35.373: E/AndroidRuntime(828):  ... 11 more

有人可以告诉我我的错误在哪里吗?

4

2 回答 2

1

请求任何 requestWindowFeature 调用都在您的活动中的 super.onCreate 调用之前完成

IE

requestWindowFeature(Window.FEATURE_NO_TITLE); this should be called before super.onCreate()

改变喜欢

    requestWindowFeature(Window.FEATURE_NO_TITLE);
  super.onCreate(savedInstanceState);
于 2013-03-16T17:15:10.597 回答
0

是这里:

Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
于 2013-03-16T17:10:08.753 回答