我为MSN应用程序编写代码,并将此应用程序连接到服务器ASP.NET 此代码在我的计算机中运行完美,但是当我在其他计算机上运行此代码时 它在这一行给我运行时错误
new SigninPerson(s1,s2);
错误:
could not find class 'com.example.hello.Signinperson' referenced from method
com.example.hello.MainActivity.GoToProfileActivity
代码:
public class MainActivity extends Activity {
public final String URL="http://10.0.2.2:47102/ProjectTwo/Service.asmx";
public final String NAMESPACE="http://tempuri.org/";
public final String METHOD= "signin";
public final String ACTION = "http://tempuri.org/signin";
private EditText EditTextEmail;
private EditText EditTextPass;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void GoToSignupActivity (View V)
{
Intent SignupAct = new Intent("com.example.hello.SignupActivity");
startActivity(Intent.createChooser(SignupAct, "Choose an Application"));
}
public void GoToProfileActivity (View V)
{
EditTextEmail = (EditText) findViewById(R.id.Edit_Text_Email);
EditTextPass = (EditText) findViewById(R.id.Edit_Text_Pass);
if (isEmptyEditText(EditTextEmail) | isEmptyEditText(EditTextPass))
{
showDialog(0);
}
else
{
String s1 = EditTextEmail.getText().toString().trim();
String s2 = EditTextPass.getText().toString().trim();
SigninPerson SIPerson = new SigninPerson(s1,s2);
SoapObject Req = new SoapObject(NAMESPACE, METHOD);
PropertyInfo p = new PropertyInfo();
p.setName("SIPerson");
p.setValue(SIPerson);
p.setType(SIPerson.getClass());
Req.addProperty(p);
SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
env.dotNet = true;
env.setOutputSoapObject(Req);
env.addMapping(NAMESPACE, "SigninPerson", new SigninPerson().getClass());
HttpTransportSE ahttp = new HttpTransportSE(URL);
SoapObject Res = null;
try
{
ahttp.call(ACTION, env);
Res = (SoapObject) env.getResponse();
}
catch (Exception ex)
{
ex.printStackTrace();
}
if (Integer.parseInt(Res.getProperty(0).toString())==0)
{
showDialog(1);
}
else
{
SIPerson.Person_Id = Integer.parseInt(Res.getProperty(0).toString());
SIPerson.F_Name = Res.getPropertyAsString(1).toString();
SIPerson.L_Name = Res.getPropertyAsString(2).toString();
SIPerson.E_Mail = Res.getPropertyAsString(3).toString();
SIPerson.Password = Res.getPropertyAsString(4).toString();
Intent ProfileAct = new Intent("com.example.hello.ProfileActivity");
ProfileAct.putExtra("ReciveLogin", SIPerson);
startActivity(Intent.createChooser(ProfileAct, "Choose an Application"));
}
}
}
public boolean isEmptyEditText (EditText ET)
{
boolean isEmpty = true;
if (ET.getText().toString().trim().length() > 0)
{
isEmpty = false;
}
return isEmpty;
}
@Override
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case 0:
Dialog EnterBothDialog = new Dialog(this);
EnterBothDialog.setTitle("Please Enter Both E-Mail / Password");
return EnterBothDialog;
case 1:
Dialog InvalidEmPass = new Dialog(this);
InvalidEmPass.setTitle("Invalid Email / Password");
return InvalidEmPass;
}
return null;
}
}
这是SigninPerson
public class SigninPerson implements KvmSerializable, Serializable {
public int Person_Id;
public String F_Name;
public String L_Name;
public String E_Mail;
public String Password;
public SigninPerson ()
{
}
public SigninPerson (int id, String Fname, String Lname, String Email, String Pass)
{
Person_Id = id;
F_Name = Fname;
L_Name = Lname;
E_Mail = Email;
Password = Pass;
}
public SigninPerson (String Email, String Pass)
{
Person_Id = 0;
F_Name = "";
L_Name = "";
}
@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
switch (arg0)
{
case 0:
return Person_Id;
case 1:
return F_Name;
case 2:
return L_Name;
case 3:
return E_Mail;
case 4:
return Password;
}
return null;
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 5;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
// TODO Auto-generated method stub
switch (arg0)
{
case 0:
arg2.type = PropertyInfo.INTEGER_CLASS;
arg2.name = "Person_Id";
break;
case 1:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "F_Name";
break;
case 2:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "L_Name";
break;
case 3:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "E_Mail";
break;
case 4:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Password";
break;
default:break;
}
}
@Override
public void setProperty(int arg0, Object arg1) {
// TODO Auto-generated method stub
switch (arg0)
{
case 0:
Person_Id = Integer.parseInt(arg1.toString());
break;
case 1:
F_Name = arg1.toString();
break;
case 2:
L_Name = arg1.toString();
break;
case 3:
E_Mail = arg1.toString();
break;
case 4:
Password = arg1.toString();
break;
default:break;
}
}
}
但是当我从SigninPerson和Override
中删除工具时public class SigninPerson{
/**
*
*/
private static final long serialVersionUID = 1L;
public int Person_Id;
public String F_Name;
public String L_Name;
public String E_Mail;
public String Password;
public SigninPerson ()
{
}
public SigninPerson (int id, String Fname, String Lname, String Email, String Pass)
{
Person_Id = id;
F_Name = Fname;
L_Name = Lname;
E_Mail = Email;
Password = Pass;
}
public SigninPerson (String Email, String Pass)
{
Person_Id = 0;
F_Name = "";
L_Name = "";
}
}
它为SigninPerson
制作新内容并且不给我运行时间
我试图找到问题很长时间,但我找不到任何错误的
拜托,任何人都可以帮助我
因为我必须在早上发送我的申请
答案 0 :(得分:2)
您应该更改此行:
SigninPerson SIPerson = null;
new SigninPerson(s1,s2);
为:
SigninPerson SIPerson = new SigninPerson(s1,s2);
答案 1 :(得分:1)
当您为NullPointerException
声明引用时,它会为您提供SigninPerson
,但您从未将其分配给新的对象 @SOfanatic为你推荐的这个班级(+1给他)。
SigninPerson SIPerson = null;// << here assign SIPerson to new SigninPerson
//....
p.setValue(SIPerson);
p.setType(SIPerson.getClass());