gpt4 book ai didi

android - 扩展 Spinner 以添加索引,错误膨胀类

转载 作者:行者123 更新时间:2023-11-30 03:15:46 26 4
gpt4 key购买 nike

我需要向 Spinner 添加两个索引,因此我创建了一个 Spin 类来扩展 Spinner。现在在 XML 文件中,我使用类 Spin 的完整路径名,但它给我“没有在路径上找到类”和“错误膨胀类”错误。这是代码:

public class AcceptTimetable extends Activity
{
class Spin extends Spinner
{
int i, j;
public Spin(Context context)
{
super(context);
}

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

public Spin(Context context, int mode)
{
super(context, mode);
// TODO Auto-generated constructor stub
}

public Spin(Context context, AttributeSet attrs, int defStyle, int mode)
{
super(context, attrs, defStyle, mode);
// TODO Auto-generated constructor stub
}

public Spin(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}

public void setIndices(int a, int b)
{
i=a;
j=b;
}

public int getRow()
{ return i; }

public int getColumn()
{ return j; }
}

Spin hours[][]=new Spin[6][6];

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

hours[0][0]=(Spin)findViewById(R.id.ttmon1);
//error at this line


}

这是 XML(只是相关部分):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".AcceptTimeTable" >

<TextView
android:id="@+id/entertt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter the time table:" />

<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/entertt" >"

<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:layout_below="@id/entertt" >

<TableRow
android:id="@+id/monday"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Mon:" />

<AcceptTimetable.Spin
android:id="@+id/ttmon1"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>

包是“com.example.bunkmaster”,而不是使用“AccpetTimetable.Spin”,即使我说“com.example.bunkmaster.AcceptTimetable.Spin”,它也会给出同样的错误。只是“旋转”也会给出同样的错误。我是 Android 的新手,无法理解这一点,请帮忙。

这是我启动 AcceptTimetable Activity 时的堆栈跟踪:

11-22 16:51:02.474: E/AndroidRuntime(2562): FATAL EXCEPTION: main
11-22 16:51:02.474: E/AndroidRuntime(2562): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.example.bunkmaster/com.example.bunkmaster.AcceptTimetable}:
android.view.InflateException: Binary XML file line #39: Error inflating class
AcceptTimetable.Spin 11-22 16:51:02.474: E/AndroidRuntime(2562): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
11-22 16:51:02.474: E/AndroidRuntime(2562): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-22 16:51:02.474: E/AndroidRuntime(2562): at
android.app.ActivityThread.access$600(ActivityThread.java:141)
11-22 16:51:02.474: E/AndroidRuntime(2562): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-22 16:51:02.474: E/AndroidRuntime(2562): at
android.os.Handler.dispatchMessage(Handler.java:99)
11-22 16:51:02.474: E/AndroidRuntime(2562): at
android.os.Looper.loop(Looper.java:137)
11-22 16:51:02.474: E/AndroidRuntime(2562): at
android.app.ActivityThread.main(ActivityThread.java:5041)
11-22 16:51:02.474: E/AndroidRuntime(2562): at
java.lang.reflect.Method.invokeNative(Native Method)
11-22 16:51:02.474: E/AndroidRuntime(2562): at
java.lang.reflect.Method.invoke(Method.java:511)
11-22 16:51:02.474: E/AndroidRuntime(2562): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-22 16:51:02.474: E/AndroidRuntime(2562): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-22 16:51:02.474: E/AndroidRuntime(2562): at dalvik.system.NativeStart.main(Native Method)
11-22 16:51:02.474: E/AndroidRuntime(2562): Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class AcceptTimetable.Spin
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-22 16:51:02.474: E/AndroidRuntime(2562): at com.example.bunkmaster.AcceptTimetable.onCreate(AcceptTimetable.java:66)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.app.Activity.performCreate(Activity.java:5104)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-22 16:51:02.474: E/AndroidRuntime(2562): ... 11 more
11-22 16:51:02.474: E/AndroidRuntime(2562): Caused by: java.lang.ClassNotFoundException: Didn't find class "AcceptTimetable.Spin" on path: /data/app/com.example.bunkmaster-2.apk
11-22 16:51:02.474: E/AndroidRuntime(2562): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
11-22 16:51:02.474: E/AndroidRuntime(2562): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-22 16:51:02.474: E/AndroidRuntime(2562): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
11-22 16:51:02.474: E/AndroidRuntime(2562): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
11-22 16:51:02.474: E/AndroidRuntime(2562): ... 22 more

最佳答案

伙计们,我想通了。我在自己的 java 文件中定义了 Spin 类,在 XML 中我使用了“com.example.bunkmaster.Spin”。像魅力一样工作 ^_^

关于android - 扩展 Spinner 以添加索引,错误膨胀类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20150868/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com