我有一个问题不知道如何询问。所以请给我指导,因为我是开发 android 应用程序的初学者(这是迄今为止最复杂、繁琐和令人困惑的事情!)。
我创建了一个新的“Hello World”项目,必须进行一些其他设置(或其他任何操作,不确定我做了什么),然后使用枚举器“运行”我的第一个 Android 应用程序。模拟器启动,应用程序“Hello World”立即停止并显示以下消息:
The application HelloWorld (process ...) has stopped unexpectedly. Please try again.
在我的 eclipse 窗口中,我看到以下三个警告,但我不确定它是否与上面的实际问题有关:
Could not locate '/home/alexander/opt/src/android-sdk-linux/extras/android/support/v7/appcompat/bin/android-support-v7-appcompat.jar'. This will not be added to the package.
The type ActionBarActivity is deprecated MainActivity.java /HelloWorld/src/com/example/helloworld line 3 Java Problem
The type ActionBarActivity is deprecated MainActivity.java /HelloWorld/src/com/example/helloworld line 10 Java Problem
这是 MainActivity.java 的内容:
package com.example.helloworld;
import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
@SuppressLint("NewApi") public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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);
}
}
我该如何解决这个问题?我怎么才能开始弄清楚哪里出了问题?有没有其他方法可以更简单地创建 android 应用程序?或者它必须非常复杂、繁琐和令人困惑......?
最佳答案
您的 SDK 版本似乎不正确。所以它无法加载 ActionBarActivity
。
此外,ActionBarActivity
已被删除,因此您可能希望使用 AppCompatActivity
。
引用:https://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html
我还建议切换到 Android Studio,因为它更易于管理 SDK。
关于java - 如何修复 android-eclipse HelloWorld 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33259450/