簡體   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