我的代码就像这样,创建了一个构造函数。我想从homepage.java访问该字符串到login.php。但android给了我一个错误“访问构造函数不允许”..我做错了吗?请帮助。 HomePage.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);
}
}
login.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");
}
}
答案 0 :(得分:1)
http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
您已使用 no modifier 声明了HomePage
的构造函数。这意味着只有同一个包中的类可以调用它,这就是你收到错误的原因。
HomePage()
{
...
将其设为public
public HomePage()
{
...