-2
我的代碼是這樣的,創建了一個構造函數。我想從homepage.java訪問字符串到login.php。但android給我一個錯誤「訪問構造函數不允許」..我做錯了嗎?請幫助。 HomePage.java如何從其他類的字符串中獲取值到Android中的類?
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");
}
}
是你的'Login'類和'HomePage'類在同一個包? – 2013-02-08 17:38:03
使用公共主頁的構造函數 – 2013-02-08 17:39:02
http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html – 2013-02-08 17:40:36