Android:创建意图后,我无法从 MainActivity 打开 UI

创建 Intent 方法后,我无法从 MainActivity 访问我的 UI。当我从 MainActivity 中选择 SelectPLayer 和 SelectPLayer2 活动时,我的应用程序崩溃。我也无法让 Clickable ListViews 转到 GameEmulator 中的指定 TextView。


//MainActivity.java



        //Class to select player 1

        public class SelectPlayer extends Activity {



            //Public static array list with adapter to crete the array and reference for listview being sent by intent from AddPLayer class

            public static ArrayList<String> list = new ArrayList<>();

            public static ArrayAdapter<String> adapter;

            ListView selectView;

            TextView title;


            @Override

            protected void onCreate(Bundle savedInstanceState) {

                super.onCreate(savedInstanceState);

                setContentView(R.layout.selectplayer);


                //Identify selectview ListView

                selectView = findViewById(R.id.selectview) ;

                selectView.setClickable(true);

                selectView.setVisibility(View.VISIBLE);


                //Using adapter for ListView menu

                adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);

                selectView.setAdapter(adapter);

                selectView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override

                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                        String item =(String) parent.getItemAtPosition(position); // finding the item which has been clicked by the user

                        Intent intent = new Intent(SelectPlayer.this, GameEmulator.class); //starting an intent to call GameEmulator Activity

                        intent.putExtra(GameEmulator.value, item);// Putting the value clicked by user in intent

                        startActivity(intent); // starting GameEmulator Activity

                    }

                });

     

蓝山帝景
浏览 116回答 1
1回答

杨魅力

&nbsp;String&nbsp;data&nbsp;=&nbsp;i.getExtras().getString("text_key");你getExtras()正在返回空值。确保正确初始化您的意图。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java