0

我想不通,我看不到循环和随机数,程序将直接关闭..并弹出“不幸已停止”?

package com.main.project.spotddifference;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

private long startTime = 0L;

private Handler customHandler = new Handler();
long timeInMilliseconds = 0L;
long timeSwapBuff = 0L;
long updatedTime = 0L;

Context context;
ImageView display,all;
TextView timer;
int anss,triesCount;

Random random = new Random( System.currentTimeMillis() );
int next = random.nextInt( 23 ) + 1;

int[] imageViews = {R.id.A,R.id.B,R.id.C,R.id.D };

int[] img = new int[] {R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4,
        R.drawable.img5,R.drawable.img6,R.drawable.img7,R.drawable.img8,
        R.drawable.img9,R.drawable.img10,R.drawable.img11,R.drawable.img12,
        R.drawable.img13,R.drawable.img14,R.drawable.img15,R.drawable.img16,
        R.drawable.img17,R.drawable.img18,R.drawable.img19,R.drawable.img20,
        R.drawable.img21,R.drawable.img22,R.drawable.img23,R.drawable.img24};

int [] ansLET = new int[] {R.drawable.alpha,R.drawable.charlie,R.drawable.alpha,R.drawable.delta,
        R.drawable.delta,R.drawable.alpha,R.drawable.beta,R.drawable.alpha,
        R.drawable.alpha,R.drawable.beta,R.drawable.delta,R.drawable.delta,
        R.drawable.charlie,R.drawable.alpha,R.drawable.charlie,R.drawable.alpha,
        R.drawable.beta,R.drawable.delta,R.drawable.charlie,R.drawable.alpha,
        R.drawable.beta,R.drawable.alpha,R.drawable.charlie,R.drawable.delta};

int [] ansImg = new int[]{R.drawable.aimg1,R.drawable.aimg2,R.drawable.aimg3,R.drawable.aimg4,
        R.drawable.aimg5,R.drawable.aimg6,R.drawable.aimg7,R.drawable.aimg8,
        R.drawable.aimg9,R.drawable.aimg10,R.drawable.aimg11,R.drawable.aimg12,
        R.drawable.aimg13,R.drawable.aimg14,R.drawable.aimg15,R.drawable.aimg16,
        R.drawable.aimg17,R.drawable.aimg18,R.drawable.aimg19,R.drawable.aimg20,
        R.drawable.aimg21,R.drawable.aimg22,R.drawable.aimg23,R.drawable.aimg24};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);

    display = (ImageView)findViewById(R.id.imageView1);
    timer = (TextView)findViewById(R.id.textView1);
    context = this;
     allImage();
     allButton();
}

private void allButton() {
     Button choose = (Button)findViewById(R.id.choice);
     Button quit = (Button)findViewById(R.id.back);

     choose.setOnClickListener(this);
     quit.setOnClickListener(this);
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.splash, menu);
    return true;
}



private void allImage() {
     ImageView a= (ImageView)findViewById(R.id.A);
     ImageView b= (ImageView)findViewById(R.id.B);
     ImageView c= (ImageView)findViewById(R.id.C);
     ImageView d= (ImageView)findViewById(R.id.D);

     a.setOnClickListener(this);
     b.setOnClickListener(this);
     c.setOnClickListener(this);
     d.setOnClickListener(this);
}



@Override
public void onClick(View arg0) {
    switch(arg0.getId()){
        case R.id.A:
            display.setImageResource(R.drawable.alpha);
            break;
        case R.id.B:
            display.setImageResource(R.drawable.beta);
            break;
        case R.id.C:
            display.setImageResource(R.drawable.charlie);
            break;
        case R.id.D:
            display.setImageResource(R.drawable.delta);
            break;

        case R.id.choice:
            checkAns();
            break;
        case R.id.quit:
            Intent intent2 = new Intent (this,MenuActivity.class);
            startActivity(intent2);
            break;
    }
}

public void randomImage(){
    List<Integer> generated = new ArrayList<Integer>();
    for (int i = 0; i < imageViews.length; i++) {
        int v = imageViews[i]-1;
        int vs = imageViews[i]-3;

        if ( generated.contains( next ) ) {
            generated.add( next );
            ImageView iv = (ImageView) findViewById( v );
            ImageView ivs = (ImageView) findViewById( vs );
            iv.setImageResource( img[next] );
            ivs.setImageResource(ansImg[next]);
            checkAns();
        }
    }
}

@SuppressWarnings("unchecked")
public void checkAns(){
    for(int a = 1 ; a <= 2 ; a++){
        for(int s = 1 ; s <= 5; s++ ){
            if(((List<Integer>) display).contains(ansLET[next])){
            randomImage();
            }
            else{
                Intent in = new Intent (getApplicationContext(),AgainActivity.class);
                in.putExtra("result", "Congratulation!.You got the right answer!.");
                startActivity(in);
                break;
                }
            }
        Intent go = new Intent (getApplicationContext(),CongratsActivity.class);
        startActivity(go);
        }
    }

public void startTime(){
    startTime = SystemClock.uptimeMillis();
    customHandler.postDelayed(updateTimerThread, 0);
}

public void pauseTime(){
    timeSwapBuff += timeInMilliseconds;
    customHandler.removeCallbacks(updateTimerThread);
}

private Runnable updateTimerThread = new Runnable() {

    public void run() {

        timeInMilliseconds = SystemClock.uptimeMillis() - startTime;

        updatedTime = timeSwapBuff + timeInMilliseconds;

        int secs = (int) (updatedTime / 1000);
        int mins = secs / 60;
        secs = secs % 60;
        int milliseconds = (int) (updatedTime % 1000);
        timer.setText("" + String.format("%02",mins) + ":"
                + String.format("%02d", secs) + ":"
                + String.format("%02d", milliseconds));
        customHandler.postDelayed(this, 0);
    }

};

}

我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back"  >
<HorizontalScrollView
    android:id="@+id/horizontalScrollView1"
    android:layout_width="350dp"
    android:layout_height="350dp"
    android:layout_centerVertical="true" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/A"
            android:layout_width="270dp"
            android:layout_height="270dp"
            android:layout_marginBottom="25dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="25dp"
            android:contentDescription="@string/pics"
             />

        <ImageView
            android:id="@+id/B"
            android:layout_width="270dp"
            android:layout_height="270dp"
            android:layout_marginBottom="25dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="25dp"
            android:contentDescription="@string/pics"
             />

        <ImageView
            android:id="@+id/C"
            android:layout_width="270dp"
            android:layout_height="270dp"
            android:layout_marginBottom="25dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="25dp"
            android:contentDescription="@string/pics"
             />

        <ImageView
            android:id="@+id/D"
            android:layout_width="270dp"
            android:layout_height="270dp"
            android:layout_marginBottom="25dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="25dp"
            android:contentDescription="@string/pics"
             />
    </LinearLayout>
</HorizontalScrollView>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/horizontalScrollView1"
    android:layout_marginBottom="15dp"
    android:layout_alignParentBottom="true" >

    <Button
        android:id="@+id/choice"
        android:layout_width="150dp"
        android:layout_height="70dp"
        android:background="@drawable/button_custom3"
        android:text="@string/btn_in_choose"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/answer"
        android:layout_width="110dp"
        android:layout_height="80dp"
        android:layout_marginRight="20dp"
        android:contentDescription="@string/pics"
         />
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/horizontalScrollView1"
    android:layout_alignParentTop="true"
    android:orientation="horizontal"
    android:weightSum="200" >

    <Button
        android:layout_weight="20"
        android:id="@+id/back"
        android:layout_width="50dp"
        android:layout_height="80dp"
        android:background="@drawable/button_custom3"
        android:text="@string/btn_mainmenu"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="160"
        android:text="@string/heading_timer"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:layout_weight="20"
        android:id="@+id/hm"
        android:layout_width="50dp"
        android:layout_height="80dp"
        android:background="@drawable/button_custom3"
        android:text="@string/btn_in_hint"
        android:textStyle="bold" />

    </LinearLayout>
</RelativeLayout>

日志文件:

09-17 22:45:22.828: D/dalvikvm(935): GC_FOR_ALLOC freed 38K, 7% free 2402K/2580K, paused 51ms, total 54ms
09-17 22:45:22.848: I/dalvikvm-heap(935): Grow heap (frag case) to 3.944MB for 1536016-byte allocation
09-17 22:45:22.918: D/dalvikvm(935): GC_FOR_ALLOC freed <1K, 5% free 3901K/4084K, paused 66ms, total 66ms
09-17 22:45:23.008: D/dalvikvm(935): GC_CONCURRENT freed <1K, 5% free 3901K/4084K, paused 9ms+6ms, total 89ms
09-17 22:45:23.398: D/dalvikvm(935): GC_FOR_ALLOC freed <1K, 5% free 3901K/4084K, paused 37ms, total 37ms
09-17 22:45:23.409: I/dalvikvm-heap(935): Grow heap (frag case) to 4.766MB for 864016-byte allocation
09-17 22:45:23.558: D/dalvikvm(935): GC_CONCURRENT freed 0K, 4% free 4745K/4928K, paused 89ms+5ms, total 147ms
09-17 22:45:23.558: D/dalvikvm(935): WAIT_FOR_CONCURRENT_GC blocked 8ms
09-17 22:45:23.888: D/dalvikvm(935): GC_CONCURRENT freed 1500K, 30% free 3946K/5628K, paused 6ms+57ms, total 171ms
09-17 22:45:24.108: D/dalvikvm(935): GC_FOR_ALLOC freed 697K, 36% free 3643K/5628K, paused 38ms, total 43ms
09-17 22:45:24.128: I/dalvikvm-heap(935): Grow heap (frag case) to 5.155MB for 1536016-byte allocation
09-17 22:45:24.288: D/dalvikvm(935): GC_FOR_ALLOC freed <1K, 28% free 5142K/7132K, paused 154ms, total 155ms
09-17 22:45:24.428: D/dalvikvm(935): GC_CONCURRENT freed <1K, 28% free 5142K/7132K, paused 9ms+6ms, total 140ms
09-17 22:45:25.068: D/dalvikvm(935): GC_CONCURRENT freed <1K, 17% free 5986K/7132K, paused 73ms+89ms, total 267ms
09-17 22:45:25.158: D/dalvikvm(935): GC_FOR_ALLOC freed 1500K, 9% free 4487K/4924K, paused 62ms, total 63ms
09-17 22:45:25.188: I/dalvikvm-heap(935): Grow heap (frag case) to 5.979MB for 1536016-byte allocation
09-17 22:45:25.398: D/dalvikvm(935): GC_CONCURRENT freed <1K, 7% free 5987K/6428K, paused 74ms+46ms, total 211ms
09-17 22:45:25.908: D/dalvikvm(935): GC_FOR_ALLOC freed 1500K, 27% free 5331K/7272K, paused 51ms, total 52ms
09-17 22:45:25.908: I/dalvikvm-heap(935): Grow heap (frag case) to 6.804MB for 1536016-byte allocation
09-17 22:45:26.128: D/dalvikvm(935): GC_CONCURRENT freed <1K, 7% free 6831K/7272K, paused 72ms+6ms, total 201ms
09-17 22:45:26.688: D/dalvikvm(935): GC_FOR_ALLOC freed 1500K, 24% free 6175K/8116K, paused 62ms, total 62ms
09-17 22:45:26.688: I/dalvikvm-heap(935): Grow heap (frag case) to 7.628MB for 1536016-byte allocation
09-17 22:45:26.898: D/dalvikvm(935): GC_CONCURRENT freed <1K, 6% free 7675K/8116K, paused 75ms+28ms, total 202ms
09-17 22:45:27.439: D/dalvikvm(935): GC_FOR_ALLOC freed 1500K, 22% free 7020K/8960K, paused 50ms, total 51ms
09-17 22:45:27.639: D/dalvikvm(935): GC_CONCURRENT freed <1K, 5% free 8520K/8960K, paused 71ms+22ms, total 185ms
09-17 22:45:28.129: D/dalvikvm(935): GC_FOR_ALLOC freed 1500K, 20% free 7864K/9804K, paused 46ms, total 46ms
09-17 22:45:28.609: D/dalvikvm(935): GC_FOR_ALLOC freed <1K, 5% free 9364K/9804K, paused 43ms, total 44ms
09-17 22:45:28.738: D/dalvikvm(935): GC_FOR_ALLOC freed 1500K, 19% free 8708K/10648K, paused 47ms, total 47ms
09-17 22:45:29.198: D/dalvikvm(935): GC_FOR_ALLOC freed <1K, 5% free 10208K/10648K, paused 45ms, total 46ms
09-17 22:45:29.318: D/dalvikvm(935): GC_FOR_ALLOC freed 1500K, 17% free 9553K/11492K, paused 40ms, total 46ms
09-17 22:45:29.808: D/dalvikvm(935): GC_FOR_ALLOC freed <1K, 4% free 11053K/11492K, paused 66ms, total 66ms
09-17 22:45:29.948: D/dalvikvm(935): GC_FOR_ALLOC freed 1500K, 16% free 10397K/12336K, paused 52ms, total 53ms
09-17 22:45:30.398: D/dalvikvm(935): GC_FOR_ALLOC freed <1K, 4% free 11897K/12336K, paused 56ms, total 57ms
09-17 22:45:30.518: D/dalvikvm(935): GC_FOR_ALLOC freed 1500K, 15% free 11241K/13180K, paused 48ms, total 49ms
09-17 22:45:30.958: D/dalvikvm(935): GC_FOR_ALLOC freed <1K, 4% free 12741K/13180K, paused 51ms, total 52ms
09-17 22:45:31.268: I/Choreographer(935): Skipped 72 frames!  The application may be doing too much work on its main thread.
09-17 22:45:31.298: D/gralloc_goldfish(935): Emulator without GPU emulation detected.
09-17 22:45:36.348: I/Choreographer(935): Skipped 79 frames!  The application may be doing too much work on its main thread.
09-17 22:45:36.458: I/Choreographer(935): Skipped 78 frames!  The application may be doing too much work on its main thread.
09-17 22:45:36.588: I/Choreographer(935): Skipped 83 frames!  The application may be doing too much work on its main thread.
09-17 22:45:36.808: I/Choreographer(935): Skipped 83 frames!  The application may be doing too much work on its main thread.
09-17 22:45:38.178: D/dalvikvm(935): GC_FOR_ALLOC freed 1507K, 14% free 12737K/14644K, paused 158ms, total 187ms
09-17 22:45:39.329: I/Choreographer(935): Skipped 2407 frames!  The application may be doing too much work on its main thread.
09-17 22:45:39.988: I/Choreographer(935): Skipped 620 frames!  The application may be doing too much work on its main thread.
09-17 22:45:40.748: I/Choreographer(935): Skipped 703 frames!  The application may be doing too much work on its main thread.
09-17 22:45:41.048: I/Choreographer(935): Skipped 285 frames!  The application may be doing too much work on its main thread.
09-17 22:45:43.338: I/Choreographer(935): Skipped 77 frames!  The application may be doing too much work on its main thread.
09-17 22:45:43.908: I/Choreographer(935): Skipped 40 frames!  The application may be doing too much work on its main thread.
09-17 22:45:44.338: I/Choreographer(935): Skipped 132 frames!  The application may be doing too much work on its main thread.
09-17 22:45:48.948: D/AndroidRuntime(935): Shutting down VM
09-17 22:45:48.948: W/dalvikvm(935): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
09-17 22:45:49.108: E/AndroidRuntime(935): FATAL EXCEPTION: main
09-17 22:45:49.108: E/AndroidRuntime(935): java.util.UnknownFormatConversionException: Conversion: 02
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.util.Formatter$FormatSpecifierParser.unknownFormatConversionException(Formatter.java:2304)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.util.Formatter$FormatSpecifierParser.advance(Formatter.java:2298)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.util.Formatter$FormatSpecifierParser.parseConversionType(Formatter.java:2377)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.util.Formatter$FormatSpecifierParser.parseWidth(Formatter.java:2360)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.util.Formatter$FormatSpecifierParser.parseArgumentIndexAndFlags(Formatter.java:2344)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.util.Formatter$FormatSpecifierParser.parseFormatToken(Formatter.java:2281)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.util.Formatter.doFormat(Formatter.java:1069)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.util.Formatter.format(Formatter.java:1040)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.util.Formatter.format(Formatter.java:1009)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.lang.String.format(String.java:1988)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.lang.String.format(String.java:1962)
09-17 22:45:49.108: E/AndroidRuntime(935):  at com.main.project.spotddifference.MainActivity$1.run(MainActivity.java:196)
09-17 22:45:49.108: E/AndroidRuntime(935):  at android.os.Handler.handleCallback(Handler.java:725)
09-17 22:45:49.108: E/AndroidRuntime(935):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-17 22:45:49.108: E/AndroidRuntime(935):  at android.os.Looper.loop(Looper.java:137)
09-17 22:45:49.108: E/AndroidRuntime(935):  at android.app.ActivityThread.main(ActivityThread.java:5041)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.lang.reflect.Method.invokeNative(Native Method)
09-17 22:45:49.108: E/AndroidRuntime(935):  at java.lang.reflect.Method.invoke(Method.java:511)
09-17 22:45:49.108: E/AndroidRuntime(935):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-17 22:45:49.108: E/AndroidRuntime(935):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-17 22:45:49.108: E/AndroidRuntime(935):  at dalvik.system.NativeStart.main(Native Method)
09-17 22:45:52.828: I/Process(935): Sending signal. PID: 935 SIG: 9
09-17 22:45:53.808: E/Trace(972): error opening trace file: No such file or directory (2)
09-17 22:45:54.478: D/dalvikvm(972): GC_FOR_ALLOC freed 41K, 8% free 2402K/2584K, paused 139ms, total 176ms
09-17 22:45:54.578: I/dalvikvm-heap(972): Grow heap (frag case) to 3.944MB for 1536016-byte allocation
09-17 22:45:54.748: D/dalvikvm(972): GC_FOR_ALLOC freed <1K, 5% free 3901K/4088K, paused 169ms, total 169ms
09-17 22:45:54.948: D/dalvikvm(972): GC_CONCURRENT freed <1K, 5% free 3901K/4088K, paused 15ms+26ms, total 199ms
09-17 22:45:56.298: D/dalvikvm(972): GC_FOR_ALLOC freed <1K, 5% free 3901K/4088K, paused 238ms, total 238ms
09-17 22:45:56.358: I/dalvikvm-heap(972): Grow heap (frag case) to 4.766MB for 864016-byte allocation
09-17 22:45:56.618: D/dalvikvm(972): GC_CONCURRENT freed 0K, 4% free 4745K/4932K, paused 74ms+35ms, total 258ms
09-17 22:45:57.848: D/dalvikvm(972): GC_FOR_ALLOC freed 1500K, 31% free 3872K/5560K, paused 140ms, total 170ms
09-17 22:45:58.218: D/dalvikvm(972): GC_CONCURRENT freed 625K, 34% free 3704K/5560K, paused 6ms+6ms, total 228ms
09-17 22:45:58.588: D/dalvikvm(972): GC_CONCURRENT freed 291K, 32% free 3805K/5560K, paused 77ms+33ms, total 174ms
09-17 22:45:58.868: I/Choreographer(972): Skipped 46 frames!  The application may be doing too much work on its main thread.
09-17 22:45:58.899: D/gralloc_goldfish(972): Emulator without GPU emulation detected.
09-17 22:46:13.848: I/Choreographer(972): Skipped 88 frames!  The application may be doing too much work on its main thread.
09-17 22:46:14.098: D/AndroidRuntime(972): Shutting down VM
09-17 22:46:14.118: W/dalvikvm(972): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
09-17 22:46:14.368: E/AndroidRuntime(972): FATAL EXCEPTION: main
09-17 22:46:14.368: E/AndroidRuntime(972): java.lang.RuntimeException: Unable to start activity ComponentInfo    {com.main.project.spotddifference/com.main.project.spotddifference.HelpActivity}: android.content.res.Resources$NotFoundException: Resource ID     #0x7f090014 type #0x12 is not valid
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.os.Looper.loop(Looper.java:137)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.app.ActivityThread.main(ActivityThread.java:5041)
09-17 22:46:14.368: E/AndroidRuntime(972):  at java.lang.reflect.Method.invokeNative(Native Method)
09-17 22:46:14.368: E/AndroidRuntime(972):  at java.lang.reflect.Method.invoke(Method.java:511)
09-17 22:46:14.368: E/AndroidRuntime(972):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-17 22:46:14.368: E/AndroidRuntime(972):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-17 22:46:14.368: E/AndroidRuntime(972):  at dalvik.system.NativeStart.main(Native Method)
09-17 22:46:14.368: E/AndroidRuntime(972): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f090014 type #0x12 is not valid
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:2144)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.content.res.Resources.getLayout(Resources.java:853)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-17 22:46:14.368: E/AndroidRuntime(972):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.app.Activity.setContentView(Activity.java:1881)
09-17 22:46:14.368: E/AndroidRuntime(972):  at com.main.project.spotddifference.HelpActivity.onCreate(HelpActivity.java:17)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.app.Activity.performCreate(Activity.java:5104)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-17 22:46:14.368: E/AndroidRuntime(972):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-17 22:46:14.368: E/AndroidRuntime(972):  ... 11 more
09-17 22:46:16.808: I/Process(972): Sending signal. PID: 972 SIG: 9

这是我的代码,请帮我解决这个问题。

4

4 回答 4

1

Cmon,您自己的 logcat 清楚地回答了您的问题。这实际上是您收到的一条非常清晰的异常消息,请不要低估:

09-17 22:45:49.108: E/AndroidRuntime(935): 
java.util.UnknownFormatConversionException: 
Conversion: 02
于 2013-09-18T03:46:47.743 回答
0

它很可能R.java没有重新生成,或者您的 XML 中存在 IDE 无法检测到的错误。无论如何,错误日志中的以下行可以提供帮助:Resource ID #0x7f090014 type #0x12 is not valid

打开您的R.java文件并尝试找到 Java 编译器为其设置了该值的变量。变量名称对应于 XML 文件中的一个元素。尝试查找元素并检查其 XML 文件是否未损坏。

作为最后的手段,开始一个一个地重建你的 XML 文件,一个个地标记,直到你找到问题。

于 2013-09-17T23:34:40.117 回答
0

logcat 显示:

这意味着某些格式化程序字符串存在问题,因此请检查:

String.format("%02",mins) 并用 "%02d" 制作它,它应该可以工作......

于 2013-09-17T23:39:38.547 回答
0

您可能因繁重的工作而冻结了 II 线程。花一些时间并使用 AsyncTask 实现线程

于 2013-09-18T03:36:22.547 回答