Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 意图传递变量故障_Java_Android_If Statement_Android Intent - Fatal编程技术网

Java 意图传递变量故障

Java 意图传递变量故障,java,android,if-statement,android-intent,Java,Android,If Statement,Android Intent,在我的应用程序中,我试图为用户提供两个功能。一个是上传带有图片的帖子,另一个是上传没有图片的帖子。为此,我创建了字符串nonselected_image和selected_image(或selected_位图)。如果用户按下其中一个文本视图,其中一个字符串将在文本中传递。当用户希望创建非照片帖子时,它非常有效,但当用户希望创建一个带有照片的帖子时,会出现两个帖子,一个带有照片,另一个没有。我做错了什么?这是我的密码 向下一个活动发送意图和字符串 TextView nextScreen =

在我的应用程序中,我试图为用户提供两个功能。一个是上传带有图片的帖子,另一个是上传没有图片的帖子。为此,我创建了字符串nonselected_image和selected_image(或selected_位图)。如果用户按下其中一个文本视图,其中一个字符串将在文本中传递。当用户希望创建非照片帖子时,它非常有效,但当用户希望创建一个带有照片的帖子时,会出现两个帖子,一个带有照片,另一个没有。我做错了什么?这是我的密码

向下一个活动发送意图和字符串

   TextView nextScreen = (TextView) view.findViewById(R.id.tvNext);
        nextScreen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "onClick: navigating to the final share screen.");

                if (isRootTask()) {
                    Intent intent = new Intent(getActivity(), NextActivity.class);
                    intent.putExtra(getString(R.string.selected_image), mSelectedImage);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(getActivity(), AccountSettingsActivity.class);
                    intent.putExtra(getString(R.string.selected_image), mSelectedImage);
                    intent.putExtra(getString(R.string.return_to_fragment), getString(R.string.edit_profile_fragment));
                    startActivity(intent);
                    getActivity().finish();
                }

            }
        });

       noPhoto.setOnClickListener(new View.OnClickListener(){
            public void onClick (View v) {

                mSelectedImage = null;
                Intent intent = new Intent(getActivity(), NextActivity.class);
                intent.putExtra(getString(R.string.nonselected_image), nonSelectedImage);
                startActivity(intent);

            }
        });
接收意图并根据传递的变量采取相应的操作

  public void onClick(View v) {
                Log.d(TAG, "onClick: navigating to the final share screen.");
                //upload the image to firebase
        //        Toast.makeText(NextActivity.this, "Attempting to upload new photo", Toast.LENGTH_SHORT).show();
                String caption = mCaption.getText().toString();

                if(intent.hasExtra(getString(R.string.selected_image))){
                    imgUrl = intent.getStringExtra(getString(R.string.selected_image));
                    Toast.makeText(NextActivity.this, "Attempting to upload a normal photo", Toast.LENGTH_SHORT).show();
                    mFirebaseMethods.uploadNewPhoto(getString(R.string.new_photo), caption, imageCount, imgUrl,null);
                }
                else if(intent.hasExtra(getString(R.string.selected_bitmap))){
                    bitmap = (Bitmap) intent.getParcelableExtra(getString(R.string.selected_bitmap));
                    Toast.makeText(NextActivity.this, "Attempting to upload a new bitmap", Toast.LENGTH_SHORT).show();
                    mFirebaseMethods.uploadNewPhoto(getString(R.string.new_photo), caption, imageCount, null,bitmap);
                }
                else if(intent.hasExtra(getString(R.string.nonselected_image)));{
                    Toast.makeText(NextActivity.this, "Attempting to upload new photo", Toast.LENGTH_SHORT).show();
                    imgUrl = intent.getStringExtra(getString(R.string.nonselected_image));
                  mFirebaseMethods.uploadNoPhoto(getString(R.string.new_photo), caption, imageCount, imgUrl, null); // HERE IS THE ERROR

                }

日志中有错误吗?没有一个错误,只是行为不端。你有没有让它工作过?还是你还需要帮助?不,我知道了,伙计