-2

我的代码是这样的,创建了一个构造函数。我想从 homepage.java 访问字符串到 login.php。但是android给了我一个错误“不允许访问构造函数”..我做错了吗?请帮忙。主页.java

public class HomePage extends Activity {

private Button clBtn;
private Button bcBtn;
private Button atBtn;
public String ip="";

 HomePage()
 {
    this.ip = "http://111.111.11.1/sp/";
 }

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_page);
    }
}

登录.java

public class Login extends Activity {

private EditText etFacNo; 
private EditText etPassword;
private Button loginBtn;
HomePage getIP = new HomePage();
String url = getIP.ip;


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login_page);

    .
    .
    .
    .
    .
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost request = new HttpPost(url+"loginteacher.php");

}
}
4

1 回答 1

1

http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

您已经声明了HomePage没有修饰符的构造函数。这意味着只有同一个包中的类才能调用它,这就是您收到该错误的原因。

HomePage()
{
    ...

做了public

public HomePage()
{
    ...
于 2013-02-08T17:43:10.800 回答