在Android Studio

时间:2015-06-28 06:49:41

标签: android

我是Android开发应用的新手。我正在关注官方网站上提供的教程。到目前为止一切都很好但是当我开始创建和修改操作栏时,这个错误开始出现:

Error:Execution failed for task ':app:processDebugManifest'.
  

清单合并失败:AndroidManifest.xml上的主AndroidManifest.xml清单:未声明package属性

我的清单文件是这个

     <?xml version="1.0" encoding="utf-8"?>
       <manifest xmlns:android="http://schemas.android.com/apk/res/android">
       <uses-sdk android:minSdkVersion="14"/>
      package="com.mycompany.myfirstapp" >

      <application>
    <!-- The/main activity (it has no parent activity) -->
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Holo" >

    <activity
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.myfirstapp.DisplayMessageActivity"
        android:label="@string/title_activity_display_message"
                          android:parentActivityName="com.example.hpcore.myfirstapp.MyActivity" >
         <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.hpcore.myfirstapp.MyActivity" />
    </activity>
   </application>

     </manifest>

我的主要活动Java代码是:

         package com.example.hpcore.myfirstapp;

        import android.support.v7.app.ActionBarActivity;
          import android.os.Bundle;
           import android.view.Menu;
           import android.view.MenuInflater;
          import android.view.MenuItem;
          import android.content.Intent;
          import android.view.View;
          import android.widget.EditText;

          import com.mycompany.myfirstapp.DisplayMessageActivity;


      public class MyActivity extends ActionBarActivity {
     public final static String EXTRA_MESSAGE= "com.hp core.myfirstapp.MESSAGE";
      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);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_displaymessage);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_Activity_actions,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @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.
        switch (item.getItemId())
        {
            case R.id.action_search:
                openSearch();
                return true;
            case R.id.action_settings:
                openSettings();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }

    }
}

我猜其中一个文件存在问题。

1 个答案:

答案 0 :(得分:0)

package属性应该是Manifest标记 -

的一部分

更改清单标记,如下所示 -

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mycompany.myfirstapp" >
       <uses-sdk android:minSdkVersion="14"/>