1

リストビューを作成しようとしています。アイテムをクリックすると、別のクラスを作成したいと思います。2番目のクラスは、実際にはrawフォルダーからファイルを開くためのものです。

私のクラスは

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:
              }

          }
        });

        }}

マニフェストファイルに入れましたが、実行するとアプリが停止します。これは私のlogcatです

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呼び出しの前に行われます。

すなわち

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 に答える