Java onCreate(Bundle)已在.com中定义
如何修复onCreate的此重复 我尝试将onCreate更改为onCreate 1 但是@Override得到一个错误 “方法不重写其超类中的方法” 我该怎么解决这个问题请帮忙谢谢Java onCreate(Bundle)已在.com中定义,java,android,android-studio,Java,Android,Android Studio,如何修复onCreate的此重复 我尝试将onCreate更改为onCreate 1 但是@Override得到一个错误 “方法不重写其超类中的方法” 我该怎么解决这个问题请帮忙谢谢 @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.acti
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
email = (EditText) findViewById(R.id.email);
password = (EditText) findViewById(R.id.password);
login = (Button) findViewById(R.id.login);
signup = (TextView) findViewById(R.id.open_signup);
progressDialog = new ProgressDialog(this);
session = new UserSession(this);
userInfo = new UserInfo(this);
if (session.isUserLoggedin()) {
startActivity(new Intent(this, MainActivity.class));
finish();
}
login.setOnClickListener(this);
signup.setOnClickListener(this);
}
private void login(final String email, final String password) {
//Tag used to cancel the request
String tag_string_req = "req_login";
progressDialog.setMessage("Logging in....");
progressDialog.show();
StringRequest strReq = new StringRequest(Request.Method.POST,
Utils.LOGIN_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Login Response: " + response.toString());
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
//check for error node in json
if (!error) {
//now store the user in SQLite
JSONObject user = jObj.getJSONObject("user");
String uName = user.getString("username");
String email = user.getString("email");
//Inserting row in users table
userInfo.setEmail(email);
userInfo.setUsername(uName);
session.setLoggedin(true);
startActivity(new Intent(Login.this, MainActivity.class));
finish();
} else {
//error in login, get the error message
String errorMsg = jObj.getString("error_msg");
toast(errorMsg);
}
} catch (JSONException e) {
//json error
e.printStackTrace();
toast("Json error: " + e.getMessage());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Login Error: " + error.getMessage());
toast("Unknown Error occured");
progressDialog.hide();
}
}) {
@Override
protected Map<String, String> getParams() {
//Posting parameters to login url
Map<String, String> params = new HashMap<>();
params.put("email", email);
params.put("password", password);
return params;
}
;
//Adding request to request queue
AndroidLoginController.getInstance();
addToRequestQueue(strReq, tag_string_req);
}
private void toast(String x) {
Toast.makeText(this, x, Toast.LENGTH_SHORT).show();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.login:
String uName = email.getText().toString().trim();
String pass = password.getText().toString().trim();
login(uName, pass);
break;
case R.id.open_signup:
startActivity(new Intent(this, SignUp.class));
break;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("Login Page") // TODO: Define a title for the content shown.
// TODO: Make sure this auto-generated URL is correct.
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u登录);
email=(EditText)findviewbyd(R.id.email);
密码=(EditText)findViewById(R.id.password);
login=(按钮)findviewbyd(R.id.login);
注册=(TextView)findViewById(R.id.open\u注册);
progressDialog=新建progressDialog(此);
会话=新用户会话(此会话);
userInfo=新的userInfo(此);
if(session.isUserLoggedin()){
startActivity(新意图(this,MainActivity.class));
完成();
}
login.setOnClickListener(this);
signup.setOnClickListener(this);
}
私有无效登录(最终字符串电子邮件、最终字符串密码){
//用于取消请求的标记
String tag\u String\u req=“req\u login”;
progressDialog.setMessage(“登录…”);
progressDialog.show();
StringRequest strReq=新的StringRequest(Request.Method.POST,
Utils.LOGIN\u URL,新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
Log.d(标记“登录响应:+Response.toString());
试一试{
JSONObject jObj=新的JSONObject(响应);
布尔错误=jObj.getBoolean(“错误”);
//检查json中的错误节点
如果(!错误){
//现在将用户存储在SQLite中
JSONObject user=jObj.getJSONObject(“用户”);
字符串uName=user.getString(“用户名”);
String email=user.getString(“电子邮件”);
//在用户表中插入行
userInfo.setEmail(电子邮件);
userInfo.setUsername(uName);
session.setLoggedin(true);
startActivity(新意图(Login.this、MainActivity.class));
完成();
}否则{
//登录时出错,请获取错误消息
String errorMsg=jObj.getString(“error_msg”);
吐司;
}
}捕获(JSONException e){
//json错误
e、 printStackTrace();
toast(“Json错误:+e.getMessage());
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Log.e(标记“登录错误:+Error.getMessage());
toast(“发生未知错误”);
progressDialog.hide();
}
}) {
@凌驾
受保护的映射getParams(){
//将参数发布到登录url
Map params=新的HashMap();
参数put(“电子邮件”,电子邮件);
参数put(“密码”,密码);
返回参数;
}
;
//将请求添加到请求队列
AndroidLoginController.getInstance();
addToRequestQueue(streq、标记字符串请求);
}
私有空吐司(字符串x){
Toast.makeText(this,x,Toast.LENGTH_SHORT).show();
}
@凌驾
公共void onClick(视图v){
开关(v.getId()){
案例R.id.login:
字符串uName=email.getText().toString().trim();
String pass=password.getText().toString().trim();
登录(uName,pass);
打破
案例R.id.open\u注册:
startActivity(新意图(这个,SignUp.class));
打破
}
}
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//注意:这是自动生成的,用于实现应用程序索引API。
//看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
client=new GoogleApiClient.Builder(this.addApi(AppIndex.API).build();
}
/**
*注意:这是自动生成的,用于实现应用程序索引API。
*看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
*/
公共行动getIndexApiAction(){
Thing对象=newthing.Builder()
.setName(“登录页”)//TODO:为显示的内容定义标题。
//TODO:确保此自动生成的URL正确无误。
.setUrl(Uri.parse(“http://[ENTER-YOUR-URL-HERE]”)
.build();
返回新的Action.Builder(Action.TYPE\u视图)
.setObject(对象)
.setActionStatus(操作.状态\类型\完成)
.build();
}
@凌驾
public void onStart(){
super.onStart();
//注意:这是自动生成的,用于实现应用程序索引API。
//看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
client.connect();
AppIndex.AppIndexApi.start(客户端,getIndexApiAction());
}
@凌驾
公共void onStop(){
super.onStop();
//注意:这是自动生成的,用于实现应用程序索引API。
//看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
AppIndex.AppIndexApi.end(客户端,getIndexApiAction());
client.disconnect();
}
}
您不需要两个onCreate
方法。您需要在这两种方法中的一种中执行所有需要的操作
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
email = (EditText) findViewById(R.id.email);
password = (EditText) findViewById(R.id.password);
login = (Button) findViewById(R.id.login);
signup = (TextView) findViewById(R.id.open_signup);
progressDialog = new ProgressDialog(this);
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
session = new UserSession(this);
userInfo = new UserInfo(this);
if (session.isUserLoggedin()) {
startActivity(new Intent(this, MainActivity.class));
finish();
}
login.setOnClickListener(this);
signup.setOnClickListener(this);
}