gpt4 book ai didi

java - 无法启动 Activity ComponentInfo

转载 作者:行者123 更新时间:2023-12-02 04:04:59 29 4
gpt4 key购买 nike

当我运行我的 Activity registeration.javalogin.java 时,它将 Intent 中的用户名传递给名为 profile.java 的新 Activity > 关于成功。问题是当我尝试登录时,应用程序崩溃并在 logcat 中给出以下错误。我尝试了有关此问题的 stackoverflow 问题上的所有内容,但没有一个解决它。任何建议都将受到高度赞赏。

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admin.funtube/com.example.admin.funtube.profile}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.admin.funtube.profile.onCreate(profile.java:20)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:123)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)

profile.java

public class profile extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);

TextView welcometxt = (TextView) findViewById(R.id.welcome);

Bundle extras = getIntent().getExtras();
welcometxt.setText("Welcome " + extras.getString("name").toUpperCase());

}
}

login.java

 if (email != null && password !=null) {
String em=email.getText().toString();
String pwd=password.getText().toString();
String user= FunTubeDBOperations.loginUsers(em, pwd);
if(user!=null)
{
Toast.makeText(getApplicationContext(), "Login successfully!!", Toast.LENGTH_LONG).show();
Intent intent = new Intent(login.this, profile.class);
intent.putExtra("name", user);
startActivity(intent);
finish();
}
}

Profile.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/header_imageview"
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
android:src="@drawable/logo"
android:adjustViewBounds="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<LinearLayout
android:id="@+id/informations_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="@+id/header_imageview"
android:gravity="center"
android:paddingTop="32dp"
android:paddingBottom="32dp">


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="17dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:gravity="center"
android:textColor="#FF707070"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="#FF909090" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UploadPic"
android:id="@+id/bup"
android:layout_gravity="center_horizontal" />

</LinearLayout>

<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:layout_below="@+id/informations_container"
android:background="#FFF0F0F0">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">



</LinearLayout>
</HorizontalScrollView>


<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/logo"
android:layout_centerHorizontal="true"
android:layout_above="@+id/informations_container"
android:layout_marginBottom="-16dp" />

</RelativeLayout>

最佳答案

TextView welcometxt = (TextView) findViewById(R.id.welcome);

您的布局文件中没有名为 welcome 的小部件。因此,findViewById() 将无法检索它。因此,welcometxt 将为 null

关于java - 无法启动 Activity ComponentInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34404705/

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