了解我的应用中没有行的stacktrace

时间:2018-07-20 01:53:31

标签: android android-studio exception

我正在尝试在同一布局上初始化(或填充,如果愿意的话)两个微调器。我正在模仿在其他示例中看到的代码,并且初始化在调试器中可以正常进行,但是有时在 之后-以及在微调器的布局出现在我的Android设备(我的手机)上之前-该应用程序崩溃并显示堆栈跟踪,该跟踪无法识别我的应用程序中的任何代码行。我试图找出问题出在我的应用程序中。这是Logcat的相关代码行。我正在运行Android Studio 3.1.3。

07-19 21:31:14.821 30262-30262 / com.example.android.twlistsales E / ArrayAdapter:您必须提供TextView的资源ID 07-19 21:31:14.822 30262-30262 / com.example.android.twlistsales D / AndroidRuntime:关闭VM 07-19 21:31:14.838 30262-30262 / com.example.android.twlistsales E / AndroidRuntime:FATAL EXCEPTION:main     流程:com.example.android.twlistsales,PID:30262     java.lang.IllegalStateException:ArrayAdapter要求资源ID为TextView         在android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:401)         在android.widget.ArrayAdapter.getView(ArrayAdapter.java:371)         在android.widget.AbsSpinner.onMeasure(AbsSpinner.java:195)         在android.widget.Spinner.onMeasure(Spinner.java:662)         在android.support.v7.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:420)         在android.view.View.measure(View.java:21125)         在android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1212)         在android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1552)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)         在android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)         在android.widget.LinearLayout.measureVertical(LinearLayout.java:758)         在android.widget.LinearLayout.onMeasure(LinearLayout.java:640)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)         在android.widget.LinearLayout.measureVertical(LinearLayout.java:758)         在android.widget.LinearLayout.onMeasure(LinearLayout.java:640)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)         在com.android.internal.policy.DecorView.onMeasure(DecorView.java:896)         在android.view.View.measure(View.java:21125)         在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2612)         在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1664)         在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1915)         在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1537)         在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:7183)         在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:959)         在android.view.Choreographer.doCallbacks(Choreographer.java:734)         在android.view.Choreographer.doFrame(Choreographer.java:670)         在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:945)         在android.os.Handler.handleCallback(Handler.java:751)         在android.os.Handler.dispatchMessage(Handler.java:95)         在android.os.Looper.loop(Looper.java:154)         在android.app.ActivityThread.main(ActivityThread.java:6776)         在java.lang.reflect.Method.invoke(本机方法)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1518)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)      造成原因:java.lang.ClassCastException:android.support.constraint.ConstraintLayout无法强制转换为android.widget.TextView         在android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:388)         在android.widget.ArrayAdapter.getView(ArrayAdapter.java:371)         在android.widget.AbsSpinner.onMeasure(AbsSpinner.java:195)         在android.widget.Spinner.onMeasure(Spinner.java:662)         在android.support.v7.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:420)         在android.view.View.measure(View.java:21125)         在android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1212)         在android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1552)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)         在android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)         在android.widget.LinearLayout.measureVertical(LinearLayout.java:758)         在android.widget.LinearLayout.onMeasure(LinearLayout.java:640)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)         在android.widget.LinearLayout.measureVertical(LinearLayout.java:758)         在android.widget.LinearLayout.onMeasure(LinearLayout.java:640)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)         在com.android.internal.policy.DecorView.onMeasure(DecorView.java:896)         在android.view.View.measure(View.java:21125)         在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2612)         在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1664)         在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1915)         在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1537)         在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:7183)         在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:959)         在android.view.Choreographer.doCallbacks(Choreographer.java:734)         在android.view.Choreographer.doFrame(Choreographer.java:670)         在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:945)         在android.os.Handler.handleCallback(Handler.java:751)         在android.os.Handler.dispatchMessage(Handler.java:95)         在android.os.Looper.loop(Looper.java:154)         在android.app.ActivityThread.main(ActivityThread.java:6776)         在java.lang.reflect.Method.invoke(本机方法)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1518)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)      造成原因:java.lang.ClassCastException:android.support.constraint.ConstraintLayout无法强制转换为android.widget.TextView         在android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:388)         在android.widget.ArrayAdapter.getView(ArrayAdapter.java:371)         在android.widget.AbsSpinner.onMeasure(AbsSpinner.java:195)         在android.widget.Spinner.onMeasure(Spinner.java:662)         在android.support.v7.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:420)         在android.view.View.measure(View.java:21125)         在android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1212)         在android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1552)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)         在android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)         在android.widget.LinearLayout.measureVertical(LinearLayout.java:758)         在android.widget.LinearLayout.onMeasure(LinearLayout.java:640)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)         在android.widget.LinearLayout.measureVertical(LinearLayout.java:758)         在android.widget.LinearLayout.onMeasure(LinearLayout.java:640)         在android.view.View.measure(View.java:21125)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6461)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)         在com.android.internal.policy.DecorView.onMeasure(DecorView.java:896)         在android.view.View.measure(View.java:21125)         在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2612)         在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1664)         在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1915)         在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1537)         在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:7183)         在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:959)         在android.view.Choreographer.doCallbacks(Choreographer.java:734)         在android.view.Choreographer.doFrame(Choreographer.java:670)         在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:945)         在android.os.Handler.handleCallback(Handler.java:751)         在android.os.Handler.dispatchMessage(Handler.java:95)         在android.os.Looper.loop(Looper.java:154)         在android.app.ActivityThread.main(ActivityThread.java:6776)         在java.lang.reflect.Method.invoke(本机方法)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1518)         com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

[由于某种原因,它不会让我在此处粘贴堆栈跟踪的最后一部分,所以我要输入它:] 造成原因:java.lang.ClassCastException:android.support.ConstraintLayout无法转换为android.widget.TextView 在android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:388)上<42更多...> <1内部调用> <2更多...>

我猜想,如果我真的可以看到在堆栈跟踪的最后一行中所隐含的行,这将启发我知道我在代码中犯了什么错误,但给出的只是Java代码,这不是很有帮助。

我倾向于认为我的微调器初始化代码在Java中引起了某种问题,但我所看到的只是问题的这个方面,而对问题的出处一无所知在我的代码中。我该如何解决?

关于它的价值,这是我给两个微调器的初始化代码:

    //Set up spinner for Client Code
    spClientCode = findViewById(R.id.client_spinner);
    //Create an array of client codes from the Client enum
    ArrayList<String> clientCodes = new ArrayList<>();
    for (Client client: Client.values()) {
        clientCodes.add(client.toString());
    }
    ArrayAdapter<String> clientAdapter = new ArrayAdapter(this, R.layout.activity_add_sale, clientCodes);

    clientAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spClientCode.setAdapter(clientAdapter);

    //Set up spinner for Seller
    spSellerName = findViewById(R.id.seller_spinner);
    //Create an array of seller names from the Seller enum
    ArrayList<String> sellers = new ArrayList<>();
    for (Seller seller: Seller.values()) {
        sellers.add(seller.toString());
    }
    ArrayAdapter<String> sellerAdapter = new ArrayAdapter(this, R.layout.activity_add_sale, sellers);

    sellerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spSellerName.setAdapter(sellerAdapter);

0 个答案:

没有答案