【问题标题】:java.lang.ClassNotFoundException: Didn't find class "com.example.cinema.DashboardLayout"java.lang.ClassNotFoundException:没有找到类“com.example.cinema.DashboardLayout”
【发布时间】:2014-03-18 02:30:53
【问题描述】:

我正在尝试开发一个使用仪表板设计方法作为其主页的应用程序。但我遇到了运行时错误。这是logcat:

02-18 13:43:21.488: D/dalvikvm(1248): Late-enabling CheckJNI
02-18 13:43:21.612: D/dalvikvm(1248): GC_CONCURRENT freed 103K, 21% free 2753K/3456K, paused 5ms+1ms, total 10ms
02-18 13:43:21.616: D/dalvikvm(1248): GC_FOR_ALLOC freed 11K, 20% free 2943K/3656K, paused 2ms, total 2ms
02-18 13:43:21.628: I/dalvikvm-heap(1248): Grow heap (frag case) to 4.221MB for 805500-byte allocation
02-18 13:43:21.628: D/dalvikvm(1248): GC_FOR_ALLOC freed 1K, 17% free 3728K/4444K, paused 3ms, total 3ms
02-18 13:43:21.632: D/dalvikvm(1248): GC_CONCURRENT freed 0K, 17% free 3728K/4444K, paused 1ms+0ms, total 2ms
02-18 13:43:21.640: D/AndroidRuntime(1248): Shutting down VM
02-18 13:43:21.644: W/dalvikvm(1248): threadid=1: thread exiting with uncaught exception (group=0xa4c45648)
02-18 13:43:21.644: E/AndroidRuntime(1248): FATAL EXCEPTION: main
02-18 13:43:21.644: E/AndroidRuntime(1248): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.example.cinema/org.example.cinema.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class com.example.cinema.DashboardLayout
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.os.Looper.loop(Looper.java:137)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.app.ActivityThread.main(ActivityThread.java:5103)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at java.lang.reflect.Method.invokeNative(Native Method)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at java.lang.reflect.Method.invoke(Method.java:525)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at dalvik.system.NativeStart.main(Native Method)
02-18 13:43:21.644: E/AndroidRuntime(1248): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class com.example.cinema.DashboardLayout
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:816)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.app.Activity.setContentView(Activity.java:1895)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at org.example.cinema.MainActivity.onCreate(MainActivity.java:14)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.app.Activity.performCreate(Activity.java:5133)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
02-18 13:43:21.644: E/AndroidRuntime(1248):     ... 11 more
02-18 13:43:21.644: E/AndroidRuntime(1248): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.cinema.DashboardLayout" on path: DexPathList[[zip file "/data/app/org.example.cinema-2.apk"],nativeLibraryDirectories=[/data/app-lib/org.example.cinema-2, /system/lib]]
02-18 13:43:21.644: E/AndroidRuntime(1248):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
02-18 13:43:21.644: E/AndroidRuntime(1248):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
02-18 13:43:21.644: E/AndroidRuntime(1248):     ... j22 more

我有 DashboarLayout.java,部分代码如下所示:

package org.example.cinema;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;


public class DashboardLayout extends ViewGroup {

    private static final int UNEVEN_GRID_PENALTY_MULTIPLIER = 10;

    private int mMaxChildWidth = 0;
    private int mMaxChildHeight = 0;

    public DashboardLayout(Context context) {
        super(context, null);
    }

    public DashboardLayout(Context context, AttributeSet attrs) {
        super(context, attrs, 0);
    }

    public DashboardLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
         ............

使用这个类的xml布局文件如下:

<com.example.cinema.DashboardLayout>
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   ........
</com.example.cinema.DashboardLayout>

还有我的 MainActivity.java:

package org.example.cinema;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import org.example.cinema.R;

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dashboard_layout);

  ..........

【问题讨论】:

  • 你有一个名为com.example.cinema.DashboardLayout的类吗?
  • 发布您的相关代码。
  • 检查你的布局Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class com.example.cinema.DashboardLayout
  • 你能发布布局xml吗?
  • 您的 DashboardLayout 或子视图是否包含大图?

标签: java android xml dashboard


【解决方案1】:

布局参考com.example.cinema.DashboardLayout。你的课程是org.example.cinema.DashboardLayout。这些必须相同。最简单的解决方案是在布局中将com 替换为org

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2019-08-30
    • 1970-01-01
    • 2014-11-28
    • 2021-08-30
    • 2019-05-11
    • 2018-04-04
    相关资源
    最近更新 更多