-3

I got all my code set up and completed. I tried running my app to make sure it functions as it should and I get a Unfortunately your app has stopped. I tried looking at other examples of this problem but couldn't find out what actually is wrong with my app. I checked my LogCat and still couldn't figure it out. If I could get a hand on what I should look at I would appreciate it.

10-11 22:13:01.521: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
10-11 22:13:01.540: W/AudioService(286): onLoadSoundEffects(), Error -1 while loading samples
10-11 22:13:01.551: I/ActivityManager(286): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=net.androidbootcamp.zipcarrentalapp/.MainActivity} from pid 414
10-11 22:13:01.611: W/WindowManager(286): Screenshot failure taking screenshot for (266x425) to layer 21010
10-11 22:13:01.691: W/dalvikvm(859): PR_CAPBSET_DROP 0 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
10-11 22:13:01.771: D/dalvikvm(859): Not late-enabling CheckJNI (already on)
10-11 22:13:01.781: I/ActivityManager(286): Start proc net.androidbootcamp.zipcarrentalapp for activity net.androidbootcamp.zipcarrentalapp/.MainActivity: pid=859 uid=10046 gids={50046, 1028}
10-11 22:13:03.620: D/AndroidRuntime(859): Shutting down VM
10-11 22:13:03.650: W/dalvikvm(859): threadid=1: thread exiting with uncaught exception (group=0x41465700)
10-11 22:13:03.770: E/AndroidRuntime(859): FATAL EXCEPTION: main
10-11 22:13:03.770: E/AndroidRuntime(859): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.androidbootcamp.zipcarrentalapp/net.androidbootcamp.zipcarrentalapp.MainActivity}: java.lang.NullPointerException
10-11 22:13:03.770: E/AndroidRuntime(859):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
10-11 22:13:03.770: E/AndroidRuntime(859):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-11 22:13:03.770: E/AndroidRuntime(859):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-11 22:13:03.770: E/AndroidRuntime(859):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-11 22:13:03.770: E/AndroidRuntime(859):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 22:13:03.770: E/AndroidRuntime(859):  at android.os.Looper.loop(Looper.java:137)
10-11 22:13:03.770: E/AndroidRuntime(859):  at android.app.ActivityThread.main(ActivityThread.java:5103)
10-11 22:13:03.770: E/AndroidRuntime(859):  at java.lang.reflect.Method.invokeNative(Native Method)
10-11 22:13:03.770: E/AndroidRuntime(859):  at java.lang.reflect.Method.invoke(Method.java:525)
10-11 22:13:03.770: E/AndroidRuntime(859):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-11 22:13:03.770: E/AndroidRuntime(859):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-11 22:13:03.770: E/AndroidRuntime(859):  at dalvik.system.NativeStart.main(Native Method)
10-11 22:13:03.770: E/AndroidRuntime(859): Caused by: java.lang.NullPointerException
10-11 22:13:03.770: E/AndroidRuntime(859):  at android.app.Activity.findViewById(Activity.java:1853)
10-11 22:13:03.770: E/AndroidRuntime(859):  at net.androidbootcamp.zipcarrentalapp.MainActivity.(MainActivity.java:16)
10-11 22:13:03.770: E/AndroidRuntime(859):  at java.lang.Class.newInstanceImpl(Native Method)
10-11 22:13:03.770: E/AndroidRuntime(859):  at java.lang.Class.newInstance(Class.java:1130)
10-11 22:13:03.770: E/AndroidRuntime(859):  at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-11 22:13:03.770: E/AndroidRuntime(859):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
10-11 22:13:03.770: E/AndroidRuntime(859):  ... 11 more
10-11 22:13:04.510: W/ActivityManager(286):   Force finishing activity net.androidbootcamp.zipcarrentalapp/.MainActivity
10-11 22:13:04.983: I/WindowManager(286): Screenshot max retries 4 of Token{41ad2f58 ActivityRecord{41989b98 u0 net.androidbootcamp.zipcarrentalapp/.MainActivity}} appWin=Window{41ab4b70 u0 Starting net.androidbootcamp.zipcarrentalapp} drawState=4
10-11 22:13:04.983: W/WindowManager(286): Screenshot failure taking screenshot for (800x1280) to layer 21015
10-11 22:13:05.010: W/ActivityManager(286):   Force finishing activity com.android.customlocale2/.CustomLocaleActivity
10-11 22:13:05.450: I/Choreographer(414): Skipped 423 frames!  The application may be doing too much work on its main thread.
10-11 22:13:05.720: W/ActivityManager(286): Activity pause timeout for ActivityRecord{41989b98 u0 net.androidbootcamp.zipcarrentalapp/.MainActivity}
10-11 22:13:05.970: I/Choreographer(286): Skipped 33 frames!  The application may be doing too much work on its main thread.
10-11 22:13:06.410: I/Choreographer(414): Skipped 32 frames!  The application may be doing too much work on its main thread.
10-11 22:13:06.780: I/ActivityManager(286): Activity reported stop, but no longer stopping: ActivityRecord{419b5e78 u0 com.android.launcher/com.android.launcher2.Launcher}
10-11 22:13:08.680: E/SoundPool(286): error loading /system/media/audio/ui/Effect_Tick.ogg
10-11 22:13:08.680: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
10-11 22:13:08.871: E/SoundPool(286): error loading /system/media/audio/ui/KeypressStandard.ogg
10-11 22:13:08.871: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
10-11 22:13:08.911: E/SoundPool(286): error loading /system/media/audio/ui/KeypressSpacebar.ogg
10-11 22:13:08.911: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
10-11 22:13:08.931: E/SoundPool(286): error loading /system/media/audio/ui/KeypressDelete.ogg
10-11 22:13:08.971: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
10-11 22:13:08.971: E/SoundPool(286): error loading /system/media/audio/ui/KeypressReturn.ogg
10-11 22:13:08.990: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
10-11 22:13:09.001: W/AudioService(286): onLoadSoundEffects(), Error -1 while loading samples
10-11 22:13:09.052: I/Process(859): Sending signal. PID: 859 SIG: 9
10-11 22:13:09.521: I/ActivityManager(286): Process net.androidbootcamp.zipcarrentalapp (pid 859) has died.
10-11 22:13:10.610: I/Choreographer(839): Skipped 603 frames!  The application may be doing too much work on its main thread.
package net.androidbootcamp.zipcarrentalapp;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;


public class MainActivity extends ActionBarActivity 
{
    private RadioGroup radioGroupId;
    private RadioButton radioButton;
    private Button button;
        final RadioButton Compact = (RadioButton)findViewById(R.id.radCompact);
        final RadioButton MidSize = (RadioButton)findViewById(R.id.radMidSize);
        final RadioButton Luxury = (RadioButton)findViewById(R.id.radLuxury);
        final TextView txtResult = (TextView) findViewById(R.id.txtResult);
        double radCompact = 59.99;
        double radMidSize = 65.99;
        double radLuxury = 89.99;
        int days = 0;
        double computeValue;

        public void operation(int days)
        {
            if(days <= 10)
            {
                if(Compact.isChecked())
                {
                    computeValue = radCompact * days;
                    txtResult.setText("Cost:" + Double.toString(computeValue));

                }

                else if (MidSize.isChecked())
                {
                    computeValue = radMidSize * days;
                    txtResult.setText("Cost: " + Double.toString(computeValue));
                }
                else if (Luxury.isChecked())
               {
                    computeValue = radLuxury * days;
                    txtResult.setText("Cost:" + Double.toString(computeValue));
                }
            }
        }

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


    @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;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) 
        {
            return true;
        }
       return super.onOptionsItemSelected(item);
    }
}
  • I suspect that your problem is similar to this one: http://stackoverflow.com/questions/23653778/nullpointerexception-accessing-views-in-oncreate – Stephen C Oct 12 '14 at 03:07
  • I am not sure why are you getting a null pointer exception. The looks code looks fine... I had problem earlier with`Double.toString(...)` so once try doing this - `String.valueOf(computeValue);` – Confuse Oct 12 '14 at 03:11
  • @Neutrino, I tried doing what you said and also what user4133647 said each on its seperate tries. I have no success. Im still getting the same " unfortunately your app has stopped". I reviewed the link that StephenC gave me but was unable to figure this out as well. I am still fairly new to android development and im not sure why its not running. – Average Joe Oct 12 '14 at 03:24
  • Check 323go's answer. It will answer your question... – Confuse Oct 12 '14 at 05:36

1 Answers1

1

You can't use findViewById in the class definition. There's no view defined. All of those findViewById() calls belong after setContentView() in your onCreate().

Change this:

final RadioButton Compact = (RadioButton)findViewById(R.id.radCompact);
final RadioButton MidSize = (RadioButton)findViewById(R.id.radMidSize);
final RadioButton Luxury = (RadioButton)findViewById(R.id.radLuxury);
final TextView txtResult = (TextView) findViewById(R.id.txtResult);

to

RadioButton Compact;
RadioButton MidSize;
RadioButton Luxury;
TextView txtResult;

and change

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

to

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Compact = (RadioButton) findViewById(R.id.radCompact);
    MidSize = (RadioButton) findViewById(R.id.radMidSize);
    Luxury = (RadioButton) findViewById(R.id.radLuxury);
    txtResult = (TextView) findViewById(R.id.txtResult);
}

As a matter of style and convention, you should start member names with lower case letters, such as Compact would better be rbCompact, etc.

323go
  • 14,143
  • 6
  • 33
  • 41