程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-開發app時遇到Source not found的錯誤

android-開發app時遇到Source not found的錯誤

編輯:編程綜合問答
開發app時遇到"Source not found"的錯誤

我今天在做一個app,但是我好想不能找到代碼中的錯誤。
當我檢查的時候,沒有語法錯誤,但是當我想要運行或者是測試的時候,就會報錯:
"Source not found" on "ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2106`

它讓我找另外一個路徑,但是只有一個可用的默認設置。我代碼錯了嗎?怎麼解決?

這是logcat:

12-20 22:12:29.722: I/System.out(1518): debugger has settled (1479) 
12-20 22:12:30.172: W/Trace(1518): Unexpected value from nativeGetEnabledTags: 0 
12-20 22:12:30.222: W/Trace(1518): Unexpected value from nativeGetEnabledTags: 0

這個是控制台報的錯誤:

[2012-12-20 17:19:45 - rockPaperScissorLizardSpock] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.rockpaperscissorlizardspock/.MainActivity }
[2012-12-20 17:19:45 - rockPaperScissorLizardSpock] ActivityManager: Warning: Activity not started, its current task has been brought to the front

這是我源文件:

package com.example.rockpaperscissorlizardspock;
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.view.View.OnClickListener;

public class rockpaperscissorlizardspock extends Activity {
    /**當activity第一次創建的時候調用 */

    private TextView resultText;
    private Button play, reset;
    private ImageButton scissors, paper, rock, lizard, spock;
    private int paperimg, paper_pressedimg, scissorsimg, scissors_pressedimg,     rockimg, rock_pressedimg, lizardimg, lizard_pressedimg, spockimg, spock_pressedimg;
        private ImageView compSciss, compPaper, compRock, compLiz, compSpock;
    Random rand = new Random();
    int compChoice = 0;
    String pChoice ="";
    String cChoice = "";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Initialize();
    }

    /** 初始化所有的組件*/
     private void Initialize()
    {
        play = (Button) findViewById(R.id.button1);
        reset = (Button) findViewById(R.id.button2);
        resultText = (TextView) findViewById(R.id.resultText);
        lizard = (ImageButton) findViewById(R.id.imageButton4);
        spock = (ImageButton) findViewById(R.id.imageButton5);
        scissors = (ImageButton) findViewById(R.id.imageButton3);
        paper = (ImageButton) findViewById(R.id.imageButton2);
        rock = (ImageButton) findViewById(R.id.imageButton1);
        compSciss = (ImageView) findViewById(R.id.computerScissors);
        compPaper = (ImageView) findViewById(R.id.computerPaper);
        compRock = (ImageView) findViewById(R.id.computerRock);
        spockimg = R.raw.spock;
        spock_pressedimg = R.raw.spock_pressed;
        lizardimg = R.raw.lizard;
        lizard_pressedimg = R.raw.lizard_pressed;
        paperimg = R.raw.paper;
        paper_pressedimg = R.raw.paper_pressed;
        scissorsimg = R.raw.scissors;
        scissors_pressedimg = R.raw.scissors_pressed;
        rockimg = R.raw.rock1;
        rock_pressedimg = R.raw.rock1_pressed;

        /**設置按鈕 Listeners*/
        play.setOnClickListener(new OnClickListener(){
            public void onClick(View arg0){
                play();
            }
        });

        reset.setOnClickListener(new OnClickListener(){
             public void onClick(View arg0){
                paper.setImageResource(paperimg);

                 rock.setImageResource(rockimg);
                scissors.setImageResource(scissorsimg);
                lizard.setImageResource(lizardimg);
                spock.setImageResource(spockimg);
                compPaper.setImageResource(paperimg);
                compRock.setImageResource(rockimg);
                compSciss.setImageResource(scissorsimg);
                compLiz.setImageResource(lizardimg);
                compSpock.setImageResource    (spockimg);               
                pChoice = "";
                cChoice = "";
                play.setEnabled(false);
                reset.setEnabled(true);
                scissors.setEnabled(true);
                paper.setEnabled(true);
                rock.setEnabled(true);
                lizard.setEnabled(true);
                spock.setEnabled(true);
                resultText.setText("");
            }
        });

        /*
         * 當特殊的選擇做出的時候聲明
         */

        scissors.setOnClickListener(new OnClickListener(){
             public void onClick(View arg0){    
                     scissors.setImageResource(scissors_pressedimg);
                    paper.setImageResource(paperimg);
                    rock.setImageResource(rockimg);
                    spock.setImageResource(spockimg);
                    lizard.setImageResource(lizardimg);
                    pChoice = "S";
                    play.setEnabled(true);
             }
         });

         paper.setOnClickListener(new OnClickListener(){
            public void onClick(View arg0){
                    paper.setImageResource(paper_pressedimg);
                    scissors.setImageResource(scissorsimg);
                    spock.setImageResource(spockimg);
                    rock.setImageResource(rockimg);
                    lizard.setImageResource(lizardimg);
                    pChoice = "P";
                    play.setEnabled(true);
            }
         });

        rock.setOnClickListener(new OnClickListener(){
            public void onClick(View arg0){
                rock.setImageResource(rock_pressedimg);
                scissors.setImageResource(scissorsimg);
                paper.setImageResource(paperimg);
                spock.setImageResource(spockimg);
                lizard.setImageResource(lizardimg);
                pChoice = "R";
                play.setEnabled(true);
            }
        });

        lizard.setOnClickListener(new OnClickListener(){
             public void onClick(View arg0){
                 lizard.setImageResource(lizard_pressedimg);
                 spock.setImageResource(spockimg);
                 rock.setImageResource(rockimg);
                 scissors.setImageResource(scissorsimg);
                 paper.setImageResource(paperimg);
                 pChoice = "L";
                 play.setEnabled(true);
            }
         });

        spock.setOnClickListener(new OnClickListener(){
            public void onClick(View arg0){
                spock.setImageResource(spock_pressedimg);
                lizard.setImageResource(lizardimg);
                rock.setImageResource(rockimg);
                scissors.setImageResource(scissorsimg);
                paper.setImageResource(paperimg);
                pChoice = "SP";
                play.setEnabled(true);
            }
        });

    }

    /**這個方法是對電腦的移動和player的移動做出選擇
     *  
     */
    public void play()
    {
        compChoice = rand.nextInt(5);

        if(compChoice == 0)
        {
            cChoice = "R";
            compRock.setImageResource(rock_pressedimg);
            }
        else if(compChoice == 1){
            cChoice = "P";
            compPaper.setImageResource(paper_pressedimg);
        }       
         else if(compChoice == 2)
        {
            cChoice = "S";
            compSciss.setImageResource(scissors_pressedimg);
            }
        else if(compChoice == 3)
           {
            cChoice = "L";
             compLiz.setImageResource(lizard_pressedimg);
            }
        else if(compChoice == 4)
       { 
       cChoice = "SP";
       compSpock.setImageResource(spock_pressedimg);
       }

    check();
}

/**
 * 比較電腦和player的移動
 */
public void check()
{
    if(pChoice == "R") //Rock
    {
        if(cChoice == "R")
            resultText.setText("Draw");

        else if(cChoice == "P")
            resultText.setText("You Lose");

        else if(cChoice == "S")
            resultText.setText("You Win");

        else if(cChoice == "L")
            resultText.setText("You Win");

        else if(cChoice == "SP")
            resultText.setText("You Lose");
    }

    else if(pChoice == "P") //Paper
    {
        if(cChoice == "R")
            resultText.setText("You Win");

        else if(cChoice == "P")
            resultText.setText("Draw");

        else if(cChoice == "S")
            resultText.setText("You Lose");

        else if(cChoice == "SP")
            resultText.setText("You Win");

        else if(cChoice == "L")
            resultText.setText("You Lose");


    }

    else if(pChoice == "S") //Scissors
    {
        if(cChoice == "R")
            resultText.setText("You Lose");

        else if(cChoice == "P")
            resultText.setText("You Win");

        else if(cChoice == "S")
            resultText.setText("Draw");

        else if(cChoice == "L")
            resultText.setText("You Win");

        else if(cChoice == "SP")
            resultText.setText("You Lose");


    }

    else if(pChoice == "L") //Lizard
    {
      if(cChoice == "R")
        resultText.setText("You Lose");

      else if(cChoice == "L")
        resultText.setText("Draw");

      else if(cChoice == "SP")
        resultText.setText("You Win");

      else if(cChoice == "S")
        resultText.setText("You Lose");

      else if(cChoice == "P")
        resultText.setText("You Win");
    }

    else if(pChoice == "SP") //Spock
    {
        if(cChoice == "SP")
            resultText.setText("Draw");

        else if(cChoice == "L")
            resultText.setText("You Lose");

        else if(cChoice == "S")
            resultText.setText("You Win");

        else if(cChoice == "P")
            resultText.setText("You Lose");

        else if(cChoice == "R")
            resultText.setText("You Win");

    }

    gameOver();
}


/**
 * 在每次round後運行,除了reset按鈕禁用所有按鈕
 * 
 */
public void gameOver()
{
    play.setEnabled(false);
    scissors.setEnabled(false);
    rock.setEnabled(false);
    paper.setEnabled(false);
    spock.setEnabled(false);
    lizard.setEnabled(false);
    reset.setEnabled(true);
}

最佳回答:


看起來好像你需要給你的AndroidManifest.xml加activity。看起來應該是這樣,被定位在app的部分manifest中。詳細的你可以看看這個http://developer.android.com/guide/topics/manifest/manifest-intro.html
這個是一個例子:

<activity
    android:name=".rockpaperscissorlizardspock"
    android:label="@string/app_name"
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved