我正试图打开我的应用程序,但这是一个错误的膨胀
日志:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pokedex, PID: 10007
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.pokedex/com.example.pokedex.ui.main.MainActivity}:
android.view.InflateException: Binary XML file line #14 in com.example.pokedex:layout/main_activity:
Binary XML file line #14 in com.example.pokedex:layout/main_activity: Error inflating class
androidx.fragment.app.FragmentContainerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at
android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.view.InflateException: Binary XML file line #14 in
com.example.pokedex:layout/main_activity: Binary XML file line #14 in
com.example.pokedex:layout/main_activity: Error inflating class
androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #14 in
com.example.pokedex:layout/main_activity: Error inflating class
androidx.fragment.app.FragmentContainerView
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object
reference
at com.example.pokedex.ui.entrada.EntradaFragment.onCreate(EntradaFragment.kt:31)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2936)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:472)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:278)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2177)
at
androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2094)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1990)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3122)
at androidx.fragment.app.FragmentManager.dispatchCreate(FragmentManager.java:3045)
at androidx.fragment.app.Fragment.onCreate(Fragment.java:1867)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:264)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2936)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:472)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:278)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2177)
at
androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2094)
at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1959)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:311)
at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.java:176)
at
androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView
(FragmentLayoutInflaterFactory.java:52)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
at
androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:313)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:292)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1067)
E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:995)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.pokedex.ui.main.MainActivity.onCreate(MainActivity.kt:41)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at
android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
它拉出错误的片段行:
reg_novo_user.setOnClickListener {
val intent = Intent(activity, RegistroActivity::class.java)
startActivity(intent)
}
这段代码在一个条目片段中,我正在使用firebase实现一个登录
就在我的startActivity下面,我有一个“finish()”,但由于我在一个片段中,我必须删除它,我不知道如果没有这个方法,问题是否会出现
看起来RegistroActivity正在尝试初始化一个片段,但失败了。
原因:java.lang.NullPointerException:尝试对空对象调用虚拟方法“void android.widget.textview.SetonClickListener(android.view.view$OnClickListener
此错误消息行表示您试图在尚未初始化的textview上设置侦听器。尝试在onViewCreated方法中初始化侦听器。
应该管用