在模拟器上编译应用程序时出错

时间:2017-07-05 11:23:20

标签: android android-studio material-design

我正在尝试将我的应用程序安装到模拟器中以证明它但是当我尝试启动应用程序时崩溃并且不让我打开

我在CoordinarorLayout中使用MainActivity

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="mx.com.dtss.carritocompras.MainActivity">

    <android.support.v7.app.AlertController.RecycleListView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </android.support.v7.app.AlertController.RecycleListView>


</android.support.design.widget.CoordinatorLayout>

在其他活动中我使用CardView

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.FitWindowsLinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/img"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/txtDesPro"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/txtDetalle"/>
        </LinearLayout>
    </android.support.v7.widget.FitWindowsLinearLayout>

</android.support.v7.widget.CardView>

这就是我AndroidManifest中的内容:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="mx.com.dtss.carritocompras" >

        <uses-permission android:name="android.permission.INTERNET"></uses-permission>

        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme" >
            <activity android:name=".MainActivity" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>

    </manifest>

and this is what I have in my `MainActivity`:

package mx.com.dtss.carritocompras;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    RecyclerView recycler;
    RecyclerView.Adapter adap;
    ArrayList<elemento> listaCard;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        recycler = (RecyclerView)findViewById(R.id.recycler);
        recycler.setHasFixedSize(true);
        recycler.setLayoutManager(new LinearLayoutManager(getApplicationContext()));

        Thread tr = new Thread(){
            @Override
            public void run(){
                String NAMESPACE = "http://tempuri.org/";
                String URL = "http://192.168.0.14/Publicacion/WebServiceCarrito.asmx";
                String METHOD_NAME = "listarProductos";
                String SOAP_ACTION = "http://tempuri.org/listarProductos";

                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet= true;
                envelope.setOutputSoapObject(request);
                HttpTransportSE transporte = new HttpTransportSE(URL);

                try{
                    transporte.call(SOAP_ACTION, envelope);
                    final SoapObject soap = (SoapObject)envelope.getResponse();

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            listarProductos(soap);
                        }
                    });
                } catch (Exception e){

                }
            }
        };
        tr.start();
    }

    public void listarProductos(SoapObject soap){
        listaCard = new ArrayList<elemento>();
            for(int i = 0; i < soap.getPropertyCount(); i++){
                SoapObject reg = (SoapObject)soap.getProperty(i);
                elemento e1 = new elemento(reg.getProperty(0).toString(), reg.getProperty(1).toString(),
                        reg.getProperty(2).toString(), Double.parseDouble(reg.getProperty(4).toString()),
                        reg.getProperty(5).toString());

                listaCard.add(e1);
        }

        adap = new Adaptador(listaCard, getApplication());
        recycler.setAdapter(adap);
    }
}

这是我尝试编译时抛出的错误:

07-04 22:34:30.059 13691-13691/mx.com.dtss.carritocompras E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: mx.com.dtss.carritocompras, PID: 13691
                                                                            java.lang.RuntimeException: Unable to start activity ComponentInfo{mx.com.dtss.carritocompras/mx.com.dtss.carritocompras.MainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.app.AlertController.RecycleListView
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
                                                                                at android.app.ActivityThread.access$900(ActivityThread.java:157)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                at android.os.Looper.loop(Looper.java:148)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5477)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                             Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.app.AlertController.RecycleListView
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                                at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                                                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                                at mx.com.dtss.carritocompras.MainActivity.onCreate(MainActivity.java:24)
                                                                                at android.app.Activity.performCreate(Activity.java:6445)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
                                                                                at android.app.ActivityThread.access$900(ActivityThread.java:157) 
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5477) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                             Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class android.support.v7.app.AlertController.RecycleListView
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                                at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                                                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                at mx.com.dtss.carritocompras.MainActivity.onCreate(MainActivity.java:24) 
                                                                                at android.app.Activity.performCreate(Activity.java:6445) 
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376) 
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
                                                                                at android.app.ActivityThread.access$900(ActivityThread.java:157) 
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5477) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                             Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path: DexPathList[[zip file "/data/app/mx.com.dtss.carritocompras-1/base.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_dependencies_apk.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_slice_0_apk.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_slice_1_apk.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_slice_2_apk.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_slice_3_apk.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_slice_4_apk.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_slice_5_apk.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_slice_6_apk.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_slice_7_apk.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_slice_8_apk.apk", zip file "/data/app/mx.com.dtss.carritocompras-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/mx.com.dtss.carritocompras-1/lib/arm64, /vendor/lib64, /system/lib64]]
                                                                                at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                                at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                                at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:583)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                                at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                                                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                at mx.com.dtss.carritocompras.MainActivity.onCreate(MainActivity.java:24) 
                                                                                at android.app.Activity.performCreate(Activity.java:6445) 
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376) 
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
                                                                                at android.app.ActivityThread.access$900(ActivityThread.java:157) 
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5477) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                                Suppressed: java.lang.ClassNotFoundException: android.support.v7.app.AlertController.RecycleListView
                                                                                at java.lang.Class.classForName(Native Method)

我希望有人可以帮助我

2 个答案:

答案 0 :(得分:1)

Logcat表示line 10上有错误

 <android.support.v7.app.AlertController.RecycleListView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </android.support.v7.app.AlertController.RecycleListView>

而不是在

下面使用
   <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </android.support.v7.widget.RecyclerView>

答案 1 :(得分:1)

RecycleListView是一个不供外部使用的内部类。它在支持库中公开显示的事实可能是一个错误。

在xml文件中使用此代码创建ListView

android.support.v7.widget.RecyclerView