Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > จะแก้ไขข้อมูลจาก MySQL ผ่าน Android แต่เรียกข้อมูลไม่ขึ้นครับ ช่วยดูให้ทีครับ



 

จะแก้ไขข้อมูลจาก MySQL ผ่าน Android แต่เรียกข้อมูลไม่ขึ้นครับ ช่วยดูให้ทีครับ

 



Topic : 112758



โพสกระทู้ ( 4 )
บทความ ( 0 )



สถานะออฟไลน์




ข้อมูลไม่ขึ้นให้แก้ไขตามภาพนี้ครับ

จากตัวอย่างนี้ครับ
https://www.thaicreate.com/mobile/android-edit-update-server-database.html

อันนี้ LogCat ครับ

Error
11-22 13:12:14.125: W/System.err(1498): org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
11-22 13:12:14.125: W/System.err(1498): at org.json.JSON.typeMismatch(JSON.java:111)
11-22 13:12:14.135: W/System.err(1498): at org.json.JSONObject.<init>(JSONObject.java:158)
11-22 13:12:14.135: W/System.err(1498): at org.json.JSONObject.<init>(JSONObject.java:171)
11-22 13:12:14.135: W/System.err(1498): at com.farmone.VacUpdate.showInfo(VacUpdate.java:118)
11-22 13:12:14.165: W/System.err(1498): at com.farmone.VacUpdate.onCreate(VacUpdate.java:54)
11-22 13:12:14.165: W/System.err(1498): at android.app.Activity.performCreate(Activity.java:5104)
11-22 13:12:14.165: W/System.err(1498): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-22 13:12:14.165: W/System.err(1498): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-22 13:12:14.185: W/System.err(1498): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-22 13:12:14.185: W/System.err(1498): at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-22 13:12:14.195: W/System.err(1498): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-22 13:12:14.195: W/System.err(1498): at android.os.Handler.dispatchMessage(Handler.java:99)
11-22 13:12:14.225: W/System.err(1498): at android.os.Looper.loop(Looper.java:137)
11-22 13:12:14.225: W/System.err(1498): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-22 13:12:14.235: W/System.err(1498): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 13:12:14.254: W/System.err(1498): at java.lang.reflect.Method.invoke(Method.java:511)
11-22 13:12:14.254: W/System.err(1498): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-22 13:12:14.254: W/System.err(1498): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-22 13:12:14.265: W/System.err(1498): at dalvik.system.NativeStart.main(Native Method)




Tag : Mobile, MySQL, Android, Tablets, Mobile









ประวัติการแก้ไข
2014-11-22 20:23:28
2014-11-22 20:24:11
2014-11-22 20:24:25
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-11-22 20:22:00 By : Kyoshiro11 View : 1443 Reply : 3
 

 

No. 1



โพสกระทู้ ( 4 )
บทความ ( 0 )



สถานะออฟไลน์


อันนี้โค้ดที่ผมใช้คับครับ

Code (Android-Java)
package com.farmone;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
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.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;


public class VacUpdate extends Activity {
	   
    @SuppressLint("NewApi")
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vac_update);

        // Permission StrictMode
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        
        showInfo();
        
        // btnSave
        Button btnSave = (Button) findViewById(R.id.btnsave);
        // Perform action on click
        btnSave.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	if(SaveData())
            	{
            		// When Save Complete
        			Intent newActivity = new Intent(VacUpdate.this,VacShowData.class);
        			startActivity(newActivity);
            	}
            }
        });
        
    }
    
    public void showInfo()
    {
    	
    	  final TextView tName = (TextView)findViewById(R.id.txtName); 
    	  
          final TextView tEff = (TextView)findViewById(R.id.txtEff); 
          
          final TextView tDose = (TextView)findViewById(R.id.txtDose);    
          
          final TextView tDosetime = (TextView)findViewById(R.id.txtDosetime); 
          
          final TextView tUnit = (TextView)findViewById(R.id.txtUnit);  
          
          final TextView tPrice = (TextView)findViewById(R.id.txtPrice);
 
          
        //  final Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
          
          
    	
    	Button btnSave = (Button) findViewById(R.id.btnsave);
    	
    	String url = "http://10.0.2.2/Farmone/getByVaccineName.php";
    	
    	Intent intent= getIntent();
    	final String Namee = intent.getStringExtra("Namee"); 

		List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("sNamee", Namee));

        
        
    	String resultServer  = getHttpPost(url,params);
    	
        String strNamee = "";
    	String strEffect = "";
    	String strDose = "";
    	String strDoseTime = "";
    	String strUnit = "";
    	String strPrice = "";
    
    
    
    	
    	JSONObject c;
		try {
			c = new JSONObject(resultServer);
			strNamee = c.getString("Namee");
			strEffect = c.getString("Effect");
			strDose = c.getString("Dose");
			strDoseTime = c.getString("DoseTime");
			strUnit = c.getString("Unit");
			strPrice = c.getString("Price");
		
			
			
			if(!strNamee.equals(""))
			{
				tName.setText(strNamee);
				tEff.setText(strEffect);
				tDose.setText(strDose);
				tDosetime.setText(strDoseTime);
				tUnit.setText(strUnit);
				tPrice.setText(strPrice);
				
				
				
				
			}
			else
			{
				tName.setText("-");
				tEff.setText("-");
				tDose.setText("-");
				tDosetime.setText("-");
				tUnit.setText("-");
				tPrice.setText("-");
			
				
				
				btnSave.setEnabled(false);
		
			}
        	
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
    }
    
    
    public boolean SaveData()
    {
    	
        
        final TextView txtName = (TextView)findViewById(R.id.txtName); 
        final EditText txtEff = (EditText)findViewById(R.id.txtEff);
        final EditText txtDose = (EditText)findViewById(R.id.txtDose);
        final EditText txtDosetime = (EditText)findViewById(R.id.txtDosetime);       
        final EditText txtUnit = (EditText)findViewById(R.id.txtUnit);  
        final EditText txtPrice = (EditText)findViewById(R.id.txtPrice);  
        
        //final Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);      
     // Spinner Nipple
       // final Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
        
            
    		// Dialog
        	final AlertDialog.Builder ad = new AlertDialog.Builder(this);

    		ad.setTitle("Error! ");
    		ad.setIcon(android.R.drawable.btn_star_big_on); 
    		ad.setPositiveButton("Close", null);


    		// Check House
    		if(txtName.getText().length() == 0)
    		{
                ad.setMessage("กรุณากรอกข้อมูลโรงเรือน");
                ad.show();
                txtName.requestFocus();
                return false;
    		}
    	
  

     		String url = "http://10.0.2.2/Farmone/updateVaccine.php";
     		
    		List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("sNamee", txtName.getText().toString()));
            params.add(new BasicNameValuePair("sEffect", txtEff.getText().toString()));
            params.add(new BasicNameValuePair("sDose", txtDose.getText().toString()));
            params.add(new BasicNameValuePair("sDoseTime", txtDosetime.getText().toString()));
            
            params.add(new BasicNameValuePair("sUnit", txtUnit.getText().toString()));
            //txtNipple >> spinner1
         //  params.add(new BasicNameValuePair("sSex", spinner1.getSelectedItem().toString()));
            
            params.add(new BasicNameValuePair("sPrice", txtPrice.getText().toString()));
            
            //txtNipple >> spinner1
         //  params.add(new BasicNameValuePair("sSex", spinner1.getSelectedItem().toString()));
            
            
            /** Get result from Server (Return the JSON Code)
             * StatusID = ? [0=Failed,1=Complete]
             * Error	= ?	[On case error return custom error message]
             * 
             * Eg Save Failed = {"StatusID":"0","Error":"Email Exists!"}
             * Eg Save Complete = {"StatusID":"1","Error":""}
             */
        	
            String resultServer  = getHttpPost(url,params);
            
            /*** Default Value ***/
        	String strStatusID = "0";
        	String strError = "Unknow Status!";
        	
        	JSONObject c;
			try {
				c = new JSONObject(resultServer);
            	strStatusID = c.getString("StatusID");
            	strError = c.getString("Error");
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			// Prepare Save Data
			if(strStatusID.equals("0"))
			{
                ad.setMessage(strError);
                ad.show();
				return false;
			}
			else
			{
				Toast.makeText(VacUpdate.this, "แก้ไขข้อมูลเรียบร้อย", Toast.LENGTH_SHORT).show();
			}
       	            
    
    	return true;
    }
    
	public String getHttpPost(String url,List<NameValuePair> params) {
		StringBuilder str = new StringBuilder();
		HttpClient client = new DefaultHttpClient();
		HttpPost httpPost = new HttpPost(url);
		
		try {
			httpPost.setEntity(new UrlEncodedFormEntity(params));
			HttpResponse response = client.execute(httpPost);
			StatusLine statusLine = response.getStatusLine();
			int statusCode = statusLine.getStatusCode();
			if (statusCode == 200) { // Status OK
				HttpEntity entity = response.getEntity();
				InputStream content = entity.getContent();
				BufferedReader reader = new BufferedReader(new InputStreamReader(content));
				String line;
				while ((line = reader.readLine()) != null) {
					str.append(line);
				}
			} else {
				Log.e("Log", "Failed to download result..");
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str.toString();
	}
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    


@Override
public boolean onOptionsItemSelected(MenuItem item)
{
	
    switch (item.getItemId())
    {
    case R.id.menu1:
        Toast.makeText(VacUpdate.this, "กลับสู่เมนูหลัก", Toast.LENGTH_SHORT).show();
        Intent newActivity = new Intent(VacUpdate.this,MainMenu.class);
		startActivity(newActivity);
        return true;

   

    default:
        return super.onOptionsItemSelected(item);
    }
	
	}
}











ประวัติการแก้ไข
2014-11-22 20:27:53
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-22 20:25:40 By : Kyoshiro11
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

จาก Error เหมือนว่าจะมีปัญหาตั้งแต่ php แปลงค่าเป็น JSON ครับ มันมี Error หรือเปล่าครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-22 22:00:35 By : mr.win
 

 

No. 3



โพสกระทู้ ( 4 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 2 เขียนโดย : mr.win เมื่อวันที่ 2014-11-22 22:00:35
รายละเอียดของการตอบ ::

ลองจาก php ขึ้นแบบนี้คับควรแก้ตรงไหนคับ

php




ประวัติการแก้ไข
2014-11-25 22:17:21
2014-11-25 22:18:49
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-25 22:16:13 By : Kyoshiro11
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : จะแก้ไขข้อมูลจาก MySQL ผ่าน Android แต่เรียกข้อมูลไม่ขึ้นครับ ช่วยดูให้ทีครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่