1

我想为android创建一个应用程序。此应用程序必须与网关(以太网/Lon)进行通信。这个网关比生成两个 java 类的 POM.xml 交付:-ILON100.class -ILON100PortType.class 我按照他们的说明和教程,我在 Eclipse 中创建了一个 java 项目。该项目改变了网关的两个状态继电器并获得了它们的新位置。该项目运行正常。

现在我想用一个 Android 项目创建相同的项目。我使用相同的 javacode 创建项目并且我的项目正在运行,但是当我尝试更改继电器的状态时。当我在 java 中运行我的新项目时,当我在 Android 中使用 AVD 运行我的项目时,我的项目停止。我通过以下行代码在 Android 中执行字体“Recup”:“Client.Recup();” 在我的主要课程“Principal.java”中。

我的 Logcat 错误是:

11-02 10:50:44.461: E/AndroidRuntime(665): FATAL EXCEPTION: main
11-02 10:50:44.461: E/AndroidRuntime(665): java.lang.IllegalStateException: Could not execute method of the activity
11-02 10:50:44.461: E/AndroidRuntime(665):         at android.view.View$1.onClick(View.java:3591)
11-02 10:50:44.461: E/AndroidRuntime(665):         at android.view.View.performClick(View.java:4084)
11-02 10:50:44.461: E/AndroidRuntime(665):         at android.view.View$PerformClick.run(View.java:16966)
11-02 10:50:44.461: E/AndroidRuntime(665):         at android.os.Handler.handleCallback(Handler.java:615)
11-02 10:50:44.461: E/AndroidRuntime(665):         at android.os.Handler.dispatchMessage(Handler.java:92)
11-02 10:50:44.461: E/AndroidRuntime(665):         at android.os.Looper.loop(Looper.java:137)
11-02 10:50:44.461: E/AndroidRuntime(665):         at android.app.ActivityThread.main(ActivityThread.java:4745)
11-02 10:50:44.461: E/AndroidRuntime(665):         at java.lang.reflect.Method.invokeNative(Native Method)
11-02 10:50:44.461: E/AndroidRuntime(665):         at java.lang.reflect.Method.invoke(Method.java:511)
11-02 10:50:44.461: E/AndroidRuntime(665):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-02 10:50:44.461: E/AndroidRuntime(665):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-02 10:50:44.461: E/AndroidRuntime(665):         at dalvik.system.NativeStart.main(Native Method)
11-02 10:50:44.461: E/AndroidRuntime(665): Caused by: java.lang.reflect.InvocationTargetException
11-02 10:50:44.461: E/AndroidRuntime(665):         at java.lang.reflect.Method.invokeNative(Native Method)
11-02 10:50:44.461: E/AndroidRuntime(665):         at java.lang.reflect.Method.invoke(Method.java:511)
11-02 10:50:44.461: E/AndroidRuntime(665):         at android.view.View$1.onClick(View.java:3586)
11-02 10:50:44.461: E/AndroidRuntime(665):         ... 11 more
11-02 10:50:44.461: E/AndroidRuntime(665): Caused by: java.lang.NoClassDefFoundError: com.echelon.wsdl.web_services_ns.ilon100.v4_0.wsdl.ILON100
11-02 10:50:44.461: E/AndroidRuntime(665):         at com.echelon.sample.client.ilon.Client.Recup(Client.java:25)
11-02 10:50:44.461: E/AndroidRuntime(665):         at com.echelon.sample.client.ilon.Principal.test(Principal.java:23)
11-02 10:50:44.461: E/AndroidRuntime(665):         ... 14 more
11-02 10:50:49.991: I/Process(665): Sending signal. PID: 665 SIG: 9

客户端类:

package com.echelon.sample.client.ilon;

import com.echelon.wsdl.web_services_ns.ilon100.v4_0.message.DpData;
import com.echelon.wsdl.web_services_ns.ilon100.v4_0.message.EXSelect;
import com.echelon.wsdl.web_services_ns.ilon100.v4_0.message.ItemColl;
import com.echelon.wsdl.web_services_ns.ilon100.v4_0.message.ItemDataColl;
import com.echelon.wsdl.web_services_ns.ilon100.v4_0.wsdl.ILON100;
import com.echelon.wsdl.web_services_ns.ilon100.v4_0.wsdl.ILON100PortType;

public class Client
{

    public static void main (String[] args)
    {
        Recup();
    }

    public static void Recup()
    {
        ILON100 iLon100 = null;
        ILON100PortType SmartServer = null;
        try
        {
            iLon100 = new ILON100();
            SmartServer = (iLon100).getILON100HttpPort();
                try 
                {
                    // _________________________
                    // Soap::List
                    EXSelect xSelect = new EXSelect();
                    xSelect.setXSelect("//Item[@xsi:type=\"Dp_Cfg\"][contains(UCPTname,\"nviClaValue\")]");
                    ItemColl itemColl = SmartServer.list(xSelect);
                    if(0 < itemColl.getUCPTfaultCount()) {
                        System.out.printf("List-Response contains %s faults\r\n",itemColl.getUCPTfaultCount());
                    }
                    // just print the returned count of Item-s
                    System.out.println("Items returned = " + itemColl.getItem().size());
                    if(itemColl.getItem().size()> 0) 
                    {
                        // _________________________
                        // Soap::Read
                        ItemDataColl itemDataColl = SmartServer.read(itemColl);
                        if(0 < itemDataColl.getUCPTfaultCount()) 
                        {
                            System.out.printf("Read-Response contains %s faults\r\n",itemColl.getUCPTfaultCount());
                        }
                        // just print some properties
                        for (int i = 0; i <itemColl.getItem().size(); i++)
                        {
                            System.out.print(((DpData)(itemDataColl.getItem().get(i))).getUCPTname()+ " = ");
                            System.out.print(((DpData)(itemDataColl.getItem().get(i))).getUCPTvalue().get(0).getValue() + "(Value Read)" + "\r\n");
                            DpData dpData = (DpData) itemDataColl.getItem().get(i);
                            if(dpData.getUCPTvalue().get(0).getValue().compareTo ("0.0 0")== 0)
                            {
                                dpData.getUCPTvalue().get(0).setValue("100.0 1");
                                dpData.getUCPTvalue().get(1).setValue("ON");
                                itemDataColl.getItem().add(dpData);
                            }
                            else if(dpData.getUCPTvalue().get(0).getValue().compareTo ("100.0 1")== 0)
                            {
                                dpData.getUCPTvalue().get(0).setValue("0.0 0");
                                dpData.getUCPTvalue().get(1).setValue("OFF");
                                itemDataColl.getItem().add(dpData);
                            }
                        }
                        ItemColl writeResponse = SmartServer.write(itemDataColl);
                        if(writeResponse.getUCPTfaultCount()> 0)
                        {
                            // print out error and exit
                            System.out.println("An error occurred:");
                            for (int j = 0; j <itemColl.getItem().size(); j++)
                            {
                                System.out.println("Item: " + itemColl.getItem().get(j).getUCPTname() + ",fault code: " + itemColl.getItem().get(j).getFault().getFaultcode() + ",fault string: " + itemColl.getItem().get(j).getFault().getFaultstring());
                            }
                        }
                        else
                        {
                            // success
                            System.out.println("\r\n" + "Write is successful");
                            for (int j = 0; j <itemColl.getItem().size(); j++)
                            {
                                System.out.print(((DpData)(itemDataColl.getItem().get(j))).getUCPTname()+" = ");
                                System.out.print(((DpData)(itemDataColl.getItem().get(j))).getUCPTvalue().get(0).getValue()+ "(Value Written)" + "\r\n");
                            }
                        }
                    }
                }
                catch (Exception e) 
                {
                    System.out.println(e.getMessage());
                }
        }
        catch (Exception e) 
        {
            System.out.println(e.getMessage());
        }
        finally 
        {
            iLon100 = null;
            SmartServer = null;
        }
    }
}

校长类:

package com.echelon.sample.client.ilon;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class Principal extends Activity
{
    @Override
    public void onCreate (Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layoutclient);
    }

    public void test (View V)
    {
        TextView tvw_affiche;
        tvw_affiche=(TextView)this.findViewById(R.id.tvw_affiche);
        tvw_affiche.setText("");
        /*********************************************************/
        Client.Recup();
        /*********************************************************/
        tvw_affiche.setText("OK");
    }
}

ILON100.class:

package com.echelon.wsdl.web_services_ns.ilon100.v4_0.wsdl;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;

/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.7-b73 
 * Generated source version: 2.2
 * 
 */
@WebServiceClient(name = "iLON100", targetNamespace = "http://wsdl.echelon.com/web_services_ns/ilon100/v4.0/wsdl/", wsdlLocation = "file:/C:/Users/WIN7CLIMEL/workspace/ilon.ws.clients/jax-ws/src/wsdl/iLON100.wsdl")
public class ILON100
    extends Service
{

    private final static URL ILON100_WSDL_LOCATION;
    private final static WebServiceException ILON100_EXCEPTION;
    private final static QName ILON100_QNAME = new QName("http://wsdl.echelon.com/web_services_ns/ilon100/v4.0/wsdl/", "iLON100");

    static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = new URL("file:/C:/Users/WIN7CLIMEL/workspace/ilon.ws.clients/jax-ws/src/wsdl/iLON100.wsdl");
        } catch (MalformedURLException ex) {
            e = new WebServiceException(ex);
        }
        ILON100_WSDL_LOCATION = url;
        ILON100_EXCEPTION = e;
    }

    public ILON100() {
        super(__getWsdlLocation(), ILON100_QNAME);
    }

    public ILON100(WebServiceFeature... features) {
        super(__getWsdlLocation(), ILON100_QNAME, features);
    }

    public ILON100(URL wsdlLocation) {
        super(wsdlLocation, ILON100_QNAME);
    }

    public ILON100(URL wsdlLocation, WebServiceFeature... features) {
        super(wsdlLocation, ILON100_QNAME, features);
    }

    public ILON100(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public ILON100(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
        super(wsdlLocation, serviceName, features);
    }

    /**
     * 
     * @return
     *     returns ILON100PortType
     */
    @WebEndpoint(name = "iLON100httpPort")
    public ILON100PortType getILON100HttpPort() {
        return super.getPort(new QName("http://wsdl.echelon.com/web_services_ns/ilon100/v4.0/wsdl/", "iLON100httpPort"), ILON100PortType.class);
    }

    /**
     * 
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns ILON100PortType
     */
    @WebEndpoint(name = "iLON100httpPort")
    public ILON100PortType getILON100HttpPort(WebServiceFeature... features) {
        return super.getPort(new QName("http://wsdl.echelon.com/web_services_ns/ilon100/v4.0/wsdl/", "iLON100httpPort"), ILON100PortType.class, features);
    }

    private static URL __getWsdlLocation() {
        if (ILON100_EXCEPTION!= null) {
            throw ILON100_EXCEPTION;
        }
        return ILON100_WSDL_LOCATION;
    }
}

安卓清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.echelon.sample.client.ilon"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />   

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Client"
            android:label="@string/app_name" >
        </activity>   
        <activity
            android:name=".Principal"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />         
            </intent-filter>
        </activity>
     </application>
</manifest>

Fichier POM.xml

<?xml version="1.0" encoding="UTF-8" ?>
 <project
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.echelon.es</groupId>
    <artifactId>ilon-ws</artifactId>
    <version>4.03-SNAPSHOT</version>
    <name>ECHELON i.LON SmartServer</name>
    <packaging>jar</packaging>

    <properties>
        <ip-address-ilon>192.168.0.100</ip-address-ilon>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.2.7-promoted-b73</version>
        </dependency>

        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>1.5_r4</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>java.net</id>
            <url>http://download.java.net/maven/1/</url>
            <layout>legacy</layout>
        </repository>
        <repository>
            <id>java.net2</id>
            <url>http://download.java.net/maven/2/</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>java.net2</id>
            <url>http://download.java.net/maven/2/</url>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <!-- To define the plugin version  -->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.6</version>
                </plugin>
            </plugins>
        </pluginManagement>
                <sourceDirectory>src</sourceDirectory>
        <plugins>
              <plugin>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <configuration>
                      <source>1.5</source>
                      <target>1.5</target>
                  </configuration>
              </plugin>
            <!--  CALL: mvn javadoc:javadoc -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.6</version>
            </plugin>

            <!--  CALL: mvn jaxws:wsimport -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <verbose>true</verbose>
                    <!-- +++++++++++++++++++++++++++++++++ -->
                    <!--  get the WSDL file from the i.LON -->
                    <!-- +++++++++++++++++++++++++++++++++ -->
                    <!-- wsdlUrls>
                      <wsdlUrl>http://${ip-address-ilon}:80/WSDL/v4.0/iLON100.wsdl</wsdlUrl>
                    </wsdlUrls -->

                    <!-- +++++++++++++++++++++++++++++++++++++++ -->
                    <!--  get the WSDL file from the a directory -->
                    <!-- +++++++++++++++++++++++++++++++++++++++ -->
                    <wsdlDirectory>${basedir}/src/wsdl</wsdlDirectory>
                    <wsdlFiles>                
                        <wsdlFile>iLON100.wsdl</wsdlFile>
                    </wsdlFiles>
                    <!-- packageName>fromwsdl.client</packageName -->
                </configuration>

                <!-- if you want to use a specific version of JAX-WS -->
                <dependencies>
                    <dependency>
                        <groupId>com.sun.xml.ws</groupId>
                        <artifactId>jaxws-tools</artifactId>
                        <version>2.2.7-promoted-b73</version>
                    </dependency>
                </dependencies>            
              </plugin>

              <!-- Don't forget Java 5!!      -->
              <!-- CALL: mvn compiler:compile -->
              <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <verbose>true</verbose>
                        <source>1.5</source>
                        <target>1.5</target>
                    </configuration>
              </plugin>

              <!--  CALL: mvn source:jar -->
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-source-plugin</artifactId>
                  <executions>
                      <execution>
                          <id>attach-sources</id>
                          <phase>verify</phase>
                          <goals>
                              <goal>jar</goal>
                          </goals>
                      </execution>
                  </executions>
                  <configuration>
                      <verbose>true</verbose>
                  </configuration>            
              </plugin>          
        </plugins>
    </build>
    <reporting>
        <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.5</version>
        </plugin>
        </plugins>
    </reporting>    
</project>

好的。我提前感谢所有将解决我的问题的人。真挚地

4

0 回答 0