java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.earljames.register_login/com.example.earljames.register_login.Home}: java.lang.NullPointerException
这是我的主页代码。
public class Home extends AppCompatActivity implements View.OnClickListener {
Button bLogout;
EditText etUsername, etName, etAge;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
etUsername = (EditText) findViewById(R.id.etUsername);
etName = (EditText) findViewById(R.id.etName);
etAge = (EditText) findViewById(R.id.etAge);
bLogout = (Button) findViewById(R.id.bLogout);
bLogout.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.bLogout:
startActivity(new Intent(this,Login.class));
break;
}
}
}
Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Home">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Login" />
<activity
android:name=".Register"
android:label="@string/title_activity_register"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>
Activity_Register.xml
<TextView
android:text="Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etName"
android:layout_marginBottom="10dp"/>
<TextView
android:text="Age"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etAge"
android:layout_marginBottom="10dp"/>
<TextView
android:text="Username"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etUsername"
android:layout_marginBottom="10dp"/>
<TextView
android:text="Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etPassword"
android:inputType="textPassword"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:text="Register"
android:id="@+id/bRegister"
android:layout_height="wrap_content" />
最佳答案
可能我能看到的是你这个变量的问题
试试 HOME.this
写这行还是不行
Intent i = new Intent(Home.this,Ur new activity.class) i.setFlag(Intent.FLAG_NEWACTIVITY) 启动 Activity (i)
关于java.lang.RuntimeException : Unable to start activity ComponentInfo for register and login 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36964047/