(未解决)Android FragmentActivity 错误
(Unsolvd) Android FragmentActivity error
早上好,
在 Eclipse 中设置 Android 依赖项时,我 运行 遇到了很多问题。
自从修复了原始错误(依赖项)后,我现在遇到了一些新的错误,这些错误似乎由于之前的 XML 和 targetSDK 错误而没有发生,但还有其他原因。
我想创建一个简单的应用程序,但是它需要我使用 google 地图 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 之后,依赖性错误就消失了,但是上面的错误已经出现了。
我试图删除该项目,然后重新添加它。还尝试重新安装这些工具,以防这些工具对我造成干扰。
我不太确定你们还需要什么代码等来帮助我,所以如果您需要更多代码片段,请继续告诉我。
非常感谢有关此问题的任何帮助。
此致,
乔金
编辑(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
}
}
编辑:仍然需要帮助。
添加最新的支持和设计依赖并重建您的项目
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
是因为你的compiledSdkVersion
。您应该将其设置为 21 或更高,因为 @android:style/Theme.Material.Light.DialogWhenLarge.NoActionBar
是在 API 级别 21 中引入的。参见 here。
早上好,
在 Eclipse 中设置 Android 依赖项时,我 运行 遇到了很多问题。
自从修复了原始错误(依赖项)后,我现在遇到了一些新的错误,这些错误似乎由于之前的 XML 和 targetSDK 错误而没有发生,但还有其他原因。
我想创建一个简单的应用程序,但是它需要我使用 google 地图 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 之后,依赖性错误就消失了,但是上面的错误已经出现了。
我试图删除该项目,然后重新添加它。还尝试重新安装这些工具,以防这些工具对我造成干扰。
我不太确定你们还需要什么代码等来帮助我,所以如果您需要更多代码片段,请继续告诉我。
非常感谢有关此问题的任何帮助。
此致, 乔金
编辑(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
}
}
编辑:仍然需要帮助。
添加最新的支持和设计依赖并重建您的项目
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
是因为你的compiledSdkVersion
。您应该将其设置为 21 或更高,因为 @android:style/Theme.Material.Light.DialogWhenLarge.NoActionBar
是在 API 级别 21 中引入的。参见 here。