我目前正在开发一个Android应用程序,虽然每个东西都在Jelly Bean模拟器上工作正常但我在2.2模拟器上遇到以下错误:
10-11 22:26:35.853: E/AndroidRuntime(303): FATAL EXCEPTION: main
10-11 22:26:35.853: E/AndroidRuntime(303): android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
10-11 22:26:35.853: E/AndroidRuntime(303): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
10-11 22:26:35.853: E/AndroidRuntime(303): at com.android.iagrams.util.MyAdapter.getView(MyAapter.java:20)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.ListView.makeAndAddView(ListView.java:1727)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.ListView.fillDown(ListView.java:652)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.ListView.fillFromTop(ListView.java:709)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.ListView.layoutChildren(ListView.java:1580)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.AbsListView.onLayout(AbsListView.java:1147)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.View.layout(View.java:7035)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.View.layout(View.java:7035)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.View.layout(View.java:7035)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.View.layout(View.java:7035)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.View.layout(View.java:7035)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.os.Looper.loop(Looper.java:123)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-11 22:26:35.853: E/AndroidRuntime(303): at java.lang.reflect.Method.invokeNative(Native Method)
10-11 22:26:35.853: E/AndroidRuntime(303): at java.lang.reflect.Method.invoke(Method.java:521)
10-11 22:26:35.853: E/AndroidRuntime(303): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-11 22:26:35.853: E/AndroidRuntime(303): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-11 22:26:35.853: E/AndroidRuntime(303): at dalvik.system.NativeStart.main(Native Method)
10-11 22:26:35.853: E/AndroidRuntime(303): Caused by: java.lang.reflect.InvocationTargetException
10-11 22:26:35.853: E/AndroidRuntime(303): at android.widget.LinearLayout.<init>(LinearLayout.java:115)
10-11 22:26:35.853: E/AndroidRuntime(303): at java.lang.reflect.Constructor.constructNative(Native Method)
10-11 22:26:35.853: E/AndroidRuntime(303): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
10-11 22:26:35.853: E/AndroidRuntime(303): ... 36 more
10-11 22:26:35.853: E/AndroidRuntime(303): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
10-11 22:26:35.853: E/AndroidRuntime(303): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.View.<init>(View.java:2036)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.View.<init>(View.java:1834)
10-11 22:26:35.853: E/AndroidRuntime(303): at android.view.ViewGroup.<init>(ViewGroup.java:285)
10-11 22:26:35.853: E/AndroidRuntime(303): ... 40 more
据我所知,我没有使用任何Jelly Bean特有的功能,也不知道我得到了什么错误。我有一个自定义适配器,但我没有做太多,我只改变了几个文本视图。
答案 0 :(得分:1)
更改您的适配器,如下所示:
public class MethodAdapter extends ArrayAdapter<Method> {
LayoutInflater inflater;
public MethodAdapter(Context context, int layout, int field, ArrayList<Method> methodsList) {
super(context, layout, field, methodsList);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER);
}
class ViewHolder {
TextView bellName;
TextView bellType;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.your_item_layout, null);
holder = new ViewHolder();
holder.bellName = (TextView) row.findViewById(R.id.bellName);
holder.bellType = (TextView) row.findViewById(R.id.bellType);
convertView.addTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
Method m = getItem(position);
holder.bellName.setText(m.getName());
holder.bellType.setText(m.getSuffix());
return convertView;
}
}
Ps。:我没有编译这段代码。先检查一下......