无法解决putextra方法

时间:2019-08-01 08:48:52

标签: android android-intent

我正在尝试通过recyclerView中的意图将图像从数组列表中的一个活动发送到另一个活动。但是在putextra方法中,它显示错误,例如无法解析方法'putextra(java.lang.string,android.widget.imageview)'

    ngOnInit(): void {
        this.someObs.subscribe((elem: SomeType) => {
            /* some code */
        });
    }

3 个答案:

答案 0 :(得分:0)

您不能额外传递ImageView,您传递的对象必须是Parcelable或Serialiazable。

您的ImageView也仅与此活动有关。如果您尝试将图像发送到另一个活动,最好将路径发送到图像。

答案 1 :(得分:0)

您不能直接发送Sub Macro1() Dim rng As Range, cell As Range Set rng = Range("A3:A15") For Each cell In rng Range("A" & cell.Row & ":D" & cell.Row).Copy Range("W" & cell.Row).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("E" & cell.Row & ":H" & cell.Row).Copy Range("W" & cell.Row + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("I" & cell.Row).Copy Range("S" & cell.Row).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("R" & cell.Row + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("J" & cell.Row).Copy Range("Q" & cell.Row & ":Q" & cell.Row + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("W" & cell.Row & ":W" & cell.Row + 1).Copy Range("P" & cell.Row).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("W" & cell.Row).Copy Range("AF" & cell.Row + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("W" & cell.Row + 1).Copy Range("AF" & cell.Row).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("AA" & cell.Row & ":AE" & cell.Row + 1).Copy 'Range("AA5").Select ActiveSheet.Paste 'Range("Q8").Select Next cell End Sub ,因为image不支持

尝试此解决方案

例如,您可以使用intent发送image

ByteArray
结果活动类的holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageView img = images.get(position); img.buildDrawingCache(); Bitmap bmp = ((BitmapDrawable)img.getDrawable()).getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); Intent intent = new Intent(this, Result.class); intent.putExtra("Image", byteArray); context.startActivity(intent); } }); 中的

onCreate()

来源 Passing image from one activity another activity

答案 2 :(得分:0)

最后,我终于做到了,您只是创建了一个图像数组(注意:不要创建arrayList),以防万一您想在多个图像之间进行选择,并简单地将这些图像传递给整数。下面是代码...

onBindViewHolder(MyViewHolder持有人,最终int位置)上的public void {

Fit.Polynomial
System.Double[]
0, 1.5, 0.500000000000001

Polynomial.Fit
1.5x + 0.500000000000001x^2

//针对性活动

public void getdata(){

def model(input,training = True):

    parameters = []

    with tf.name_scope('conv1_1') as scope:
            kernel11 = tf.Variable(tf.truncated_normal([3, 3, 20, 32], dtype = tf.float64, stddev = 1e-1), name = 'kernel') 
            biases11 = tf.Variable(tf.constant(0.0, shape = [32], dtype = tf.float64),trainable = True, name = 'biases')
            conv = tf.nn.conv2d(input, kernel11, [1, 1, 1, 1], padding = 'SAME') 
            output11 = tf.nn.bias_add(conv, biases11)

            conv1_1 = tf.nn.relu(output11)
            parameters += [kernel11, biases11]


    #conv1_2
    with tf.name_scope('conv1_2') as scope:
            kernel12 = tf.Variable(tf.truncated_normal([3, 3, 32, 32], dtype=tf.float64, stddev=1e-1), name='kernel') 
            biases12 = tf.Variable(tf.constant(0.0, shape=[32], dtype=tf.float64), trainable=True, name='biases')
            conv = tf.nn.conv2d(conv1_1, kernel12, [1, 1, 1, 1], padding='SAME')
            output12 = tf.nn.bias_add(conv, biases12)
            conv1_2 = tf.nn.relu(output12)
            parameters += [kernel12, biases12]

    #pooling layer1
    pool1 = tf.nn.max_pool(conv1_2, 
                                ksize = [1, 2, 2, 1], 
                                strides = [1, 2, 2, 1],  #stride in model01_deconv is [1, 2, 2, 2, 1]
                                padding = 'SAME', 
                                name = 'pool1')


    #conv2_1
    with tf.name_scope('conv2_1') as scope:
            kernel21 = tf.Variable(tf.truncated_normal([3, 3, 32, 64], dtype = tf.float64, stddev = 1e-1), name = 'kernel')
            biases21 = tf.Variable(tf.constant(0.0, shape=[64], dtype=tf.float64), trainable=True, name='biases')
            conv = tf.nn.conv2d(pool1, kernel21, [1, 1, 1, 1], padding='SAME')
            output21 = tf.nn.bias_add(conv, biases21)
            conv2_1 = tf.nn.relu(output21)
            parameters += [kernel21, biases21]



    #conv2_2
    with tf.name_scope('conv2_2') as scope:
            kernel22 = tf.Variable(tf.truncated_normal([3, 3, 64, 64], dtype = tf.float64, stddev = 1e-1), name = 'kernel')
            biases22 = tf.Variable(tf.constant(0.0, shape=[64], dtype=tf.float64), trainable=True, name='biases')
            conv = tf.nn.conv2d(conv2_1, kernel22, [1, 1, 1, 1], padding='SAME')
            output22 = tf.nn.bias_add(conv, biases22)
            conv2_2 = tf.nn.relu(output22)
            parameters += [kernel22, biases22]
    print("************* conv2_2 ******************* \n")    

    #pooling layer2
    pool2 = tf.nn.max_pool(conv2_2, 
                                ksize = [1, 2, 2, 1], 
                                strides = [1, 2, 2, 1],
                                padding = 'SAME', 
                                name = 'pool2')

    #conv3_1
    with tf.name_scope('conv3_1') as scope:
            kernel31 = tf.Variable(tf.truncated_normal([3, 3, 64, 128], dtype = tf.float64, stddev = 1e-1), name = 'kernel')
            biases31 = tf.Variable(tf.constant(0.0, shape=[128], dtype=tf.float64), trainable=True, name='biases')
            conv = tf.nn.conv2d(pool2, kernel31, [1, 1, 1, 1], padding='SAME')
            output31 = tf.nn.bias_add(conv, biases31)
            conv3_1 = tf.nn.relu(output31)
            parameters += [kernel31, kernel31]



    #conv3_2
    with tf.name_scope('conv3_2') as scope:
            kernel32 = tf.Variable(tf.truncated_normal([3, 3, 128, 128], dtype = tf.float64, stddev = 1e-1), name = 'kernel')
            biases32 = tf.Variable(tf.constant(0.0, shape=[128], dtype=tf.float64), trainable=True, name='biases')
            conv = tf.nn.conv2d(conv3_1, kernel32, [1, 1, 1, 1], padding='SAME')
            output32 = tf.nn.bias_add(conv, biases32)
            conv3_2 = tf.nn.relu(output32)
            parameters += [kernel32, biases32]


    #conv3_3
    with tf.name_scope('conv3_3') as scope:
            kernel33 = tf.Variable(tf.truncated_normal([3, 3, 128, 128], dtype = tf.float64, stddev = 1e-1), name = 'kernel')
            biases33 = tf.Variable(tf.constant(0.0, shape=[128], dtype=tf.float64), trainable=True, name='biases')
            conv = tf.nn.conv2d(conv3_2, kernel33, [1, 1, 1, 1], padding='SAME')
            output33 = tf.nn.bias_add(conv, biases33)
            conv3_3 = tf.nn.relu(output33)
            parameters += [kernel33, biases33]



    #pooling layer3
    pool3 = tf.nn.max_pool(conv3_3, 
                                ksize = [1, 2, 2, 1], 
                                strides = [1, 2, 2, 1],
                                padding = 'SAME', 
                                name = 'pool3')


    #conv4_1
    with tf.name_scope('conv4_1') as scope:
            kernel41 = tf.Variable(tf.truncated_normal([3, 3, 128, 256], dtype = tf.float64, stddev = 1e-1), name = 'kernel')
            biases41 = tf.Variable(tf.constant(0.0, shape=[256], dtype=tf.float64), trainable=True, name='biases')
            conv = tf.nn.conv2d(pool3, kernel41, [1, 1, 1, 1], padding='SAME')
            output41 = tf.nn.bias_add(conv, biases41)
            conv4_1 = tf.nn.relu(output41)
            parameters += [kernel41, biases41]



    #conv4_2
    with tf.name_scope('conv4_2') as scope:
            kernel42 = tf.Variable(tf.truncated_normal([3, 3, 256, 256], dtype = tf.float64, stddev = 1e-1), name = 'kernel')
            biases42 = tf.Variable(tf.constant(0.0, shape=[256], dtype=tf.float64), trainable=True, name='biases')
            conv = tf.nn.conv2d(conv4_1, kernel42, [1, 1, 1, 1], padding='SAME')
            output42 = tf.nn.bias_add(conv, biases42)
            conv4_2 = tf.nn.relu(output42)
            parameters += [kernel42, biases42]




    #conv4_3
    with tf.name_scope('conv4_3') as scope:
            kernel43 = tf.Variable(tf.truncated_normal([3, 3, 256, 256], dtype = tf.float64, stddev = 1e-1), name = 'kernel')
            biases43 = tf.Variable(tf.constant(0.0, shape=[256], dtype=tf.float64), trainable=True, name='biases')
            conv = tf.nn.conv2d(conv4_2, kernel43, [1, 1, 1, 1], padding='SAME')
            output43 = tf.nn.bias_add(conv, biases43)
            conv4_3 = tf.nn.relu(output43)
            parameters += [kernel43, biases43]



   #pooling layer4
    pool4 = tf.nn.max_pool(conv4_3, 
                                ksize = [1, 2, 2, 1], 
                                strides = [1, 2, 2, 1],
                                padding = 'SAME', 
                                name = 'pool4')


    #FC 1        
    with tf.name_scope('fc1') as scope:
            shape = int(np.prod(pool4.get_shape()[1:]))
            fc1w = tf.Variable(tf.truncated_normal([shape, 4096], dtype = tf.float64, stddev = 1e-1), name = 'kernel')
            fc1b = tf.Variable(tf.constant(1.0, shape = [4096], dtype = tf.float64), trainable = True, name =  'biases')
            pool5_flat = tf.reshape(pool4, [-1, shape])
            fc1l = tf.nn.bias_add(tf.matmul(pool5_flat, fc1w), fc1b)
            fc1 = tf.nn.relu(fc1l)
            parameters += [fc1w, fc1b]

    #FC2
    with tf.name_scope('fc2') as scope:
            fc2w = tf.Variable(tf.truncated_normal([4096, 4096], dtype = tf.float64, stddev = 1e-1), name = 'kernel')
            fc2b = tf.Variable(tf.constant(1.0, shape = [4096], dtype = tf.float64), trainable = True, name =  'biases')
            fc2l = tf.nn.bias_add(tf.matmul(fc1, fc2w), fc2b)
            fc2 = tf.nn.relu(fc2l)
            parameters += [fc2w, fc2b]

    #FC3
    with tf.name_scope('fc3') as scope:
            fc3w = tf.Variable(tf.truncated_normal([4096, 3], dtype=tf.float64, stddev=1e-1), name='kernel') #[4096, 1000] but i put 3: the shape of the bbox
            fc3b = tf.Variable(tf.constant(1.0, shape=[3], dtype=tf.float64), trainable=True, name='biases') #shape=[1000]
            fc3l = tf.nn.bias_add(tf.matmul(fc2, fc3w), fc3b)
            parameters += [fc3w, fc3b]  

    print(' Done with convolution..')

    return fc3l

def train(batch_size,lr =lr_rate, epochs_tr = epochs, training = True):


    init_op_glob = tf.global_variables_initializer()

    init_op_local = tf.local_variables_initializer()

 with tf.Session() as sess:
        print("############################### Start Training ################################# \n")
#        vgg = model(x)


        dataset = dataloader(bin_path, label_path, calib_path,batch_size)      

        sess.run([init_op_glob, init_op_local])
        print(" Hiiii I'm Here 0000 \n ")

        train_loss = []
        test_loss = []
        train_accuracy = []
        test_accuracy = []

        #initializing the variables


        summary_writer = tf.summary.FileWriter('./OutputResult', sess.graph)


        for epoch in range(epochs_tr):
            print(" ######################################### Epoch ",epoch," ################################# \n", )
            for data in dataset: 




                prediction_box = sess.run(model(x, training = True), feed_dict = {x : data[0]})

                box = create_bbox(data[1],data[2],dataformat="bin", label_type="txt", is_velo_cam=True)
                print(" Hiiii I'm Here 3 \n ")


                loss = loss_function(prediction_box, box)


                optimizer = create_optimizer(lr, loss)
                opt = sess.run(optimizer)
                loss, acc = sess.run([loss, accuracy])

            print("Iteration " + str(epoch) + ", Loss = " + \
                                "{:.6f}".format(loss) + ", Training Accuracy = " + \
                                "{:.5f}".format(acc))

            print("Optimization is Finished ")

            train_loss.append(loss)
            train_accuracy.append(acc)

        summary_writer.close()

        plt.plot(range(len(train_loss)), train_loss, 'b', label = 'Training_loss')
        plt.title('Trainig loss')
        plt.xlabel('Epochs', fontsize = 16)
        plt.ylabel('Loss', fontsize =16)
        plt.legend()
        plt.figure()
        plt.show()

        plt.plot(range(len(train_accuracy)), train_accuracy, 'b', label='Training Accuracy')
        plt.title('Training Accuracy')
        plt.xlabel('Epochs ',fontsize=16)
        plt.ylabel('Loss',fontsize=16)
        plt.legend()
        plt.figure()
        plt.show()

//然后在onCreate方法中调用“ getdata();”