AndroidManifest.xml

时间:2018-04-28 01:54:54

标签: java android-manifest

我不断得到这个构建错误'class'或'interface'。我在SO上找到的所有东西都说我的Java类缺失(或者有一个额外的)“}”我在我的AndroidManifest.xml中遇到了所有Java活动的错误。这是Java代码:

public class MainActivity extends AppCompatActivity {

    protected static final String TAG = "com.example.grey";
    EditText SendValue;
    Button SendEditTextValue;
    Intent intent;

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);

        Log.d(TAG, "onCreate started from Main Activity");

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater mMenuInflater = getMenuInflater();
        mMenuInflater.inflate(R.menu.my_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == R.id.action_setting){
            Toast.makeText(MainActivity.this,
                    "Settings Clicked",
                    Toast.LENGTH_SHORT).show();
        }
        if(item.getItemId() == R.id.about_us){
            Intent intent = new Intent(this, AboutActivity.class);
            startActivity(intent);
        }
        return super.onOptionsItemSelected(item);
    }


    public void sendButton(View view){
        SendEditTextValue = (Button) findViewById(R.id.button1);
        SendValue = (EditText) findViewById(R.id.editText1);
        SendEditTextValue.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                intent = new Intent(getApplicationContext(), TextBoxMsgSend.class);
                intent.putExtra("EdiTtEXTvALUE", SendValue.getText().toString());
                startActivity(intent);

            }
        });
    }

    public void movieButton(View view){
        Intent intent = new Intent(this, ShowMovies.class);
        startActivity(intent);
    }

    public void button7(View view){
        CharSequence text = "Two";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(this, text, duration);
        toast.show();
    }

    public void button8(View view){
        CharSequence text = "Three";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(this, text, duration);
        toast.show();
    }

    public void button9(View view){
        CharSequence text = "Four";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(this, text, duration);
        toast.show();
    }



    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart started from Main Activity");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG, "onPause started from Main Activity");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG, "onStop started from Main Activity");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy started from Main Activity");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d(TAG, "onRestart started from Main Activity");
    }

}

这是AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.grey">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">

        <!-- The main/home activity (it has no parent activity) -->

        <activity android:name="MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- A child of the main activity -->
        <activity
            android:name=".TextBoxMsgSend"
            android:parentActivityName=".MainActivity" />
        <activity
            android:name=".ShowMovies"
            android:parentActivityName=".MainActivity" />
        <activity
            android:name=".RecyclerAdapter"
            android:parentActivityName=".MainActivity" />
        <activity
            android:name=".MovieDetails"
            android:parentActivityName=".ShowMovies" />


        <activity
            android:name=".AboutActivity"
            android:parentActivityName=".MainActivity">


            <!-- Parent activity meta-data to support 4.0 and lower -->
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.grey.MainActivity" />

        </activity>
    </application>

</manifest>

我一直遇到构建错误,无法执行任何提交。前几天工作正常,所以我不确定是什么改变了。如果需要,我可以发布我的其他活动。

public class MovieDetails extends AppCompatActivity{
    private static final String TAG = "MovieDetailsActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_movie_details);
        Log.d(TAG, "Started program.");

        getGalleryIntent();
    }

    private void getGalleryIntent(){
        if(getIntent().hasExtra("image_url") && getIntent().hasExtra("image_name")){
            Log.d(TAG,"Found intents.");
            String imageURL = getIntent().getStringExtra("image_url");
            String imageName = getIntent().getStringExtra("image_name");
            String imageYear = getIntent().getStringExtra("image_year");
            String imageDirector = getIntent().getStringExtra("image_director");
            String imageDescription = getIntent().getStringExtra("image_description");
            setImage(imageURL, imageName, imageYear, imageDirector, imageDescription);
        }
    }

    private void setImage(String imageURL, String imageName, String imageYear, String imageDirector, String imageDescription){
        TextView name = findViewById(R.id.title);
        name.setText(imageName);

        TextView year = findViewById(R.id.year);
        year.setText(imageYear);

        TextView director = findViewById(R.id.director);
        director.setText(imageDirector);

        TextView description = findViewById(R.id.description);
        description.setText(imageDescription);

        ImageView image = findViewById(R.id.image);
        Glide.with(this).asBitmap().load(imageURL).into(image);
    }
}

1 个答案:

答案 0 :(得分:0)

在MainActivity之前尝试一段时间,在清单中声明它。