繁体   English   中英

(Unsolvd)Android FragmentActivity错误

[英](Unsolvd) Android FragmentActivity error

早上好,

在Eclipse中设置Android依赖项时,我遇到了很多问题。

自从修复了原始错误(相关性)以来,我现在碰到了一些新错误,由于先前的XML和targetSDK错误,这似乎没有发生,但还有其他原因。

我想创建一个简单的应用程序,但是它需要我使用google maps api,自从本周开始以来,我一直在努力正确地设置依赖项。

我已经完成了从重新安装ADT,SDK,其他功能等等的所有工作-但无济于事。 我已经按照google的关于Android环境的开发指南进行了学习。

当前错误:

  Description   Resource    Path    Location    Type
FragmentActivity cannot be resolved to a type   Startup.java    /birdview/src/com/example/birdview  line 14 Java Problem
FragmentActivity cannot be resolved to a type   Startup.java    /birdview/src/com/example/birdview  line 19 Java Problem
FragmentActivity cannot be resolved to a type   Startup.java    /birdview/src/com/example/birdview  line 42 Java Problem
The method getFragmentManager() is undefined for the type Startup   Startup.java    /birdview/src/com/example/birdview  line 22 Java Problem
The method getMenuInflater() is undefined for the type Startup  Startup.java    /birdview/src/com/example/birdview  line 29 Java Problem
The method onCreate(Bundle) of type Startup must override or implement a supertype method   Startup.java    /birdview/src/com/example/birdview  line 18 Java Problem
The method onCreateOptionsMenu(Menu) of type Startup must override or implement a supertype method  Startup.java    /birdview/src/com/example/birdview  line 27 Java Problem
The method onOptionsItemSelected(MenuItem) of type Startup must override or implement a supertype method    Startup.java    /birdview/src/com/example/birdview  line 34 Java Problem
The method setContentView(int) is undefined for the type Startup    Startup.java    /birdview/src/com/example/birdview  line 20 Java Problem
Unable to resolve target 'android-19' until the SDK is loaded.  hello       Unknown Android Target Problem
Unable to resolve target 'android-21' until the SDK is loaded.  birdview        Unknown Android Target Problem
Unable to resolve target 'android-21' until the SDK is loaded.  google-play-services_lib        Unknown Android Target Problem

由于更改了targetSDK,相关性错误现在已消失,但是上述错误已取代了它。

我试图删除该项目,然后重新添加它。 还尝试重新安装工具,以防这些工具弄乱了我。

我不确定是否需要其他代码来帮助我,所以请继续告诉我是否需要更多片段。

关于此问题的任何帮助将不胜感激。

最好的问候,Joakim

编辑(成绩文件):

    apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':google-play-services_lib')
}

android {
    compileSdkVersion 21
    buildToolsVersion "23.0.2"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

编辑:

    package com.example.birdview;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;

import android.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;

public class Startup extends FragmentActivity 
implements OnMapReadyCallback {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_startup);
        if (savedInstanceState == null) {
            getFragmentManager().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.startup, 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_startup, container, false);
            return rootView;
        }
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        // TODO Auto-generated method stub

    }
}

编辑:仍然需要帮助。

添加最新的支持和设计依赖性并重建您的项目

compile 'com.android.support:design:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'

这是因为您compiledSdkVersion 您应该将其设置为21或更高,因为API级别21中引入了@android:style/Theme.Material.Light.DialogWhenLarge.NoActionBar 。请参见此处

暂无
暂无

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

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