我没有通过正确的标题值

时间:2018-06-25 03:49:09

标签: java android android-studio

这是我的Java文件,我没有获得正确的title值传递给localweb 通过此行发送值

  

.appendQueryParameter(“ Title”,textviewtitle.setText(title);)

我使用什么参数发送正确的值而不是上面的行,该文件从另一个活动获取意图数据,但是在textview中它显示正确的标题并且没有发送正确的值作为参数

fullview.java

package com.desktop.app;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static android.support.v7.app.AlertDialog.*;
import static com.desktop.app.Stitle.EXTRA_AUTHOR;
import static com.desktop.app.Stitle.EXTRA_HR;
import static com.desktop.app.Stitle.EXTRA_PUBLISHER;
import static com.desktop.app.Stitle.EXTRA_PUBY;
import static com.desktop.app.Stitle.EXTRA_RAK;
import static com.desktop.app.Stitle.EXTRA_STATUS;
import static com.desktop.app.Stitle.EXTRA_TITLE;
import static com.desktop.app.Stitle.EXTRA_VR;

public class fullview extends AppCompatActivity {

    Button location, avail, request;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fullview);

        Intent intent = getIntent();
        String title = intent.getStringExtra(EXTRA_TITLE);
        String author = intent.getStringExtra(EXTRA_AUTHOR);
        String publisher = intent.getStringExtra(EXTRA_PUBLISHER);
        int  puby = intent.getIntExtra(EXTRA_PUBY,0);
         final int  rak = intent.getIntExtra(EXTRA_RAK,0);
         final int  hr = intent.getIntExtra(EXTRA_HR,0);
         final int  vr = intent.getIntExtra(EXTRA_VR,0);
        final String status = intent.getStringExtra(EXTRA_STATUS);

        TextView textviewtitle = findViewById(R.id.textviewtitle);
        TextView textViewAuthor = findViewById(R.id.textviewauthors);
        TextView textViewPublisher = findViewById(R.id.textviewpublisher);
        TextView textViewPuby = findViewById(R.id.textviewpubyear);

        textviewtitle.setText(title);
        textViewAuthor.setText(author);
        textViewPublisher.setText(publisher);
        textViewPuby.setText(String.valueOf(puby));

        location = findViewById(R.id.loc);
        location.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                AlertDialog.Builder a_builder = new AlertDialog.Builder(fullview.this);
//                a_builder.setMessage("Location");
                {
                    AlertDialog.Builder builder=new AlertDialog.Builder(fullview.this);

                    builder.setTitle("Location");
                    builder.setMessage("Rak-No :: " + rak +  "\nColumn :: " + hr +"\nRow :: " + vr);
                    AlertDialog alertDialog=null;

                    builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(fullview.this,"Closed",Toast.LENGTH_SHORT).show();
                        }
                    });//.setNegativeButton("no", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//
//                        }
//                    });
                    alertDialog=builder.create();
                    alertDialog.show();
                }

            }
        });

        avail = findViewById(R.id.avail);
        avail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view)
                {
                    AlertDialog.Builder builder=new AlertDialog.Builder(fullview.this);
                    {
                        if (status.equals("yes")) {
                            builder.setTitle("Availablity");
                            builder.setMessage("Available");
                        } else {
                        builder.setTitle("Availablity");
                        builder.setMessage("Not Available");
                    }
                    }
                    AlertDialog alertDialog=null;

                    builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(fullview.this,"Closed",Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog=builder.create();
                    alertDialog.show();
                }
        });
        request= findViewById(R.id.request);
        request.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                request();
            }
        });

    }
    private void request(){


        //String url= "http://192.168.0.136/fyp/bookreq.php";
        final RequestQueue requestQueue = Volley.newRequestQueue(fullview.this);
        Uri.Builder builder=new Uri.Builder();
        builder.scheme("http")
                .authority("192.168.0.136")
                .appendPath("fyp")
                .appendPath("bookreq.php")
                .appendQueryParameter("Title",textviewtitle.setText(title););
                Log.i("Info",textviewtitle.setText(title););
        StringRequest stringRequest = new StringRequest(Request.Method.POST, builder.build().toString(), new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                if (response.trim().equals("successfull")){
                    Toast.makeText(getApplicationContext(), "Go to Admin For Approval",Toast.LENGTH_LONG).show();
                    Intent in = new Intent(fullview.this,Search.class);
                    startActivity(in);

                }
                else {
                    Toast.makeText(getApplicationContext(), "Already Requested",Toast.LENGTH_LONG).show();
                }

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(getApplicationContext(), "error:" +error.toString() ,Toast.LENGTH_LONG).show();

            }
        });

        requestQueue.add(stringRequest);


    }

    }
  

06-25 08:35:33.436 2682-2682 / com.desktop.app W / IInputConnectionWrapper:非活动InputConnection上的finishComposedText

     

06-25 08:35:35.449 2682-2737 / com.desktop.app I / Info:标题

这是信息显示值标题,而不是正确的值

  

06-25 08:35:30.507 2682-2682 / com.desktop.app I / Info:{“ ss”:true,“ search”:[{“ isbn”:195472462,“ title”:“ Oxford Practice Grammer”,“ authors”:“ john Eastwood”,“ accession”:1,“ publisher”:“ Ameena Saiyid Oxford University”,“ pubyear”:2014,“ pages”:432,“ rak”:1,“ hr” :1,“ vr”:1,“条形码”:195472462,“ status”:“是”},{“ isbn”:9694946719,“ title”:“高中英语Grammer”,“ authors”:“ Wren,Martin “,” accession“:4,” publisher“:” Paramount Publishing“,” pubyear“:2010,” pages“:418,” rak“:1,” hr“:1,” vr“:4,” barcode“ :9694946719,“状态”:“是”}]}   06-25 08:35:30.585 2682-2682 / com.desktop.app W / IInputConnectionWrapper:非活动InputConnection上的finishComposedText       非活动InputConnection上的finishComposedText

这是我在上述信息中获得的正确标题

1 个答案:

答案 0 :(得分:0)

  当应用程序尝试使用

NullPointerException   具有空值的对象引用。

首先,请确保设置 PROPER ID

TextView textviewtitle; // Global


@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fullview);

        textviewtitle = findViewById(R.id.textviewtitle); // Check this id

注意

  

appendQueryParameter(字符串键,                   字符串值)

您应该设置

.appendQueryParameter("Title",textviewtitle.getText().toString());