Results 1 to 8 of 8
  1. #1
    kameni123 is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Question Whats wrong here?

    Whats wrong with my programm? It gives me a notification when i pres a button thet rpstry has stoped running when i run it on my emulator.

    Java Code:
    package com.example.rpstry;
    
    import android.os.Bundle;
    import java.util.Random;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
    	
    	int p_choise;
    	int c_choise;
    	
    	int random_num;
    		
    	
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    		
    		final TextView player_choise_info = (TextView) findViewById (R.id.player_choiseView);
    		
    		
    		Button button_rock = (Button) findViewById (R.id.rock);
    		button_rock.setOnClickListener(new View.OnClickListener() {
    			
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				p_choise = 0;
    				player_choise_info.setText("Player choised: rock");
    				getCPU_choise();
    			}
    		});
    		
    		Button button_paper = (Button) findViewById (R.id.paper);
    		button_paper.setOnClickListener(new View.OnClickListener() {
    			
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				p_choise = 1;
    				player_choise_info.setText("Player choised: paper");
    				getCPU_choise();
    			}
    		});
    		
    		Button button_scissors = (Button) findViewById (R.id.scissors);
    		button_scissors.setOnClickListener(new View.OnClickListener() {
    			
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				p_choise = 2;
    				player_choise_info.setText("Player choised: scissors");
    				getCPU_choise();
    			}
    		});
    			
    	}
    	
    	public void getCPU_choise(){
    		
    		Random dice = new Random();
    		
    		int number;
    		
    		
    		number = dice.nextInt(3);
    		random_num = number;
    		
    		c_choise = random_num;
    		
    		final TextView cpu_choise_info = (TextView) findViewById (R.id.cpu_choiseView);
    				
    		cpu_choise_info.setText("CPU choise: " + c_choise);
    		
    		reslutating();
    	}
    	
    	public void reslutating(){
    		
    		final TextView result = (TextView) findViewById (R.id.result);
    		final TextView p_Score = (TextView) findViewById (R.id.p_score);
    		final TextView c_Score = (TextView) findViewById (R.id.c_score);
    		
    		int p_score = 0;
    		int c_score = 0;
    		
    //		ROCK = 0    PAPER=1  SCISSORS=2
    		if(p_choise == 0 && c_choise == 0){
    			result.setText("Draw!");
    		}
    		if(p_choise == 0 && c_choise == 1){
    			result.setText("CPU wins!");
    			c_score++;
    			c_Score.setText(c_score);
    		}
    		if(p_choise == 0 && c_choise == 2){
    			result.setText("Player wins!");
    			p_score++;
    			p_Score.setText(p_score);
    		}
    		
    		//		Case Player = Paper
    		if(p_choise == 1 && c_choise == 1){
    			result.setText("Draw!");
    		}
    		else if(p_choise == 1 && c_choise == 3){
    			result.setText("CPU wins!");
    			c_score++;
    			c_Score.setText(c_score);
    		}
    		else if(p_choise == 1 && c_choise == 0){
    			result.setText("Player wins!");
    			p_score++;
    			p_Score.setText(p_score);
    		}
    		
    		//		Case Player = Scissors
    		else if(p_choise == 2 && c_choise == 2){
    			result.setText("Draw!");
    		}
    		else if(p_choise == 2 && c_choise == 0){
    			result.setText("CPU wins!");
    			c_score++;
    			c_Score.setText(c_score);
    		}
    		else if(p_choise == 2 && c_choise == 1){
    			result.setText("Player wins!");
    			p_score++;
    			p_Score.setText(p_score);
    		}
    	}
    
    
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.main, menu);
    		return true;
    	}
    	
    
    
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: Whats wrong here?

    rpstry has stoped running
    What error messages are shown in the Logcat?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kameni123 is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Default Re: Whats wrong here?

    I dont know is this is good im using LogCat for the first time I saw a video where he showed how to place a message at the place where I want I seted Log.i("Mymessage", "Here it gets wrong") and I copied you all under thet.

    03-11 13:55:41.050: W/ResourceType(893): No package identifier when getting value for resource number 0x00000001
    03-11 13:55:41.050: D/AndroidRuntime(893): Shutting down VM
    03-11 13:55:41.050: W/dalvikvm(893): threadid=1: thread exiting with uncaught exception (group=0xb3a44ba8)
    03-11 13:55:41.070: E/AndroidRuntime(893): FATAL EXCEPTION: main
    03-11 13:55:41.070: E/AndroidRuntime(893): Process: com.example.rpstry, PID: 893
    03-11 13:55:41.070: E/AndroidRuntime(893): android.content.res.Resources$NotFoundException: String resource ID #0x1
    03-11 13:55:41.070: E/AndroidRuntime(893): at android.content.res.Resources.getText(Resources.ja va:244)
    03-11 13:55:41.070: E/AndroidRuntime(893): at android.widget.TextView.setText(TextView.java:3888 )
    03-11 13:55:41.070: E/AndroidRuntime(893): at com.example.rpstry.MainActivity.reslutating(MainAc tivity.java:109)
    03-11 13:55:41.070: E/AndroidRuntime(893): at com.example.rpstry.MainActivity.getCPU_choise(Main Activity.java:85)
    03-11 13:55:41.070: E/AndroidRuntime(893): at com.example.rpstry.MainActivity$1.onClick(MainActi vity.java:38)
    03-11 13:55:41.070: E/AndroidRuntime(893): at android.view.View.performClick(View.java:4438)
    03-11 13:55:41.070: E/AndroidRuntime(893): at android.view.View$PerformClick.run(View.java:18422 )
    03-11 13:55:41.070: E/AndroidRuntime(893): at android.os.Handler.handleCallback(Handler.java:733 )
    03-11 13:55:41.070: E/AndroidRuntime(893): at android.os.Handler.dispatchMessage(Handler.java:95 )
    03-11 13:55:41.070: E/AndroidRuntime(893): at android.os.Looper.loop(Looper.java:136)
    03-11 13:55:41.070: E/AndroidRuntime(893): at android.app.ActivityThread.main(ActivityThread.jav a:5017)
    03-11 13:55:41.070: E/AndroidRuntime(893): at java.lang.reflect.Method.invokeNative(Native Method)
    03-11 13:55:41.070: E/AndroidRuntime(893): at java.lang.reflect.Method.invoke(Method.java:515)
    03-11 13:55:41.070: E/AndroidRuntime(893): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:779)
    03-11 13:55:41.070: E/AndroidRuntime(893): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:595)
    03-11 13:55:41.070: E/AndroidRuntime(893): at dalvik.system.NativeStart.main(Native Method)
    03-11 13:55:44.260: I/Process(893): Sending signal. PID: 893 SIG: 9

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: Whats wrong here?

    FATAL EXCEPTION: main
    Process: com.example.rpstry, PID: 893
    android.content.res.Resources$NotFoundException: String resource ID #0x1
    at android.content.res.Resources.getText(Resources.ja va:244)
    at android.widget.TextView.setText(TextView.java:3888 )
    at com.example.rpstry.MainActivity.reslutating(MainAc tivity.java:109)
    at com.example.rpstry.MainActivity.getCPU_choise(Main Activity.java:85)
    at com.example.rpstry.MainActivity$1.onClick(MainActi vity.java:38)
    at android.view.View.performClick(View.java:4438)
    at android.view.View$PerformClick.run(View.java:18422 )
    The code is getting a .Resources$NotFoundException: String resource ID #0x1
    at the call to setText() on line 109
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    kameni123 is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Default Re: Whats wrong here?

    How do I fix it?

    and ty for helping me

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: Whats wrong here?

    I haven't been working with Android for very long. If you do an internet search about your problem you'll probably find a site that has a lot more knowledgeable people.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Whats wrong here?

    I don't see anything around line 109 that would produce that error message. Are you sure you're posting the right code? Are you sure you recompiled it after your last changes?

    Edit: The stack trace refers to the method that is on lines 65-82. Your error definitely doesn't correspond to your code.
    Last edited by kjkrum; 03-11-2014 at 11:10 PM.
    Get in the habit of using standard Java naming conventions!

  8. #8
    kameni123 is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Default Re: Whats wrong here?

    yes i recompiled and thets the right code idk where the error is i will learn more and try to make the game later ty for help all

Similar Threads

  1. Help! I don't know whats wrong.
    By xxgetownedxx in forum New To Java
    Replies: 3
    Last Post: 08-16-2013, 10:32 AM
  2. whats wrong with my GUI?
    By EscSequenceAlpha in forum New To Java
    Replies: 12
    Last Post: 05-31-2012, 09:20 PM
  3. I cant do this.Whats wrong?
    By gaston7eze in forum Java 2D
    Replies: 5
    Last Post: 05-30-2012, 01:34 AM
  4. Whats wrong with this?
    By Alkor in forum AWT / Swing
    Replies: 7
    Last Post: 04-03-2012, 06:49 AM
  5. whats wrong
    By atenv in forum New To Java
    Replies: 6
    Last Post: 06-15-2010, 02:55 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •