NickyMilton
NickyMilton

Reputation: 70

UPDATED: Android: java.lang.RuntimeException: Unable to start activity ComponentInfo

UPDATE** so i did pretty much everything that was said below and still got this error(see new logcat file). Its different though so i dont know how to fix it.** Ok so im a beginner so i really dont know whats going on. When i try to run this app in the emulator all it is "unfortunately this app has stopped." Ive search all the question similar to this but haven't been able to find an answer. btw this isnt a finished app or really even started, but i want to get it to run before i continue. Heres the log cat file thing.

    error opening trace file: No such file or directory (2)
08-19 06:09:04.579: D/AndroidRuntime(1006): Shutting down VM
08-19 06:09:04.599: W/dalvikvm(1006): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
 FATAL EXCEPTION: main
 android.content.res.Resources$NotFoundException: Resource ID #0x7f080001 type #0x12 is not valid
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2103)
    at android.content.res.Resources.getLayout(Resources.java:852)
    at android.view.MenuInflater.inflate(MenuInflater.java:107)
    at com.nickymilton.testbasebal3.MainActivity.onCreateOptionsMenu(MainActivity.java:22)
    at android.app.Activity.onCreatePanelMenu(Activity.java:2476)
    at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
    at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
    at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:2913)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

Now heres the activty_main.xml

    <?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="50dp"
        android:orientation="vertical" >

         <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="30dp"
            android:text="@string/EnterHome"
            android:textColor="@color/White" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="30dp"
            android:ems="10" 
            android:hint="@string/home_team"
            android:layout_below="@id/textView1"
            android:shadowColor="@color/ICSBlue" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/editText1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="30dp"
            android:text="@string/EnterAway"
            android:textColor="@color/White" />


        <EditText
            android:id="@+id/editText2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/textView2"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="30dp"
            android:ems="10"
            android:hint="@string/away_team"
            android:shadowColor="@color/ICSBlue" />

        <Button
            android:id="@+id/button3"
            android:layout_width="115dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/editText2"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="40dp"
            android:text="@string/Enter" />

        <Button
            android:id="@+id/button2"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/button3"
            android:layout_centerHorizontal="true"
  android:layout_marginTop="40dp"
                android:text="@string/Skip" />

    </RelativeLayout>

Now the activity_display_message.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".DisplayMessageActivity" />

</RelativeLayout>

Then here the mainActivity.java file

package com.nickymilton.testbasebal3;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

    public final static String EXTRA_MESSAGE = "com.nickymilton.Testbasebal3.MESSAGE";

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public void sendMessage(View view) {
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        EditText editText = (EditText) findViewById(R.id.editText1);
        String message = editText.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }
}

then the second activity DisplayMessageActivity.java

package com.nickymilton.testbasebal3;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.support.v4.app.NavUtils;

public class DisplayMessageActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Get the message from the intent
        Intent intent = getIntent();
        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

        // Create the text view
        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(message);

        // Set the text view as the activity layout
        setContentView(textView);
    }

    }

And finally the mainfest file

  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nickymilton.testbasebal3"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".DisplayMessageActivity"
            android:label="@string/title_activity_display_message" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.nickymilton.testbasebal3.MainActivity" />
        </activity>
    </application>

</manifest>

So there it is. Someone please help thanks!

Upvotes: 3

Views: 9931

Answers (3)

Emile
Emile

Reputation: 11721

I've noticed one thing, you've not declared the 'id' values correctly in some of your xml.

android:id="@id/button3"

should be

android:id="@+id/button3"

And like wise for your other id declarations.

You'll notice that in your stack trace it gives you the line number in your xml for the location of the error.

java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.nickymilton.testbasebal3/com.nickymilton.testbasebal3.MainActivity}:
android.view.InflateException: Binary XML file line #54: Error inflating class <unknown>

This might be something else. But essentially you have badly formed xml.

Error Two

You need to look through the stack trace backwards to find the source of your error, you will then most likely find the solution yourself.

 android.content.res.Resources$NotFoundException: Resource ID #0x7f080001 type #0x12 is not valid
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2103)
    at android.content.res.Resources.getLayout(Resources.java:852)
    at android.view.MenuInflater.inflate(MenuInflater.java:107)
    at com.nickymilton.testbasebal3.MainActivity.onCreateOptionsMenu(MainActivity.java:22)
    at android.app.Activity.onCreatePanelMenu(Activity.java:2476)

From the top down you'll get to the line MainActivity.oncreateOptionsMenu() Above that you'll see that its trying to inflate (your options menu xml), i.e. loadXmlResourceParser()

It doesn't go as far as giving you an xml line number but it does tell you you have an issue with an Resource id not being valid.

You'll need to post your options xml in your question if you want an answer. But i would see if you can work it out your self first. Try commenting out elements and putting them back in to see whats broken. I say this because theres only so much one Stack overflow question should answer.

Upvotes: 2

user
user

Reputation: 87064

In the declaration for one of your TextViews you have :

android:textSize="@string/TextSizefifteen"

textSize should be a number or a dimension like:

android:textSize="@dimen/TextSizefifteen"

See what you have at TextSizefifteen and how you declared it(see http://developer.android.com/guide/topics/resources/more-resources.html#Dimension).

For example:

<dimen name="TextSizefifteen">25dp</dimen>

Upvotes: 1

Alexander Lucas
Alexander Lucas

Reputation: 22371

There are issues with your XML - you can tell from the line:

Binary XML file line #54: Error inflating class <unknown>

One thing I spotted is that when you declare an android:id attribute, it needs to have a + in it, like this:

android:id="@+id/location"

This is because you're creating an id, not just referring to a pre-existing one defined elsewhere (like you might be with a string, e.g "@string/hello" might be in the values folder).

Upvotes: 4

Related Questions