我最初是在我的UI中直接进行接口并且收到错误。我改为使用AsyncTask而不是之前的配置,我现在收到不同的错误错误。我不确定为什么会抛出这些错误。
LightsMainScreen.java
package com.lnrpuc.lnrpucseniordesign;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;
import com.lnrpuc.lnrpucseniordesign.LightTest1;
public class LightsMainScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lights_main);
Button returnBtn = (Button)findViewById(R.id.returnBtn);
ToggleButton light3Btn = (ToggleButton)findViewById(R.id.light_3);
light3Btn.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
new UpdateXML().execute(); } } ) ;
returnBtn.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
finish(); } } ) ;
}
private class UpdateXML extends AsyncTask<String, Void, Void>
{
ToggleButton light3Btn = (ToggleButton)findViewById(R.id.light_3);
protected Void doInBackground(String... params) {
if(light3Btn.isChecked()) LightTest1.XMLUpdate("1", "3", "1");
else LightTest1.XMLUpdate("1", "3", "0");
return null;
}
protected void onPostExecute() {}
@Override
protected void onPreExecute() {}
protected void onProgressUpdate() {}
}
}
LightTest1.java
package com.lnrpuc.lnrpucseniordesign;
import java.rmi.RemoteException;
import com.lnrpuc.Services.GetNamesRequestType;
import com.lnrpuc.Services.GetNamesResponseType;
import com.lnrpuc.Services.GetStatusRequestType;
import com.lnrpuc.Services.GetStatusResponseType;
import com.lnrpuc.Services.HomeAutomationServicePortTypeProxy;
import com.lnrpuc.Services.SetStatusRequestType;
import com.lnrpuc.Services.SetStatusResponseType;
public class LightTest1 {
public static void XMLUpdate(String object, String number, String status){
try {
HomeAutomationServicePortTypeProxy proxy = new HomeAutomationServicePortTypeProxy();
//names request
//GetNamesRequestType inGNRT = new GetNamesRequestType();
//inGNRT.setPass("12345");
//GetNamesResponseType outGNRT = proxy.getNames(inGNRT);
//System.out.println(outGNRT.get_return());
//status request
//GetStatusRequestType inGSRT = new GetStatusRequestType();
//inGSRT.setPass("12345");
//GetStatusResponseType outGSRT = proxy.getStatus(inGSRT);
//System.out.println(outGSRT.get_return());
//set status
SetStatusRequestType inSSRT = new SetStatusRequestType();
inSSRT.setPass("12345");
inSSRT.setObject(object);
inSSRT.setNumber(number);
inSSRT.setStatus(status);
SetStatusResponseType outSSRT = proxy.setStatus(inSSRT);
System.out.println(outSSRT.get_return());
} catch (RemoteException e) {
// TODO Auto-generated catch block
System.out.println("failed");
}
}
}
LogCat输出
02-06 13:53:38.759: I/dalvikvm(16012): Failed resolving Lcom/lnrpuc/Services/HomeAutomationServicePortType; interface 93 'Ljava/rmi/Remote;'
02-06 13:53:38.759: W/dalvikvm(16012): Link of class 'Lcom/lnrpuc/Services/HomeAutomationServicePortType;' failed
02-06 13:53:38.759: I/dalvikvm(16012): Failed resolving Lcom/lnrpuc/Services/HomeAutomationServicePortTypeProxy; interface 30 'Lcom/lnrpuc/Services/HomeAutomationServicePortType;'
02-06 13:53:38.759: W/dalvikvm(16012): Link of class 'Lcom/lnrpuc/Services/HomeAutomationServicePortTypeProxy;' failed
02-06 13:53:38.759: E/dalvikvm(16012): Could not find class 'com.lnrpuc.Services.HomeAutomationServicePortTypeProxy', referenced from method com.lnrpuc.lnrpucseniordesign.LightTest1.XMLUpdate
02-06 13:53:38.759: W/dalvikvm(16012): VFY: unable to resolve new-instance 31 (Lcom/lnrpuc/Services/HomeAutomationServicePortTypeProxy;) in Lcom/lnrpuc/lnrpucseniordesign/LightTest1;
02-06 13:53:38.759: D/dalvikvm(16012): VFY: replacing opcode 0x22 at 0x0000
02-06 13:53:38.759: W/dalvikvm(16012): VFY: unable to resolve exception class 94 (Ljava/rmi/RemoteException;)
02-06 13:53:38.759: W/dalvikvm(16012): VFY: unable to find exception handler at addr 0x26
02-06 13:53:38.759: W/dalvikvm(16012): VFY: rejected Lcom/lnrpuc/lnrpucseniordesign/LightTest1;.XMLUpdate (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
02-06 13:53:38.759: W/dalvikvm(16012): VFY: rejecting opcode 0x0d at 0x0026
02-06 13:53:38.769: W/dalvikvm(16012): VFY: rejected Lcom/lnrpuc/lnrpucseniordesign/LightTest1;.XMLUpdate (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
02-06 13:53:38.769: W/dalvikvm(16012): Verifier rejected class Lcom/lnrpuc/lnrpucseniordesign/LightTest1;
02-06 13:53:38.769: W/dalvikvm(16012): threadid=11: thread exiting with uncaught exception (group=0x417c0898)
02-06 13:53:38.769: E/AndroidRuntime(16012): FATAL EXCEPTION: AsyncTask #1
02-06 13:53:38.769: E/AndroidRuntime(16012): java.lang.RuntimeException: An error occured while executing doInBackground()
02-06 13:53:38.769: E/AndroidRuntime(16012): at android.os.AsyncTask$3.done(AsyncTask.java:299)
02-06 13:53:38.769: E/AndroidRuntime(16012): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
02-06 13:53:38.769: E/AndroidRuntime(16012): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
02-06 13:53:38.769: E/AndroidRuntime(16012): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
02-06 13:53:38.769: E/AndroidRuntime(16012): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-06 13:53:38.769: E/AndroidRuntime(16012): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-06 13:53:38.769: E/AndroidRuntime(16012): at java.lang.Thread.run(Thread.java:841)
02-06 13:53:38.769: E/AndroidRuntime(16012): Caused by: java.lang.VerifyError: com/lnrpuc/lnrpucseniordesign/LightTest1
02-06 13:53:38.769: E/AndroidRuntime(16012): at com.lnrpuc.lnrpucseniordesign.LightsMainScreen$UpdateXML.doInBackground(LightsMainScreen.java:41)
02-06 13:53:38.769: E/AndroidRuntime(16012): at com.lnrpuc.lnrpucseniordesign.LightsMainScreen$UpdateXML.doInBackground(LightsMainScreen.java:1)
02-06 13:53:38.769: E/AndroidRuntime(16012): at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-06 13:53:38.769: E/AndroidRuntime(16012): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-06 13:53:38.769: E/AndroidRuntime(16012): ... 3 more