1

我收到错误登录无法解决或不是字段错误,密码和 ip 相同。我在做 android 程序时在 eclipse 中得到这个错误。

  public void onClick(View v) {
    if (v == this.viewcam)
      {
        Log.i("login", this.login.getText().toString());
        Log.i("Passwd", this.passwd.getText().toString());
        Intent localIntent1 = new Intent(v.getContext(), MjpegSample.class);
        Log.i("My ip", this.editTextIp.getText().toString());
        localIntent1.putExtra("ip", "http://" + this.editTextIp.getText().toString() + "/");
        localIntent1.putExtra("user", this.login.getText().toString());
        localIntent1.putExtra("passwd", this.passwd.getText().toString());
        startActivityForResult(localIntent1, 1000);
      }
    }
});

下面是上面对应的main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="IP CAM VIEWER"
        android:textAppearance="?android:attr/textAppearanceLarge"
        />
</LinearLayout>
<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Username : "
            android:textAppearance="?android:attr/textAppearanceLarge" />
        <EditText
            android:id="@+id/username"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10" >
            <requestFocus />
        </EditText>
    </TableRow>
    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Password : "
            android:textAppearance="?android:attr/textAppearanceLarge" />
        <EditText
            android:id="@+id/password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPassword" />
    </TableRow>
    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="IP : "
            android:textAppearance="?android:attr/textAppearanceLarge" />
        <EditText
            android:id="@+id/ip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10" />
</TableLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.62" >
    <Button
        android:id="@+id/viewcam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="96dp"
        android:layout_marginTop="16dp"
        android:text="View cam" />
</RelativeLayout>
</LinearLayout>
4

1 回答 1

1

我假设这段代码在 OnClickListener 中,在这种情况下,删除this关键字,因为它指的是 OnClickListener 实例,而不是 Activity 实例:

 public void onClick(View v) {
    if (v == viewcam)
      {
        Log.i("login", login.getText().toString());
        Log.i("Passwd", passwd.getText().toString());
        Intent localIntent1 = new Intent(v.getContext(), MjpegSample.class);
        Log.i("My ip", editTextIp.getText().toString());
        localIntent1.putExtra("ip", "http://" + editTextIp.getText().toString() + "/");
        localIntent1.putExtra("user", login.getText().toString());
        localIntent1.putExtra("passwd", passwd.getText().toString());
        startActivityForResult(localIntent1, 1000);
      }
    }

另一种选择是“完全合格” this,例如:

Log.i("login", TheActivity.this.login.getText().toString());
于 2012-05-04T22:02:10.890 回答