0

任何人都知道为什么这个意图会失败

这是日志猫中的日志

04-08 10:52:51.782: E/SpannableStringBuilder(10411): SPAN_EXCLUSIVE_EXCLUSIVE spans  cannot have a zero length
04-08 10:52:51.782: E/SpannableStringBuilder(10411): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 
04-08 10:52:52.542: E/SpannableStringBuilder(10411): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-08 10:52:52.542: E/SpannableStringBuilder(10411): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-08 10:52:53.797: E/AndroidRuntime(10411): FATAL EXCEPTION: main
04-08 10:52:53.797: E/AndroidRuntime(10411): java.lang.RuntimeException: Unable to start   activity ComponentInfo   {com.better.work.learning.letters.and.more.awesome/com.better.work.learning.letters.and.more.awesome.spellingLevel1}: android.content.res.Resources$NotFoundException: Resource ID #0x16
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.os.Looper.loop(Looper.java:137)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.app.ActivityThread.main(ActivityThread.java:4898)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at java.lang.reflect.Method.invokeNative(Native Method)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at java.lang.reflect.Method.invoke(Method.java:511)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at dalvik.system.NativeStart.main(Native Method)
04-08 10:52:53.797: E/AndroidRuntime(10411): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x16
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.content.res.Resources.getValue(Resources.java:1026)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.content.res.Resources.getDrawable(Resources.java:671)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.view.View.setBackgroundResource(View.java:14494)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at com.better.work.learning.letters.and.more.awesome.spellingLevel1.onCreate(spellingLevel1.java:72)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.app.Activity.performCreate(Activity.java:5206)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
04-08 10:52:53.797: E/AndroidRuntime(10411):    ... 11 more

代码在这里一直失败是清单文件

这不是完整的代码,但基本上没有错误,当我尝试加载扩展活动并导入的 sellLevel1 类时,它只是失败了。它也与其他所有内容一样包含在包装中。当我单击 spellingLevelPicker 类上的按钮 1 时,应用程序也会运行但不会失败

编辑

好的,这里失败了

公共类 spellingLevel1 扩展 Activity {

Context mContext = null;
private RelativeLayout mCanvasContainer;
private SCanvasView mSCanvas;
private ImageView mImageView1,mImageView2,mImageView3,mImageView4,mImageView5,mImageView6,mImageView7,mImageView8;
public int currentLetter;
private int rando;
int[] myImageList = {
        R.drawable.lettersa, R.drawable.lettersb,
        R.drawable.lettersc, R.drawable.lettersd,
        R.drawable.letterse, R.drawable.lettersf, R.drawable.lettersg,
        R.drawable.lettersh, R.drawable.lettersi, R.drawable.lettersj,
        R.drawable.lettersk, R.drawable.lettersl, R.drawable.lettersm,
        R.drawable.lettersn, R.drawable.letterso, R.drawable.lettersp,
        R.drawable.lettersq, R.drawable.lettersr, R.drawable.letterss, R.drawable.letterst,
        R.drawable.lettersu, R.drawable.lettersv, R.drawable.lettersw,
        R.drawable.lettersx, R.drawable.lettersy, R.drawable.lettersz};





/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.spelling);

    mContext = this;
    mCanvasContainer = (RelativeLayout) findViewById(R.id.canvas_container);
    mSCanvas = new SCanvasView(mContext);




ImageView mImageView01 = (ImageView) findViewById(R.id.imageView1);       
ImageView mImageView02 = (ImageView) findViewById(R.id.imageView2);       
ImageView mImageView03 = (ImageView) findViewById(R.id.imageView3);       
ImageView mImageView04 = (ImageView) findViewById(R.id.imageView4);       
ImageView mImageView05 = (ImageView) findViewById(R.id.imageView5);       
ImageView mImageView06 = (ImageView) findViewById(R.id.imageView6);       
ImageView mImageView07 = (ImageView) findViewById(R.id.imageView7);       
ImageView mImageView08 = (ImageView) findViewById(R.id.imageView8);       
Random rando = new Random();


currentLetter = rando.nextInt(myImageList.length);

mImageView01.setBackgroundResource(currentLetter);
mImageView02.setBackgroundResource(currentLetter);
mImageView03.setBackgroundResource(currentLetter);
mImageView04.setBackgroundResource(currentLetter);

}

}

下面的销毁有一个公共无效,但如果我评论 imageview 设置背景资源它不会失败

4

3 回答 3

0

首先创建一个private Context context作为您班级的成员。

然后在 onCreate 添加这个:this.context = context;

或者如果你在一个视图类中,你可以将 Context 从活动传递给你的构造函数,所以它会像这样

public className(Context context) {
     this.context = context;
}

最后是改变这个

mLevel1.setOnClickListener(new OnClickListener() {
        public void onClick (View v) {
            Intent myIntent = new Intent(v.getContext(), spellingLevel1.class); //Coming soon 
            startActivityForResult(myIntent, 0);        

        }
        });

对此

mLevel1.setOnClickListener(new OnClickListener() {
        public void onClick (View v) {
            Intent myIntent = new Intent(context, spellingLevel1.class); //Coming soon 
            startActivityForResult(myIntent, 0);        

        }
        });

我希望这能回答你的问题:)如果你对我的回答有任何疑问,请随时在评论中提问:)

于 2013-04-08T15:11:59.730 回答
0

您的 logcat 中的这些行

04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.content.res.Resources.getDrawable(Resources.java:671)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at android.view.View.setBackgroundResource(View.java:14494)
04-08 10:52:53.797: E/AndroidRuntime(10411):    at com.better.work.learning.letters.and.more.awesome.spellingLevel1.onCreate(spellingLevel1.java:72)

告诉我您的问题是您尝试在 onCreate 方法中实例化的可绘制对象之一。检查您包含在文件结构中的可绘制对象列表,以验证您拥有列出的所有可绘制对象。(并调试失败时获得的值)

代替

currentLetter = rando.nextInt(myImageList.length);

(这会给你一个介于 0 和 myImageList.length -1 之间的值)你需要使用

currentLetter = myImageList[rando.nextInt(myImageList.length)];

(这将为您提供为您的可绘制资源生成的 int)

于 2013-04-08T15:51:24.390 回答
0

我的问题的答案是代码操作系统中没有任何错误我调用的图片太大并且与其他图像视图发生冲突因此导致可绘制资源的错误

于 2013-04-08T16:40:24.173 回答