【问题标题】:(Unsolvd) Android FragmentActivity error(未解决)Android FragmentActivity 错误
【发布时间】:2016-05-22 03:59:09
【问题描述】:

早上好,

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

自从修复了原始错误(依赖项)后,我现在遇到了一些新错误,这些错误似乎由于之前的 XML 和 targetSDK 错误而没有发生,但还有其他问题。

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

我已经完成了所有工作,包括重新安装 ADT、SDK、附加功能等等 - 但无济于事。我已经按照 google's dev 上关于 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 后,依赖错误现已消失,但上述错误已取而代之。

我已尝试删除该项目,然后重新添加它。还尝试重新安装这些工具,以防它们惹恼我。

我不确定你们还需要什么代码等来帮助我,所以请继续告诉我是否需要更多 sn-ps。

我们将不胜感激有关此问题的任何帮助。

最好的问候, 乔金

编辑(Gradle 文件):

    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

    }
}

编辑:仍然需要帮助。

【问题讨论】:

  • 发布你的 gradle 文件
  • 查看编辑。谢谢!

标签: java android eclipse google-maps dependencies


【解决方案1】:

因为你的compiledSdkVersion。您应该将其设置为 21 或更高,因为在 API 级别 21 中引入了@android:style/Theme.Material.Light.DialogWhenLarge.NoActionBar。请参阅here

【讨论】:

  • 这确实解决了依赖问题。但是现在我面临各种其他错误,例如:“FragmentActivity 无法解析为类型”。有关更多信息,请参阅我对 Startup(仅限活动)的编辑。
  • 你可能想看看这个SO-164886
【解决方案2】:

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

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

【讨论】:

  • 尝试将它添加到依赖项{}中并重建项目,(清理..,构建)但它没有做任何事情......
  • 有什么线索吗?
猜你喜欢
  • 2019-01-24
  • 2017-08-08
  • 2011-07-24
  • 1970-01-01
  • 2020-11-13
  • 1970-01-01
  • 2010-10-27
  • 1970-01-01
相关资源
最近更新 更多