Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,739,536 Members 53,052 Now Online
XDA Developers Android and Mobile Development Forum

Need help identifying error.(Its my first app)

Tip us?
 
Koopla
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 1
Join Date: Jun 2014
Default Need help identifying error.(Its my first app)

Hi, I am very new to developing apps and I am following the tutorial from Google's Android Training and I am currently at the "Starting your second Activity" stage. The purpose of the tutorial is to create a second activity so that the "Send" button will display the message that I have written.

There are 2 errors here:
Code:
Select Code
Unknown member 'action_settings' of 'com.mycompany.myapp.R.id'
Unknown member 'fragment_display_message of 'com.mycompany.myapp.R.id'
and this is the code where the error occurs at DisplayMessageActivity java class:
Code:
Select Code
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import com.mycompany.myapp.*;

public class DisplayMessageActivity extends Activity
{@Override
    protected 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);
    }

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

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() { }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
								 Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_display_message,
											 container, false);
			return rootView;
        }
    }
}


I can't seem to fix this error. I have been trying to find the solution but to no avail.
I don't kow if it help you guys but here's the R.java:

Code:
Select 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 com.mycompany.myapp;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int edit_message=0x7f050000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int action_settings=0x7f040003;
        public static final int app_name=0x7f040000;
        public static final int button_send=0x7f040002;
        public static final int edit_message=0x7f040001;
        public static final int title_activity_display_message=0x7f040005;
        public static final int title_activity_main=0x7f040004;
    }
}
Here's the R java:
Code:
Select 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 com.mycompany.myapp;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int edit_message=0x7f050000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int action_settings=0x7f040003;
        public static final int app_name=0x7f040000;
        public static final int button_send=0x7f040002;
        public static final int edit_message=0x7f040001;
        public static final int title_activity_display_message=0x7f040005;
        public static final int title_activity_main=0x7f040004;
    }
}
Here's the strings xml:
Code:
Select Code
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">My App</string>
    <string name="edit_message">Enter a message</string>
    <string name="button_send">Send</string>
    <string name="action_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
	<string name="title_activity_display_message">My Message</string>
</resources>
Here's the Mainactivity java
Code:
Select Code
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import com.mycompany.myapp.*;


public class MainActivity extends Activity
{
    public final static String EXTRA_MESSAGE = "com.example.myapp.MESSAGE";
    @Override
    public void onCreate(Bundle savedInstanceState)
	{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);}
	public void sendMessage(View view) {
		Intent intent = new Intent(this, DisplayMessageActivity.class);
	    EditText editText = (EditText) findViewById(R.id.edit_message);
		String message = editText.getText().toString();
		intent.putExtra(EXTRA_MESSAGE, message);
		startActivity(intent);
		}
    
}
 
gh0stslayer
Old
#2  
gh0stslayer's Avatar
Senior Member
Thanks Meter 133
Posts: 193
Join Date: Nov 2010
Location: Bangalore
Quote:
Originally Posted by Koopla View Post
Hi, I am very new to developing apps and I am following the tutorial from Google's Android Training and I am currently at the "Starting your second Activity" stage. The purpose of the tutorial is to create a second activity so that the "Send" button will display the message that I have written.

There are 2 errors here:
Code:
Select Code
Unknown member 'action_settings' of 'com.mycompany.myapp.R.id'
Unknown member 'fragment_display_message of 'com.mycompany.myapp.R.id'
and this is the code where the error occurs at DisplayMessageActivity java class:
Code:
Select Code
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import com.mycompany.myapp.*;

public class DisplayMessageActivity extends Activity
{@Override
    protected 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);
    }

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

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() { }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
								 Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_display_message,
											 container, false);
			return rootView;
        }
    }
}


I can't seem to fix this error. I have been trying to find the solution but to no avail.
I don't kow if it help you guys but here's the R.java:

Code:
Select 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 com.mycompany.myapp;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int edit_message=0x7f050000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int action_settings=0x7f040003;
        public static final int app_name=0x7f040000;
        public static final int button_send=0x7f040002;
        public static final int edit_message=0x7f040001;
        public static final int title_activity_display_message=0x7f040005;
        public static final int title_activity_main=0x7f040004;
    }
}
Here's the R java:
Code:
Select 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 com.mycompany.myapp;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int edit_message=0x7f050000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int action_settings=0x7f040003;
        public static final int app_name=0x7f040000;
        public static final int button_send=0x7f040002;
        public static final int edit_message=0x7f040001;
        public static final int title_activity_display_message=0x7f040005;
        public static final int title_activity_main=0x7f040004;
    }
}
Here's the strings xml:
Code:
Select Code
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">My App</string>
    <string name="edit_message">Enter a message</string>
    <string name="button_send">Send</string>
    <string name="action_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
	<string name="title_activity_display_message">My Message</string>
</resources>
Here's the Mainactivity java
Code:
Select Code
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import com.mycompany.myapp.*;


public class MainActivity extends Activity
{
    public final static String EXTRA_MESSAGE = "com.example.myapp.MESSAGE";
    @Override
    public void onCreate(Bundle savedInstanceState)
	{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);}
	public void sendMessage(View view) {
		Intent intent = new Intent(this, DisplayMessageActivity.class);
	    EditText editText = (EditText) findViewById(R.id.edit_message);
		String message = editText.getText().toString();
		intent.putExtra(EXTRA_MESSAGE, message);
		startActivity(intent);
		}
    
}
You haven't created a layout for your second activity .

Create an xml layout file, called fragment_display_message, with at least a textview so that it can display your message, and add at least a textview to display the message


as far as action_settings string is concerned, it seems to be a problem with menu.xml file

if you don't wanna get into that, just delete these lines
PHP Code:
if (id == R.id.action_settings) {
            return 
true;
        } 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes