0

NPE を取得していますが、logcat を確認すると、コードが使用されているポイントがありません。

RadioButtonGroup を含む AlertDialog を表示しようとすると、プログラムがクラッシュします。以前は機能していましたが、覚えている唯一の変更はダイアログの後です。

今、私は以下を受け取ります: 編集:

06-19 17:15:19.430: E/AndroidRuntime(898): java.lang.NullPointerException
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.AbsListView.obtainView(AbsListView.java:2143)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.ListView.measureHeightOfChildren(ListView.java:1246)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.ListView.onMeasure(ListView.java:1158)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.View.measure(View.java:15518)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.View.measure(View.java:15518)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.View.measure(View.java:15518)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.View.measure(View.java:15518)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.View.measure(View.java:15518)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-19 17:15:19.430: E/AndroidRuntime(898):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.View.measure(View.java:15518)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.Choreographer.doFrame(Choreographer.java:532)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.os.Handler.handleCallback(Handler.java:725)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.os.Looper.loop(Looper.java:137)
06-19 17:15:19.430: E/AndroidRuntime(898):  at android.app.ActivityThread.main(ActivityThread.java:5041)
06-19 17:15:19.430: E/AndroidRuntime(898):  at java.lang.reflect.Method.invokeNative(Native Method)
06-19 17:15:19.430: E/AndroidRuntime(898):  at java.lang.reflect.Method.invoke(Method.java:511)
06-19 17:15:19.430: E/AndroidRuntime(898):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-19 17:15:19.430: E/AndroidRuntime(898):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-19 17:15:19.430: E/AndroidRuntime(898):  at dalvik.system.NativeStart.main(Native Method)

ステップスルーしたときに実行される最後のコードブロックは次のとおりです。

public void addTeam (View view) {
    //open select race dialog
    AlertDialog alertDialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 

    String[] items = new String[races.size()];
    int i = 0;
    for (Race race : races) {
        //add radio button for each race
        items[i] = race.raceName;
    }
    builder.setTitle(getString(R.string.select_race));
    builder.setSingleChoiceItems(items, 0, null);

    builder.setPositiveButton(R.string.done, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int whichButton) {
                dialogInterface.dismiss();
                Team team = new Team();
                team.raceIndex = ((AlertDialog) dialogInterface).getListView().getCheckedItemPosition();
                team.raceName = races.get(team.raceIndex).raceName;
                setContentView(R.layout.edit_team);
                ((TextView) findViewById(R.id.raceTV)).setText(team.raceName);
            }
    });

    alertDialog = builder.create();  
    alertDialog.show();
}

コードへの行参照がなければ、どこから始めればよいかさえわかりません。助けていただければ幸いです。

4

3 に答える 3

0

これを交換

((TextView) findViewById(R.id.raceTV)).setText(team.raceName);

((TextView) dialog.findViewById(R.id.raceTV)).setText(team.raceName);
于 2013-06-19T17:40:55.017 に答える