Android:java.lang.RuntimeException: Unable to start activity ComponentInfo

java.lang.RuntimeException: Unable to start activity ComponentInfo

报错描述:
在导入别人项目运行时出现了这个报错:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.news/com.example.activity.DetailNews}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)

解决方法:
Activity引入的包:import android.app.Activity;
AppCompatActivity引入的包:import androidx.appcompat.app.AppCompatActivity;
身为新手的我也不是很懂,但是百度得知:
这里我们需要继承的是Activity而不是AppCompatActivity
Android:java.lang.RuntimeException: Unable to start activity ComponentInfo_第1张图片

你可能感兴趣的:(android,java,开发语言)