• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps My first app force closes on opening..

falkon114

Newbie
Just finished writing my first app for my CS class. I tested it on the emulator after finally getting button ids to work (PITA :mad: for some reason), and so went along coding some buttons and a textView and editText object.

I get no compiler errors, but any time I try to open the app on the emulator, it crashes and has to force close... Any ideas?
Let me know what code you want me to post, as I don't want to post all of my code right off the bat unless I should.
TIA
 
We need to know what kind of exception is beeing thrown.
So do this:

- Go to: Window -> Show View -> Other, Android -> Logcat
- Start the app in the emulator
- The Logcat window will now be populated with a whole bunch
- When the app force closes, the logcat will contain an exception, a long list.
- Copy it, or take a snap show or what ever and post it here
 
Well, the first time I ran log cat, it recoded everything fine. I changed a couple things, cleared the log, re ran my program and now nothing is being displayed there at all, and my program is definitely still crashing.. :(
 
Alright. Thank you rooted tethering capabilities. Now that I can post my errors, this should help...
Code:
04-03 09:53:30.885: ERROR/Zygote(33): setreuid() failed. errno: 2
04-03 09:53:40.176: ERROR/Zygote(33): setreuid() failed. errno: 17
04-03 09:53:41.745: ERROR/BatteryService(59): usbOnlinePath not found
04-03 09:53:41.745: ERROR/BatteryService(59): batteryVoltagePath not found
04-03 09:53:41.745: ERROR/BatteryService(59): batteryTemperaturePath not found
04-03 09:53:41.775: ERROR/SurfaceFlinger(59): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
04-03 09:53:51.225: ERROR/EventHub(59): could not get driver version for /dev/input/mouse0, Not a typewriter
04-03 09:53:51.225: ERROR/EventHub(59): could not get driver version for /dev/input/mice, Not a typewriter
04-03 09:53:51.485: ERROR/System(59): Failure starting core service
04-03 09:53:51.485: ERROR/System(59): java.lang.SecurityException
04-03 09:53:51.485: ERROR/System(59):     at android.os.BinderProxy.transact(Native Method)
04-03 09:53:51.485: ERROR/System(59):     at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
04-03 09:53:51.485: ERROR/System(59):     at android.os.ServiceManager.addService(ServiceManager.java:72)
04-03 09:53:51.485: ERROR/System(59):     at com.android.server.ServerThread.run(SystemServer.java:184)
04-03 09:53:53.265: ERROR/SoundPool(59): error loading /system/media/audio/ui/Effect_Tick.ogg
04-03 09:53:53.265: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressStandard.ogg
04-03 09:53:53.275: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressSpacebar.ogg
04-03 09:53:53.285: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressDelete.ogg
04-03 09:53:53.295: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressReturn.ogg
04-03 09:53:57.315: ERROR/ThrottleService(59): Could not open GPS configuration file /etc/gps.conf
04-03 09:53:58.385: ERROR/logwrapper(138): executing /system/bin/tc failed: No such file or directory
04-03 09:53:58.576: ERROR/logwrapper(142): executing /system/bin/tc failed: No such file or directory
04-03 09:53:58.695: ERROR/logwrapper(143): executing /system/bin/tc failed: No such file or directory
04-03 09:54:20.005: ERROR/HierarchicalStateMachine(59): TetherMaster - unhandledMessage: msg.what=3
04-03 09:54:51.657: ERROR/AndroidRuntime(283): FATAL EXCEPTION: main
04-03 09:54:51.657: ERROR/AndroidRuntime(283): java.lang.RuntimeException: Unable to start activity ComponentInfo{cs1410.assignment08/cs1410.assignment08.Planets}: android.view.InflateException: Binary XML file line #12: Error inflating class android.widget.Button
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.os.Looper.loop(Looper.java:123)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at java.lang.reflect.Method.invokeNative(Native Method)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at java.lang.reflect.Method.invoke(Method.java:521)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at dalvik.system.NativeStart.main(Native Method)
04-03 09:54:51.657: ERROR/AndroidRuntime(283): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.widget.Button
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.app.Activity.setContentView(Activity.java:1647)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at cs1410.assignment08.Planets.onCreate(Planets.java:20)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     ... 11 more
04-03 09:54:51.657: ERROR/AndroidRuntime(283): Caused by: java.lang.reflect.InvocationTargetException
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.widget.Button.<init>(Button.java:65)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at java.lang.reflect.Constructor.constructNative(Native Method)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     ... 23 more
04-03 09:54:51.657: ERROR/AndroidRuntime(283): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/btn_default.xml from color state list resource ID #0x7f050004
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.content.res.Resources.loadColorStateList(Resources.java:1817)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.widget.TextView.<init>(TextView.java:628)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.widget.Button.<init>(Button.java:69)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     ... 27 more
04-03 09:54:51.657: ERROR/AndroidRuntime(283): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/btn_default.xml from xml type colorstatelist resource ID #0x7f050004
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:1916)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.content.res.Resources.loadColorStateList(Resources.java:1812)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     ... 30 more
04-03 09:54:51.657: ERROR/AndroidRuntime(283): Caused by: java.io.FileNotFoundException: res/drawable/btn_default.xml
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.content.res.AssetManager.openXmlAssetNative(Native Method)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:485)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:1898)
04-03 09:54:51.657: ERROR/AndroidRuntime(283):     ... 31 more

so.. thats what log cat has to say.

I'll post my code just cuz. It worked fine at first, then I added a bunch more code that should not have broken anything..
Code:
package cs1410.assignment08;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Planets extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
   
    private EditText display;
    private TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ((Button) findViewById(R.id.button1)).setOnClickListener(this);
        ((Button) findViewById(R.id.button2)).setOnClickListener(this);
        ((Button) findViewById(R.id.button3)).setOnClickListener(this);
        ((Button) findViewById(R.id.button4)).setOnClickListener(this);
        ((Button) findViewById(R.id.button5)).setOnClickListener(this);
        ((Button) findViewById(R.id.button6)).setOnClickListener(this);
        ((Button) findViewById(R.id.button7)).setOnClickListener(this);
        ((Button) findViewById(R.id.button8)).setOnClickListener(this);
        
        display = (EditText) findViewById(R.id.editText1);
        tv = (TextView) findViewById(R.id.textView1);
    }

    public void onClick(View v) {
        Button b = (Button) v;
        String buttonLabel = b.getText().toString();
        //tv.setText("...");
        
        if(buttonLabel.equals("Mercury"))
        {
            display.setText ("Mercury is about .387 AU from Sun");
            tv.setText("Mercury was named after the god Hermes, the messenger of the gods in Roman mythology.");
        }
        if(buttonLabel.equals("Venus"))
        {
            display.setText ("Venus is about .722 AU from Sun");
            tv.setText("Venus is named after the Roman goddess of love and beauty.");
        }
        else if(buttonLabel.equals("Earth"))
        {
            display.setText ("Earth is 1 AU from the Sun");
            tv.setText("Everything you've ever known, everyone you've ever loved, every king, queen, every war and disease...");
        }
        if(buttonLabel.equals("Mars"))
        {
            display.setText ("Mars is about 1.52 AU from Sun");
            tv.setText("Mars was named after Areas, the Roman god of War.");
        }
        if(buttonLabel.equals("Jupiter"))
        {
            display.setText ("Jupiter is about 5.20 AU from Sun");
            tv.setText("Jupiter, the largest planet in the Solar System, was appropriately named for the Roman King of Gods.");
        }
        if(buttonLabel.equals("Saturn"))
        {
            display.setText ("Saturn is about 9.58 AU from Sun");
            tv.setText("Saturn is named after Cronus, the god of Architecture.");
        }
        if(buttonLabel.equals("Uranus"))
        {
            display.setText ("Uranus is about 19.20 AU from Sun");
            tv.setText("Uranus was the Roman god of the Heavens.");
        }
        if(buttonLabel.equals("Neptune"))
        {
            display.setText ("Neptune is about 30.10 AU from Sun");
            tv.setText("Neptune was named after Poseidon, the god of the Seas, and with the blue color of its atmosphere, this is fitting.");
        }
        
    }
}

R file
Code:
/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package cs1410.assignment08;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class id {
        public static final int button1=0x7f050004;
        public static final int button2=0x7f050005;
        public static final int button3=0x7f050006;
        public static final int button4=0x7f050008;
        public static final int button5=0x7f050009;
        public static final int button6=0x7f05000a;
        public static final int button7=0x7f05000c;
        public static final int button8=0x7f05000d;
        public static final int editText1=0x7f050001;
        public static final int linearLayout1=0x7f050007;
        public static final int linearLayout2=0x7f05000b;
        public static final int tableLayout1=0x7f050000;
        public static final int tableRow1=0x7f050003;
        public static final int textView1=0x7f050002;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
        public static final int mercury=0x7f040002;
    }
}

XML
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TableLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/tableLayout1">
        <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Planetary info!"></EditText>
        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView1" android:text="..."></TextView>
    </TableLayout>
    <TableRow android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/tableRow1">
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:text="Mercury" android:layout_weight="1" android:textColor="@+id/button1"></Button>
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button2" android:text="Venus" android:layout_weight="1"></Button>
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button3" android:text="Earth" android:layout_weight="1"></Button>
    </TableRow>
    <LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="match_parent">
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button4" android:text="Mars" android:layout_weight="1"></Button>
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button5" android:text="Jupiter" android:layout_weight="1"></Button>
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button6" android:text="Saturn" android:layout_weight="1"></Button>
    </LinearLayout>
    <LinearLayout android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:layout_width="match_parent">
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button7" android:text="Uranus" android:layout_weight="1"></Button>
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button8" android:text="Neptune" android:layout_weight="1"></Button>
    </LinearLayout>
</LinearLayout>

I hope we can get this figured out!!!
 
In the exception it says:
Code:
Unable to start activity ComponentInfo{cs1410.assignment08/cs1410.assignment08.Planets}: android.view.InflateException: Binary XML file line #12: Error inflating class android.widget.Button
And this is because you have tried to set an id as the textcolor of the button.
Code:
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:text="Mercury" android:layout_weight="1" android:textColor="@+id/button1"></Button>
So just remove the android:textColor bit or set a color.
 
In the exception it says:
Code:
Unable to start activity ComponentInfo{cs1410.assignment08/cs1410.assignment08.Planets}: android.view.InflateException: Binary XML file line #12: Error inflating class android.widget.Button
And this is because you have tried to set an id as the textcolor of the button.
Code:
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:text="Mercury" android:layout_weight="1" android:textColor="@+id/button1"></Button>
So just remove the android:textColor bit or set a color.

I just went and tested the code then figured this out , came here to feel awesome and you stole it :P

anyway , if you used this xml it should work fine [and I think it looks better like this]

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TableLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/tableLayout1">
        <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Planetary info!"></EditText>
        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView1" android:text="..."></TextView>
    
    <TableRow android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/tableRow1">
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:text="Mercury" android:layout_weight="1" ></Button>
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button2" android:text="Venus" android:layout_weight="1"></Button>
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button3" android:text="Earth" android:layout_weight="1"></Button>
    </TableRow>
    <TableRow android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="match_parent">
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button4" android:text="Mars" android:layout_weight="1"></Button>
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button5" android:text="Jupiter" android:layout_weight="1"></Button>
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button6" android:text="Saturn" android:layout_weight="1"></Button>
    </TableRow>
    <TableRow android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:layout_width="match_parent">
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button7" android:text="Uranus" android:layout_weight="1"></Button>
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button8" android:text="Neptune" android:layout_weight="1"></Button>
    </TableRow>
    </TableLayout>
</LinearLayout>
 
Back
Top Bottom