gpt4 book ai didi

java.lang.RuntimeException : Performing stop of activity that is not resumed:

转载 作者:太空宇宙 更新时间:2023-11-04 13:40:20 26 4
gpt4 key购买 nike

当我从 LoginScreen Activity 调用 NavDrawerActivity 时,出现运行时异常。

错误

java.lang.RuntimeException: Performing stop of activity that is not resumed: {com.example.owner.loginapp/com.example.owner.loginapp.NavDrawerActivity}

如何修复这个错误?

这是我的loginScreen代码

 package com.example.owner.loginapp;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import android.content.SharedPreferences;

public class LoginScreen extends AppCompatActivity {

ImageView image;
ImageView user_img;
ImageView pass_img;
Button log_in;
Button reg;
EditText editText_Username;
EditText editText_Pass;
UserSessionManager session;

private SharedPreferences sharedPreferences;
private static final String PREFER_NAME = "Reg";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

session = new UserSessionManager(getApplicationContext());

image = (ImageView) findViewById(R.id.imageView);
image.setImageResource(R.drawable.smile);

user_img = (ImageView) findViewById(R.id.user_img);
user_img.setImageResource(R.drawable.user_img);

pass_img = (ImageView) findViewById(R.id.pass_img);
pass_img.setImageResource(R.drawable.img_pass);

log_in = (Button) findViewById(R.id.btn_Login);
reg = (Button) findViewById(R.id.btn_Reg);

editText_Username = (EditText) findViewById(R.id.editText_UserName);
editText_Pass = (EditText) findViewById(R.id.editText_Password);

Bitmap icon = BitmapFactory.decodeResource(getResources(),
image.setImageBitmap(icon);

Toast.makeText(getApplicationContext(),
"User Login Status: " + session.isUserLoggedIn(),
Toast.LENGTH_LONG).show();

sharedPreferences = getSharedPreferences(PREFER_NAME, Context.MODE_PRIVATE);

log_in.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

String username = editText_Username.getText().toString();
String password = editText_Pass.getText().toString();

if (username.trim().length() > 0 && password.trim().length() > 0) {
String uName = null;
String uPassword = null;

if (sharedPreferences.contains("Name")) {
uName = sharedPreferences.getString("Name", "");

}
if (sharedPreferences.contains("Password")) {
uPassword = sharedPreferences.getString("Password", "");

}
if (username.equals(uName) && password.equals(uPassword)) {

session.createUserLoginSession(uName, uPassword);

Intent i = new Intent(getApplicationContext(), NavDrawerActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

} else {

Toast.makeText(getApplicationContext(),
"Username/Password is incorrect",
Toast.LENGTH_LONG).show();
}
} else {

Toast.makeText(getApplicationContext(),
"Please enter username and password",
Toast.LENGTH_LONG).show();
}
}
});

reg.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

setContentView(R.layout.register);

Intent i = new Intent(getApplicationContext(), Reg.class);
startActivity(i);
}
});
}
}

最佳答案

我复制了您的代码并尝试实例化我设计的 Reg Activity 类,一切正常。您可能在Reg类的1onResumeonCreate`中做错了什么。

也发布该类(class)以获取更多信息。

关于java.lang.RuntimeException : Performing stop of activity that is not resumed:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31295813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com