java.lang.ClassNotFoundException: Didn't find class "com.example.cinema.DashboardLayout"

StackOverflow https://stackoverflow.com/questions/21852048

  •  13-10-2022
  •  | 
  •  

質問

I am trying to develop an app that uses dashboard design method as its home page. but I'm getting a run time error. Here is the 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

I have DashboarLayout.java and the code looks like this partially:

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);
    }
         ............

and the xml layout file which uses this class looks like:

<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>

and my 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);

  ..........
役に立ちましたか?

解決

The layout refers to com.example.cinema.DashboardLayout. The class you have is org.example.cinema.DashboardLayout. These need to be the same. The simplest solution is to replace com with org in the layout.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top