私のこのプロジェクトの目標は、スピナーをユーザー入力で動的に更新することです。残念ながら、私はこの戦いに負けています。Logcat は私にリソース ID エラーをスローし続けますが、ボタンを押したときにのみスローされる理由がわかりません。問題がある場合は、onCreate の後にスローされませんか?
Eclipse (ctrl + スペース経由) は、TextView を含むレイアウトのリソース ID を指定するように指示します。配列とスピナーを扱っているだけなら、なぜテキストビューが必要なのかさえ理解できません。AndroidDevelopment サイトにも同じことが書かれています。私はただ混乱しています.だから、私の質問は、このエラーは何を意味し、何が間違っているのですか?
これが問題の行だと思います:
list = new ArrayAdapter<String>(this,R.layout.settings,items);
これは.javaです
package com.example.thepicker;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
public class Settings extends Activity implements OnClickListener{
EditText getit;
ImageButton giveit;
Spinner thelist;
ArrayList<String> items;
ArrayAdapter<String> list;
String transit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
items = new ArrayList<String>();
list = new ArrayAdapter<String>(this,R.layout.settings,items);
getit = (EditText) findViewById(R.id.getit);
giveit = (ImageButton) findViewById(R.id.giveit);
thelist = (Spinner) findViewById(R.id.thelist);
thelist.setAdapter(list);
giveit.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String transit = getit.getText().toString();
items.add(transit);
list.insert(transit, 0);
list.notifyDataSetChanged();
}
}
これはログキャットです
03-11 01:39:25.682: E/Trace(1722): error opening trace file: No such file or directory (2)
03-11 01:39:26.452: D/libEGL(1722): loaded /system/lib/egl/libEGL_emulation.so
03-11 01:39:26.532: D/(1722): HostConnection::get() New Host Connection established 0x556a6180, tid 1722
03-11 01:39:26.602: D/libEGL(1722): loaded /system/lib/egl/libGLESv1_CM_emulation.so
03-11 01:39:26.623: D/libEGL(1722): loaded /system/lib/egl/libGLESv2_emulation.so
03-11 01:39:26.761: W/EGL_emulation(1722): eglSurfaceAttrib not implemented
03-11 01:39:26.772: D/OpenGLRenderer(1722): Enabling debug mode 0
03-11 01:39:30.483: W/EGL_emulation(1722): eglSurfaceAttrib not implemented
03-11 01:39:36.412: E/ArrayAdapter(1722): You must supply a resource ID for a TextView
03-11 01:39:36.412: D/AndroidRuntime(1722): Shutting down VM
03-11 01:39:36.423: W/dalvikvm(1722): threadid=1: thread exiting with uncaught exception (group=0x2bd39930)
03-11 01:39:36.562: E/AndroidRuntime(1722): FATAL EXCEPTION: main
03-11 01:39:36.562: E/AndroidRuntime(1722): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:386)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:193)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.Spinner.onMeasure(Spinner.java:439)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.View.measure(View.java:15513)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:645)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:425)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.View.measure(View.java:15513)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.View.measure(View.java:15513)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.View.measure(View.java:15513)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-11 01:39:36.562: E/AndroidRuntime(1722): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.View.measure(View.java:15513)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.Choreographer.doFrame(Choreographer.java:532)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.os.Handler.handleCallback(Handler.java:725)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.os.Handler.dispatchMessage(Handler.java:92)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.os.Looper.loop(Looper.java:137)
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-11 01:39:36.562: E/AndroidRuntime(1722): at java.lang.reflect.Method.invokeNative(Native Method)
03-11 01:39:36.562: E/AndroidRuntime(1722): at java.lang.reflect.Method.invoke(Method.java:511)
03-11 01:39:36.562: E/AndroidRuntime(1722): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-11 01:39:36.562: E/AndroidRuntime(1722): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-11 01:39:36.562: E/AndroidRuntime(1722): at dalvik.system.NativeStart.main(Native Method)
03-11 01:39:36.562: E/AndroidRuntime(1722): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
03-11 01:39:36.562: E/AndroidRuntime(1722): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:379)
03-11 01:39:36.562: E/AndroidRuntime(1722): ... 35 more
03-11 01:39:36.682: D/dalvikvm(1722): GC_CONCURRENT freed 188K, 4% free 6367K/6596K, paused 90ms+4ms, total 255ms
03-11 01:39:40.702: I/Process(1722): Sending signal. PID: 1722 SIG: 9
03-11 01:39:41.192: E/Trace(1747): error opening trace file: No such file or directory (2)
03-11 01:39:41.992: D/libEGL(1747): loaded /system/lib/egl/libEGL_emulation.so
03-11 01:39:42.092: D/(1747): HostConnection::get() New Host Connection established 0x556a6180, tid 1747
03-11 01:39:42.376: D/libEGL(1747): loaded /system/lib/egl/libGLESv1_CM_emulation.so
03-11 01:39:42.394: D/libEGL(1747): loaded /system/lib/egl/libGLESv2_emulation.so
03-11 01:39:42.674: W/EGL_emulation(1747): eglSurfaceAttrib not implemented
03-11 01:39:43.465: D/OpenGLRenderer(1747): Enabling debug mode 0