Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9069725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:30:19+00:00 2026-06-16T17:30:19+00:00

I am creating a simple Click Counter Android App using Java. I am new

  • 0

I am creating a simple Click Counter Android App using Java. I am new to Java. Here is my code below, the gui has different buttons with different functions, for example the count button itself, a reset count button, and a mute sound button.

public class wazeefa extends Activity { 

//Count Button 
TextView txtCount; 
ImageView image; 
Button btnCount; 
Button wmute; 
Button wreset; 
public static int count=0; 
SharedPreferences app_preferences; 
MediaPlayer mpButtonClick; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
// The activity is being created. 
setContentView(R.layout.wazeefa); 

//SAVE COUNT 
app_preferences = this.getSharedPreferences("myPrefscount", MODE_WORLD_READABLE); 


count = app_preferences.getInt("count", 0); 

txtCount = (TextView)findViewById(R.id.wcount); 
txtCount.setText("This app has been started " + count + " times."); 


txtCount = (TextView)findViewById(R.id.wcount); 
txtCount.setText("This app has been started " + count + " times."); 

//Button SOUND AND COUNT 
mpButtonClick = MediaPlayer.create(this, R.raw.bubble); 
//RESET Button 
wreset = (Button)findViewById(R.id.wreset); 

txtCount = (TextView)findViewById(R.id.wcount); 
txtCount.setText(String.valueOf(count)); 

btnCount = (Button)findViewById(R.id.wclick); 
btnCount.setOnClickListener(new View.OnClickListener() { 
public void onClick(View v) { 
image = (ImageView) findViewById(R.id.imageview); 
count++; 
if (count > 50) count = 0; image.setImageResource(R.drawable.duroodimage); 
if (count > 0) image.setImageResource(R.drawable.duroodimage); 
if (count > 9) image.setImageResource(R.drawable.zikrimage); 
if (count > 39) image.setImageResource(R.drawable.duroodimage); 
txtCount.setText(String.valueOf(count)); 
} 
}); 

wreset.setOnClickListener(new View.OnClickListener() { 
public void onClick(View v) { 
count = 0; 
image.setImageResource(R.drawable.duroodimage);; 
txtCount.setText("0"); 
} 
}); 
} 

@Override 
protected void onPause() { 
super.onPause(); 
// save count value here 

SharedPreferences.Editor editor = app_preferences.edit(); 
editor.putInt("count", count); 
editor.commit(); 
}

//MUTE button
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.wmute:
AudioManager.setMode(AudioManager.MODE_IN_CALL);
AudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);
default:
AudioManager.setMode(AudioManager.MODE_NORMAL );
AudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, false);
break;
}

}

I have 1 issue:

When I go back into the app and the count shows as ‘5’ just for example, the Reset button no longer functions – it does nothing, I get an error message on AVD saying ‘unfortunately ‘App’ has stopped’. But when I continue the count and then hit the Reset button it works changes the count to zero again

Any suggestions on the above issue, have I missed anything or placed code in the wrong areas? The button sound was working before I edited the code, to save the ‘count’ data.
Let me know if I’m being vague…

The Crash Log:

12-24 18:07:42.661: W/Trace(3633): Unexpected value from nativeGetEnabledTags: 0
12-24 18:07:42.741: D/AndroidRuntime(3633): Shutting down VM
12-24 18:07:42.741: W/dalvikvm(3633): threadid=1: thread exiting with uncaught     exception (group=0x40a70930)
12-24 18:07:42.811: E/AndroidRuntime(3633): FATAL EXCEPTION: main
12-24 18:07:42.811: E/AndroidRuntime(3633): java.lang.NullPointerException
12-24 18:07:42.811: E/AndroidRuntime(3633):     at  com.shaadcorp.wazaifapp.wazeefa$2.onClick(wazeefa.java:81)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at android.view.View.performClick(View.java:4202)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at android.view.View$PerformClick.run(View.java:17340)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at android.os.Handler.handleCallback(Handler.java:725)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at  android.os.Handler.dispatchMessage(Handler.java:92)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at android.os.Looper.loop(Looper.java:137)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at android.app.ActivityThread.main(ActivityThread.java:5039)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at java.lang.reflect.Method.invokeNative(Native Method)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at java.lang.reflect.Method.invoke(Method.java:511)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-24 18:07:42.811: E/AndroidRuntime(3633):     at dalvik.system.NativeStart.main(Native     Method)
12-24 18:07:48.842: I/Process(3633): Sending signal. PID: 3633 SIG: 9
12-24 18:07:51.572: E/Trace(3808): error opening trace file: No such file or directory     (2)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:30:21+00:00Added an answer on June 16, 2026 at 5:30 pm

    fixed issue, thanks for your help Passionate Androiden.

    public class wazeefa extends Activity {
    
    //Count Button
    TextView txtCount;
    ImageView image;
    Button btnCount;
    Button wmute;
    Button wreset;
    public static int count=0;
    SharedPreferences app_preferences;
    MediaPlayer mpButtonClick;
    AudioManager audioManager;
    public static boolean mutestatus=false;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // The activity is being created.
    setContentView(R.layout.wazeefa);
    
    
    
    
    audioManager =
    (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    //SAVE COUNT
    app_preferences = this.getSharedPreferences("myPrefscount", MODE_WORLD_READABLE);
    
    
    count = app_preferences.getInt("count", 0);
    
    txtCount = (TextView)findViewById(R.id.wcount);
    txtCount.setText("This app has been started " + count + " times.");
    
    image = (ImageView) findViewById(R.id.imageview);
    
    txtCount = (TextView)findViewById(R.id.wcount);
    txtCount.setText("This app has been started " + count + " times.");
    
    //Button SOUND AND COUNT
    mpButtonClick = MediaPlayer.create(this, R.raw.bubble);
    //RESET Button
    wreset = (Button)findViewById(R.id.wreset);
    
    txtCount = (TextView)findViewById(R.id.wcount);
    txtCount.setText(String.valueOf(count));
    
    btnCount = (Button)findViewById(R.id.wclick);
    
    wmute=(Button)findViewById(R.id.wmute);
    
    btnCount.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    
    count++;
    if (count > 50) count = 0; image.setImageResource(R.drawable.duroodimage);
    if (count > 0) image.setImageResource(R.drawable.duroodimage);
    if (count > 9) image.setImageResource(R.drawable.zikrimage);
    if (count > 39) image.setImageResource(R.drawable.duroodimage);
    txtCount.setText(String.valueOf(count));
    mpButtonClick.start();
    }
    });
    
    wreset.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    count = 0;
    image.setImageResource(R.drawable.duroodimage);;
    txtCount.setText("0");
    SharedPreferences.Editor editor = app_preferences.edit();
    editor.putInt("count", count);
    editor.commit();
    }
    });
    
    
    wmute.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    if(!mutestatus){
    mutestatus=true;
    audioManager.setMode(AudioManager.MODE_IN_CALL);
    audioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);
    Log.v("'test....",""+mutestatus);
    }
    else{
    mutestatus=false;
    audioManager.setMode(AudioManager.MODE_NORMAL );
    audioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, false);
    Log.v("'test....",""+mutestatus);
    }
    }});
    }
    
    @Override
    protected void onPause() {
    super.onPause();
    // save count value here
    
    SharedPreferences.Editor editor = app_preferences.edit();
    editor.putInt("count", count);
    editor.commit();
    
    
    }
    
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a simple Click Counter Android App using Java. I am new
I'm creating a simple click counter android app, sound is played when a button
I'm creating an app on android in java, very simple, which has a button
I'm creating a gui application that requires some simple input, however, when I click
Following this question Click Here . I thought of creating a simple IDE for
I am new to Android programming. I am creating a very simple application in
I am creating a simple Android App, in which the first screen would present
I'm trying to write a simple timer app. I'm creating a counter class that
I'm creating simple editor in Java FX using codemirror.js library. I embeded codemirror editor
I'm creating a simple calculator on VB6. Here's my code I'm working on: textScreen.Text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.