简体   繁体   English

Android应用程序项目日食无法正常工作

[英]Android Application project eclipse not working

I started the course from coursera and simply created my firsy Android application using the sdk on eclipse but it gave a large amount of errors in the MainActivity.java file as well as in the other layout files. 我从Coursera开始课程,只是在eclipse上使用sdk创建了我的firsy Android应用程序,但是它在MainActivity.java文件以及其他布局文件中产生了大量错误。

Main error it gave was The import android.support.v7.app cannot be resolved 它给出的主要错误是无法解析导入android.support.v7.app

After wards I guess all errors are there because of this main error. 在病房之后,我猜所有的错误都会因为这个主要错误而存在。 On mmethod OnCreate I got this error The method onCreate(Bundle) of type MainActivity must override or implement a supertype method 在方法OnCreate我遇到此错误MainActivity类型的方法onCreate(Bundle)必须重写或实现一个超类型方法

No idea of Android so I hope someone can help me out here. 不了解Android因此希望有人可以在这里为我提供帮助。

package com.example.helloandroid;

import android.support.v7.app.ActionBarActivity;//Here I got the error
import android.support.v7.app.ActionBar;//Here as well
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

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

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@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_main, container,
                false);
        return rootView;
    }
}

}

You need to add the support package v7 to your set up. 您需要将支持包v7添加到您的设置中。

Check this official tutorial: https://developer.android.com/tools/support-library/setup.html 查看此官方教程: https : //developer.android.com/tools/support-library/setup.html

尝试从sdk \\ extras \\ android \\ support \\ v7导入android.support.v7.app到您的工作区中,然后将此库附加到您的项目中,如果不解决所有错误,则随后将其注释:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM