Autore Topic: Interagire con dati di un db remoto  (Letto 463 volte)

Offline ccmex

  • Nuovo arrivato
  • *
  • Post: 41
  • Respect: 0
    • Mostra profilo
Interagire con dati di un db remoto
« il: 01 Marzo 2014, 11:23:37 CET »
0
Buongiorno a tutti.

Ho pubblicato la mia prima app android sul google play e sono molto soddisfatto per l'aiuto che ho ricevuto in questo forum.

La mia app utilizza un webservice dot net per collegarsi ad un db in remoto e mostrare alcuni dati nello smartphone.

Adesso avrei necessità di interagire con questi dati, cioè inserire dati nuovi, modificare ed aggiornare gli esistenti caricare delle foto tramite upload... avete qualche tutorial sottomano da potermi consigliare al fine di realizzare questo nuovo passo nella mia app ?

Grazie di cuore.

Offline ccmex

  • Nuovo arrivato
  • *
  • Post: 41
  • Respect: 0
    • Mostra profilo
Re:Interagire con dati di un db remoto
« Risposta #1 il: 02 Marzo 2014, 20:30:50 CET »
0
Ciao.

Sto provando ad inserire dei parametri provenienti da una app Android in un database MySQL con l'utilizzo di un Web Service ASP NET

Il Web Service ASP NET funziona correttamente, ma quando provo tramite l'applicazione Android questa va in crash, inspiegabilmente per me.

Il log cat di Eclipse:
Codice: [Seleziona]
03-02 20:22:46.200: E/SpannableStringBuilder(2095): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

03-02 20:22:46.200: E/SpannableStringBuilder(2095): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length


03-02 20:22:46.200: E/SpannableStringBuilder(2095): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length


03-02 20:22:46.200: E/SpannableStringBuilder(2095): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length


03-02 20:22:51.966: E/AndroidRuntime(2095): FATAL EXCEPTION: main


03-02 20:22:51.966: E/AndroidRuntime(2095): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxxx.xxxxx/com.xxxxx.xxxxx.callws}: java.lang.NullPointerException: println needs a message


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.app.ActivityThread.access$700(ActivityThread.java:140)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.os.Handler.dispatchMessage(Handler.java:99)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.os.Looper.loop(Looper.java:137)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.app.ActivityThread.main(ActivityThread.java:4935)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at java.lang.reflect.Method.invokeNative(Native Method)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at java.lang.reflect.Method.invoke(Method.java:511)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at dalvik.system.NativeStart.main(Native Method)


03-02 20:22:51.966: E/AndroidRuntime(2095): Caused by: java.lang.NullPointerException: println needs a message


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.util.Log.println_native(Native Method)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.util.Log.e(Log.java:297)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at com.xxxxx.xxxxx.callws.onCreate(callws.java:66)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.app.Activity.performCreate(Activity.java:5206)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)


03-02 20:22:51.966: E/AndroidRuntime(2095):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)


03-02 20:22:51.966: E/AndroidRuntime(2095):     ... 11 more



Spero possiate aiutarmi, grazie.

classe callws.java
Codice: [Seleziona]
package com.xxxxx.xxxxx;

import java.net.SocketException;


import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;


public class callws extends Activity {


    private static final String SOAP_ACTION = "[url=http://www.xxxxx.com/WebService/register";]xxxxx.com: The Leading XXX Site on the Net[/url]
    private static final String OPERATION_NAME = "register";
    private static final String WSDL_TARGET_NAMESPACE = "[url=http://www.xxxxx.com/WebServiceGoInsert";]xxxxx.com: The Leading XXX Site on the Net[/url]
    private static final String SOAP_ADDRESS = "[url=http://www.xxxxx.com/WebServiceGoInsert.asmx";]xxxxx.com: The Leading XXX Site on the Net[/url]


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ws);
       
        SoapObject Request = new SoapObject(WSDL_TARGET_NAMESPACE,
                OPERATION_NAME);


        Request.addProperty("fname", String.valueOf("Peppino"));
        Request.addProperty("lname", String.valueOf("DiCaprio"));
        Request.addProperty("email", String.valueOf("Peppino"));
        Request.addProperty("num", String.valueOf("Peppino"));
        Request.addProperty("locID", String.valueOf("10"));
        Request.addProperty("username", String.valueOf("Peppino"));
        Request.addProperty("password", String.valueOf("Peppino"));


        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);


        envelope.dotNet = true;
        envelope.setOutputSoapObject(Request);


        HttpTransportSE httptransport = new HttpTransportSE(SOAP_ADDRESS);


        TextView textView = new TextView(this);
        setContentView(textView);
       
        try {
            httptransport.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject) envelope.getResponse();
            int result = Integer.parseInt(response.getProperty(0).toString());
                        System.out.println(result);


            if (result == 1) {
                Toast.makeText(callws.this, "Dati correttamente inseriti", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(callws.this, "Riprova", Toast.LENGTH_LONG).show();
            }


        } catch (SocketException ex) {
            ex.printStackTrace();
            Log.e("Error", ex.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("Error", e.getMessage());
        }
    }
}
ws.xml
Codice: [Seleziona]
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:autoLink="web"
        android:linksClickable="true"
        android:text="@string/hello"
        android:textSize="160sp"
        android:textStyle="bold" />
   
</LinearLayout>