android.view.InflateException:二进制XML文件行#16:错误膨胀类<unknown>(ListView可能?)

时间:2015-09-28 18:34:23

标签: java android

我制作了一个应用程序,它在虚拟设备和真实设备中运行良好,但今天我的应用程序正在抛出异常,也许这里有一些旧错误,但我找不到自己的答案。所以,请告诉我如何解决它,非常感谢

这是我的logcat

FATAL EXCEPTION: main
Process: com.gvc.tvschedule, PID: 1918
android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:121)
at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
at android.widget.AbsListView.obtainView(AbsListView.java:2255)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
at android.widget.ListView.onMeasure(ListView.java:1175)
at android.view.View.measure(View.java:16497)
at android.widget.RelativeLayout.measureChild(RelativeLayout.java:689)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:473)
at android.view.View.measure(View.java:16497)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
... 48 more
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f0b0068}
at android.content.res.Resources.loadDrawable(Resources.java:2073)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.TextView.<init>(TextView.java:806)
at android.widget.TextView.<init>(TextView.java:618)
... 51 

这里是Layout XML:getprogram_main.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">

<RelativeLayout
        android:id="@+id/relativeLayoutProgram"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/relativeLayoutProgram"
        android:orientation="vertical"
        android:layout_marginTop="40dp">

    <ListView
         android:id="@android:id/list"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true">
     </ListView>

    <!-- @android:id/list or @id/android:list  -->
     </RelativeLayout>
</RelativeLayout>

和:view_program_entry.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/programtime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:paddingTop="15sp"
        android:paddingLeft="6sp"
        android:textStyle="bold"/>

       <TextView
           android:id="@+id/programtitle"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:textSize="25sp"
           android:textStyle="bold"
           android:drawableLeft="@+id/programtime" />
       <!-- android:background="@color/blue2" -->

</LinearLayout>

和Java:ProgramPickerActivity.java

package com.gvc.tvschedule;
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.gvc.service.DBController;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class ProgramPickerActivity extends Activity {

    // DB Class to perform DB related operations
    DBController controller = new DBController(this);
    // Progress Dialog Object
    ProgressDialog prgDialog;
    HashMap<String, String> queryValues;
    private static String titleTextFromView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.getprogram_main);
        ArrayList<HashMap<String, String>> programList = controller.generalProgram(MainActivity.getNameOfChannel(), DatePickerActivity.getDate());


        if (programList.size() != 0) {
            // Set the User Array list in ListView

            ListAdapter adapter = new SimpleAdapter(getApplicationContext(), programList, R.layout.view_program_entry, new String[] {
                            "ptime", "ptitle" }, new int[] { R.id.programtime, R.id.programtitle });
            ListView myList = (ListView) findViewById(android.R.id.list);


            myList.setAdapter(adapter);
            myList.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    // TODO Auto-generated method stub
                    TextView titleVIew = (TextView) view.findViewById(R.id.programtitle);
                    titleTextFromView = titleVIew.getText().toString();

                    createPopupWindownForDescription(titleTextFromView);
                }
            });

        }

         prgDialog = new ProgressDialog(this);
         prgDialog.setMessage("loading...");
         prgDialog.setCancelable(false);



    }




    private void createPopupWindownForDescription(String pTitle){
        String content = controller.getDescription(pTitle);
        AlertDialog.Builder builder = new AlertDialog.Builder(ProgramPickerActivity.this);
        builder.setTitle("Content");
        builder.setMessage(content);

        builder.show();
    }
    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        if(prgDialog!=null)
            prgDialog.dismiss();
    }

    public static String getTitleTextFromView(){
        return titleTextFromView;
    }


}

我认为问题与listview有关,因为当listview上没有数据时,它很好,但是对于数据,它会抛出错误。

2 个答案:

答案 0 :(得分:1)

android:id="@+id/list"

使用它,欢迎您

PS:改变

ListView myList = (ListView) findViewById(android.R.id.list);

有:

ListView myList = (ListView) findViewById(R.id.list);

答案 1 :(得分:1)

我相信你目前的问题是

<TextView
       android:id="@+id/programtitle"
       ...
       android:drawableLeft="@+id/programtime" />  // HERE

您正在引用其他TextView,但您应该引用Drawable。我的猜测是你想把它放在另一个TextView的左边?

如果是这种情况,LinearLayout默认情况下会从左到右排列它们,因此您只需将它们按照您希望它们出现的顺序排列即可。此外,不是问题,但由于默认情况下它们是从左到右,所以不需要

android:orientation="horizontal"

当您ListView中没有任何项目时,它没有显示,因为布局永远不会膨胀,因此错误永远不会被捕获。

Docs