简体   繁体   中英

Intent keeps failing for android

anyone know why this intent is failing

Here is the log in the log cat

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

Code keeps failing here is the manifest file

that's not the complete code but basically there are no errors on the code it just fails when I try to load u the sellingLevel1 class which extends activity and is imported. It is also included into the package as everything else. Also the app runs but doesn't fails when I click button 1 on the spellingLevelPicker class

EDIT

ok its failing here

public class spellingLevel1 extends 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);

}

}

Theres a public void on destroy below but if I comment the imageview set background resources out it doesn't fail

first create a private Context context as a member of your class.

Then in the onCreate add this : this.context = context;

or if you're in a view class you can pass the Context from activity to your constructor so it'll like this

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

and the final is change this

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

        }
        });

to this

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

        }
        });

I hope this will answer your question :) if you have any question regarding my answer feel free to ask in the comment :)

These lines in your 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)

tell me your problem is one of the drawables you're trying to instance in your onCreate method. Check the list of drawables you're including in your file structure to verify you have all the drawables you're listing. (And debug the value you're getting when you're failing)

Instead of

currentLetter = rando.nextInt(myImageList.length);

(which will give you a value between 0 and myImageList.length -1) you need to use

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

(which will give you the int that was generated for your drawable resources)

我的问题的答案是代码中什么都没有-错误的是我调用的图片太大并与其他图像视图冲突,从而导致可绘制资源的错误

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM