Java 帖子没有出现在Android上?

Java 帖子没有出现在Android上?,java,android,apache,http,post,Java,Android,Apache,Http,Post,嘿,所以我没有收到一个错误,但是我所有的日志都被启动了,除了HttpResponse之后的日志。我不知道为什么,在服务器端,我没有看到任何帖子进入的活动 这是我的密码: package com.sfsfdsfds; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; imp

嘿,所以我没有收到一个错误,但是我所有的日志都被启动了,除了HttpResponse之后的日志。我不知道为什么,在服务器端,我没有看到任何帖子进入的活动

这是我的密码:

package com.sfsfdsfds;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class wardrobe extends Activity{

    //set variable for the fields
    private EditText nameField;
    private Spinner typeField;
    private EditText colorField;
    private Spinner seasonField;
    private EditText sizeField;
    private EditText quantityField;
    private ImageView imageField;
    private ProgressBar progressBarField;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wardrobe);
        ImageView user_photo = (ImageView) findViewById(R.id.user_photo);

        //button for upload image
        Button uploadImageButton = (Button) findViewById(R.id.uploadImageButton);

        //button for posting details
        Button postWardrobe = (Button) findViewById(R.id.postButton);

        //Value of fields
        nameField = (EditText) findViewById(R.id.nameFieldWardrobeScreen);
        typeField = (Spinner) findViewById(R.id.typeFieldWardrobeScreen);
        colorField = (EditText) findViewById(R.id.colorFieldWardrobeScreen);
        seasonField = (Spinner) findViewById(R.id.seasonFieldWardrobeScreen);
        sizeField = (EditText) findViewById(R.id.sizeFieldWardrobeScreen);
        quantityField = (EditText) findViewById(R.id.quantityFieldWardrobeScreen);
        imageField = (ImageView) findViewById(R.id.user_photo);
        progressBarField = (ProgressBar) findViewById(R.id.progressBarWardrobe);
        progressBarField.setVisibility(View.GONE);


        //Creating spinner for select/options for type field
        Spinner spinnerType = (Spinner) findViewById(R.id.typeFieldWardrobeScreen); 
        ArrayAdapter<CharSequence> adapterTypeArray = ArrayAdapter.createFromResource(this,  R.array.type_array, android.R.layout.simple_spinner_item);
        adapterTypeArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerType.setAdapter(adapterTypeArray);

      //Creating spinner for select/options for season field
        Spinner spinnerSeason = (Spinner) findViewById(R.id.seasonFieldWardrobeScreen); 
        ArrayAdapter<CharSequence> adapterSeasonArray = ArrayAdapter.createFromResource(this,  R.array.season_array, android.R.layout.simple_spinner_item);
        adapterSeasonArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerSeason.setAdapter(adapterSeasonArray); 

       uploadImageButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

                //below allows you to open the phones gallery
                Image_Picker_Dialog();
            }

        });


       postWardrobe.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                    //validate input and that something was entered
                    if(nameField.getText().toString().length()<1 || colorField.getText().toString().length()<1 || sizeField.getText().toString().length()<1 || quantityField.getText().toString().length()<1) {

                        //missing required info (null was this  but lets see)
                        Toast.makeText(getApplicationContext(), "Please complete all sections!", Toast.LENGTH_LONG).show();
                    } else {
                        JSONObject dataWardrobe = new JSONObject();

                        try {
                            dataWardrobe.put("type", typeField.getSelectedItem().toString());
                            dataWardrobe.put("color", colorField.getText().toString());
                            dataWardrobe.put("season", seasonField.getSelectedItem().toString());
                            dataWardrobe.put("size", sizeField.getText().toString());
                            dataWardrobe.put("quantity", quantityField.getText().toString());               

                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                        //make progress bar visible
                        progressBarField.setVisibility(View.VISIBLE);

                        //execute the post request
                        new dataSend().postData(dataWardrobe);
                    }

                    //below should send data over

                }

            });    
    }

    // After the selection of image you will retun on the main activity with bitmap image
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
            {
                    super.onActivityResult(requestCode, resultCode, data);
                    if (requestCode == Utility.GALLERY_PICTURE)
                            {
                                    // data contains result
                                    // Do some task
                                    Image_Selecting_Task(data);
                            } else if (requestCode == Utility.CAMERA_PICTURE)
                            {
                                    // Do some task
                                    Image_Selecting_Task(data);
                            }
            }
    public void Image_Picker_Dialog()
    {

        AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
        myAlertDialog.setTitle("Pictures Option");
        myAlertDialog.setMessage("Select Picture Mode");

        myAlertDialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface arg0, int arg1)
                    {
                        Utility.pictureActionIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
                        Utility.pictureActionIntent.setType("image/*");
                        Utility.pictureActionIntent.putExtra("return-data", true);
                        startActivityForResult(Utility.pictureActionIntent, Utility.GALLERY_PICTURE);
                    }
            });

        myAlertDialog.setNegativeButton("Camera", new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface arg0, int arg1)
                    {
                        Utility.pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                        startActivityForResult(Utility.pictureActionIntent, Utility.CAMERA_PICTURE);
                    }
            });
        myAlertDialog.show();

    }

    public void Image_Selecting_Task(Intent data)
    {
        ImageView user_photo = (ImageView) findViewById(R.id.user_photo);

        try
            {
                Utility.uri = data.getData();
                if (Utility.uri != null)
                    {
                        // User had pick an image.
                        Cursor cursor = getContentResolver().query(Utility.uri, new String[]
                            { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
                        cursor.moveToFirst();
                        // Link to the image
                        final String imageFilePath = cursor.getString(0);

                        //Assign string path to File
                        Utility.Default_DIR = new File(imageFilePath);

                        // Create new dir MY_IMAGES_DIR if not created and copy image into that dir and store that image path in valid_photo
                        Utility.Create_MY_IMAGES_DIR();

                        // Copy your image 
                        Utility.copyFile(Utility.Default_DIR, Utility.MY_IMG_DIR);

                        // Get new image path and decode it
                        Bitmap b = Utility.decodeFile(Utility.Paste_Target_Location);

                        // use new copied path and use anywhere 
                        String valid_photo = Utility.Paste_Target_Location.toString();
                        b = Bitmap.createScaledBitmap(b, 150, 150, true);

                        //set your selected image in image view
                        user_photo.setImageBitmap(b);
                        cursor.close();

                    } else
                    {
                        Toast toast = Toast.makeText(this, "Sorry!!! You haven't selecet any image.", Toast.LENGTH_LONG);
                        toast.show();
                    }
            } catch (Exception e)
            {
                // you get this when you will not select any single image 
                Log.e("onActivityResult", "" + e);

            }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    //Calling code for different selected menu options
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch(item.getItemId()) {

            //show settings activity screen (main preference activity file)
            case R.id.wardrobe:
                Intent intent = new Intent(wardrobe.this, wardrobe.class);
                startActivity(intent);

            //if index button clicked in menu sub-menu options
            case R.id.matches:
                Toast.makeText(this, "matches was clicked!", 5).show();

            //if index button clicked in menu sub-menu options
            case R.id.worn:
                Toast.makeText(this, "worn was clicked!", 5).show();

            default:
        }

        return super.onOptionsItemSelected(item);
    }

    private class dataSend extends AsyncTask<JSONObject, Integer, Double> {

        protected Double doInBackground(JSONObject... params) {
            // TODO Auto-generated method stub
            postData(params[0]);
            return null;
        }

        protected void onPostExecute(Double result) {
            progressBarField.setVisibility(View.GONE);
            Toast.makeText(wardrobe.this, "info sent", Toast.LENGTH_LONG).show();
        }

        protected void onProgressUpdate(Integer... progress) {
            progressBarField.setProgress(progress[0]);
        }

        public void postData(JSONObject dataWardrobe) {

            Log.v("posting data", "poooooost");
            // Create a new HttpClient and Post Header
            //int TIMEOUT_MILLISEC = 10000;  // = 10 seconds
            HttpParams httpParams = new BasicHttpParams();
            //HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
            //HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
            HttpClient httpclient = new DefaultHttpClient(httpParams);

            HttpPost httppost = new HttpPost("http://127.0.0.1:3000/wardrobe");
            Log.v("posteed", "posteed url");
            try {
                Log.v("trying data", "prep");
                //add data
                 StringEntity se = new StringEntity( dataWardrobe.toString());  
                 se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                 httppost.setEntity(se);
                Log.v("posteed", "posteed 11");

                // execute http post request
                HttpResponse response = httpclient.execute(httppost);
                Log.v("posteed", "posteed 22");

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }
        }

    }



}
package com.sfdsfds;
导入java.io.File;
导入java.io.IOException;
导入java.util.ArrayList;
导入java.util.List;
导入org.apache.http.HttpResponse;
导入org.apache.http.NameValuePair;
导入org.apache.http.client.ClientProtocolException;
导入org.apache.http.client.HttpClient;
导入org.apache.http.client.entity.UrlEncodedFormEntity;
导入org.apache.http.client.methods.HttpPost;
导入org.apache.http.entity.ByteArrayEntity;
导入org.apache.http.entity.StringEntity;
导入org.apache.http.impl.client.DefaultHttpClient;
导入org.apache.http.message.BasicHeader;
导入org.apache.http.message.BasicNameValuePair;
导入org.apache.http.params.BasicHttpParams;
导入org.apache.http.params.HttpConnectionParams;
导入org.apache.http.params.HttpParams;
导入org.apache.http.protocol.http;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.app.Activity;
导入android.app.AlertDialog;
导入android.content.DialogInterface;
导入android.content.Intent;
导入android.database.Cursor;
导入android.graphics.Bitmap;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.text.Editable;
导入android.util.Log;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.ImageView;
导入android.widget.ProgressBar;
导入android.widget.Spinner;
导入android.widget.TextView;
导入android.widget.Toast;
公共课堂活动{
//为字段设置变量
私有编辑文本名称字段;
私有微调器类型字段;
私有文本颜色域;
私人纺纱机;
私人编辑文本大小字段;
私有EditText quantityField;
私有ImageView imageField;
私人ProgressBar progressBarField;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局、衣柜);
ImageView用户照片=(ImageView)findViewById(R.id.user\u照片);
//上传图像按钮
按钮uploadImageButton=(按钮)findViewById(R.id.uploadImageButton);
//用于发布详细信息的按钮
按钮后衣柜=(按钮)findViewById(R.id.postButton);
//字段值
nameField=(EditText)findViewById(R.id.nameFieldWardrobeScreen);
typeField=(微调器)findViewById(R.id.typeFieldWardrobeScreen);
colorField=(EditText)findViewById(R.id.colorFieldWardrobeScreen);
季节字段=(微调器)findViewById(R.id.seasonFieldWardrobeScreen);
sizeField=(EditText)findViewById(R.id.sizeFieldWardrobeScreen);
quantityField=(EditText)findViewById(R.id.quantityFieldWardrobeScreen);
imageField=(ImageView)findViewById(R.id.user\u照片);
progressBarField=(ProgressBar)findViewById(R.id.ProgressBard);
progressBarField.setVisibility(View.GONE);
//为“类型”字段的“选择/选项”创建微调器
微调器微调器类型=(微调器)findViewById(R.id.typeFieldWardrobeScreen);
ArrayAdapter adapterTypeArray=ArrayAdapter.createFromResource(这个,R.array.type\u数组,android.R.layout.simple\u微调器\u项);
adapterTypeArray.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
喷丝头类型。setAdapter(adapterTypeArray);
//为季节字段的选择/选项创建微调器
喷丝器喷丝器季节=(喷丝器)findViewById(R.id.SeasonalFieldWardrobeScreen);
ArrayAdapter Adapter SeasonArray=ArrayAdapter.createFromResource(这个,R.array.season\u数组,android.R.layout.simple\u微调器\u项);
adapterSeasonArray.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
喷丝头季节。设置适配器(适配器季节阵列);
uploadImageButton.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//下面允许您打开电话库
图像选择器对话框();
}
});
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//验证输入和输入的内容

if(nameField.getText().toString().length()我还没有详细阅读您的代码,但我怀疑一个重要的贡献者是:

    HttpPost httppost = new HttpPost("http://127.0.0.1:3000/wardrobe");
如果您使用的是emulator,则可能更希望连接到“10.0.2.2”。即:

主机环回接口的特殊别名(即主机上的127.0.0.1) 开发机器)

有关仿真器网络的更多详细信息,请参见此处:

这会仅仅取代127吗?另外,我实际上是将我的设备直接连接到我的计算机上,并在eclipse上运行它,如果这改变了什么的话?我尝试过这样做“”,但仍然没有什么感谢他帮了我的忙-基本上必须在清单中包括互联网权限