InflateException和ClassNotFoundException导致应用程序崩溃

时间:2014-03-07 03:02:52

标签: android classnotfoundexception inflate-exception

我正在创建一个应用,当用户选择支票时,会调用第二个活动。但是,当调用第二个活动时,我的应用程序崩溃并且日志cat在我的paycheckactivity oncreate方法上显示错误。

第一项活动

public class TableListActivity extends Activity {
private ListView mListView;
private TableListAdapter mAdapter;

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

    mListView = (ListView)findViewById(R.id.listView);
    mAdapter = new TableListAdapter(this, DataStore.CHECKS);
    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            Intent intent = new Intent (TableListActivity.this, PayCheckActivity.class);
            intent.putExtra(PayCheckActivity.Extra_check, arg2);
            startActivity(intent);
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.table_list, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_refresh) {
            Toast.makeText(this, "Refresh", Toast.LENGTH_SHORT).show();
        return true;
        }
        return super.onOptionsItemSelected(item);}}

第二项活动

public class PayCheckActivity extends Activity {
    public static final String Extra_check= "abc";

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.paycheck);
    }
}

logcat的

03-06 21:51:11.275: D/dalvikvm(1108): GC_FOR_ALLOC freed 36K, 4% free 3135K/3244K, paused 50ms, total 50ms
03-06 21:51:11.285: I/dalvikvm-heap(1108): Grow heap (frag case) to 4.200MB for 1127536-byte allocation
03-06 21:51:11.325: D/dalvikvm(1108): GC_FOR_ALLOC freed 1K, 3% free 4234K/4348K, paused 36ms, total 36ms
03-06 21:51:11.695: D/(1108): HostConnection::get() New Host Connection established 0xb7fc9f38, tid 1108
03-06 21:51:11.775: W/EGL_emulation(1108): eglSurfaceAttrib not implemented
03-06 21:51:11.805: D/OpenGLRenderer(1108): Enabling debug mode 0
03-06 21:51:14.175: D/AndroidRuntime(1108): Shutting down VM
03-06 21:51:14.175: W/dalvikvm(1108): threadid=1: thread exiting with uncaught exception (group=0xb1a5fba8)
03-06 21:51:14.225: E/AndroidRuntime(1108): FATAL EXCEPTION: main
03-06 21:51:14.225: E/AndroidRuntime(1108): Process: edu.udallas.tableservice, PID: 1108
03-06 21:51:14.225: E/AndroidRuntime(1108): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.udallas.tableservice/edu.tableservice.PayCheckActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class br
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.os.Looper.loop(Looper.java:136)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at java.lang.reflect.Method.invokeNative(Native Method)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at java.lang.reflect.Method.invoke(Method.java:515)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at dalvik.system.NativeStart.main(Native Method)
03-06 21:51:14.225: E/AndroidRuntime(1108): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class br
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.app.Activity.setContentView(Activity.java:1929)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at edu.tableservice.PayCheckActivity.onCreate(PayCheckActivity.java:22)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.app.Activity.performCreate(Activity.java:5231)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-06 21:51:14.225: E/AndroidRuntime(1108):     ... 11 more
03-06 21:51:14.225: E/AndroidRuntime(1108): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.br" on path: DexPathList[[zip file "/data/app/edu.udallas.tableservice-1.apk"],nativeLibraryDirectories=[/data/app-lib/edu.udallas.tableservice-1, /system/lib]]
03-06 21:51:14.225: E/AndroidRuntime(1108):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
03-06 21:51:14.225: E/AndroidRuntime(1108):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
03-06 21:51:14.225: E/AndroidRuntime(1108):     ... 21 more
03-06 21:51:17.095: I/Process(1108): Sending signal. PID: 1108 SIG: 9
03-06 22:03:15.835: D/dalvikvm(1134): GC_FOR_ALLOC freed 39K, 4% free 3135K/3248K, paused 89ms, total 91ms
03-06 22:03:15.845: I/dalvikvm-heap(1134): Grow heap (frag case) to 4.200MB for 1127536-byte allocation
03-06 22:03:15.885: D/dalvikvm(1134): GC_FOR_ALLOC freed 2K, 3% free 4233K/4352K, paused 35ms, total 35ms
03-06 22:03:16.215: D/(1134): HostConnection::get() New Host Connection established 0xb7edd508, tid 1134
03-06 22:03:16.315: W/EGL_emulation(1134): eglSurfaceAttrib not implemented
03-06 22:03:16.335: D/OpenGLRenderer(1134): Enabling debug mode 0
03-06 22:03:17.795: D/AndroidRuntime(1134): Shutting down VM
03-06 22:03:17.795: W/dalvikvm(1134): threadid=1: thread exiting with uncaught exception (group=0xb1a5fba8)
03-06 22:03:17.845: E/AndroidRuntime(1134): FATAL EXCEPTION: main
03-06 22:03:17.845: E/AndroidRuntime(1134): Process: edu.udallas.tableservice, PID: 1134
03-06 22:03:17.845: E/AndroidRuntime(1134): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.udallas.tableservice/edu.tableservice.PayCheckActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class br
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.os.Looper.loop(Looper.java:136)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at java.lang.reflect.Method.invokeNative(Native Method)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at java.lang.reflect.Method.invoke(Method.java:515)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at dalvik.system.NativeStart.main(Native Method)
03-06 22:03:17.845: E/AndroidRuntime(1134): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class br
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.app.Activity.setContentView(Activity.java:1929)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at edu.tableservice.PayCheckActivity.onCreate(PayCheckActivity.java:22)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.app.Activity.performCreate(Activity.java:5231)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-06 22:03:17.845: E/AndroidRuntime(1134):     ... 11 more
03-06 22:03:17.845: E/AndroidRuntime(1134): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.br" on path: DexPathList[[zip file "/data/app/edu.udallas.tableservice-1.apk"],nativeLibraryDirectories=[/data/app-lib/edu.udallas.tableservice-1, /system/lib]]
03-06 22:03:17.845: E/AndroidRuntime(1134):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
03-06 22:03:17.845: E/AndroidRuntime(1134):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
03-06 22:03:17.845: E/AndroidRuntime(1134):     ... 21 more

3 个答案:

答案 0 :(得分:5)

在这里,你得到两个Exception ...

android.view.InflateException:当您尝试inflate您的视图/ XML时,会导致它。由于您使用的是CustomAdapter,因此您在onCreateView()方法中夸大了列表项的XML以及导致问题的XML ... LogCat直接将其指示为...

Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class br

java.lang.ClassNotFoundException:由于您试图将HTML标记<br></br>置于XML Android XML不支持的XML中,因此导致该问题。 LogCat清楚地表明您正在使用此邮件的<br>标记...

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.br"

在名为br的android中没有视图...因此将其从XML中删除...您的问题将得到解决。

答案 1 :(得分:1)

在“application”标签下的AndroidManifest.xml文件中提及活动名称,如下所述:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.TableListActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     <activity
        android:name="com.example.PayCheckActivity"
        android:label="@string/app_name" >
        </activity>

</application>

如果仍然显示错误,请告诉错误。

答案 2 :(得分:0)

看起来您已经为PayCheckActivity复制了粘贴(就像我也是:) :) onCreate,因此您在那里缺少 @Override 关键字。

这个onCreate()不再是Activity重写方法,而是错误。

就这样做,

public class PayCheckActivity extends Activity{
    public static final String Extra_check= "abc";

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

希望这会有所帮助。 :)