Ant似乎没有找到包:android.support.v4.app.NavUtils
这是编译器错误:
C:\Android\MyFirstApp\src\com\example\myfirstapp\DisplayMessageActivity.java:7: error: package android.support.v4.app does not exist
C:\Android\MyFirstApp\src\com\example\myfirstapp\DisplayMessageActivity.java:22: error: cannot find symbol: NavUtils.navigateUpFromSameTask(this);
我在 sdk 中有 android 目录和类文件。
MainActivity.java
package com.example.myfirstapp; import android.app.Activity; import android.os.Bundle; import android.content.Intent; import android.view.View; import android.content.Intent; import android.widget.TextView; import android.widget.EditText; import android.view.MenuItem; public class MainActivity extends Activity { public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); TextView textView = new TextView(this); textView.setTextSize(40); textView.setText(message); setContentView(textView); getActionBar().setDisplayHomeAsUpEnabled(true); } public void sendMessage(View view){ Intent intent = new Intent(this, DisplayMessageActivity.class); EditText editText = (EditText) findViewById(R.id.edit_message); String message = editText.getText().toString(); intent.putExtra(EXTRA_MESSAGE, message); startActivity(intent); } }
DisplayMessageActivity.java
package com.example.myfirstapp; import android.app.Activity; import android.os.Bundle; import android.view.MenuItem; import android.view.View; import android.support.v4.app.NavUtils; public class DisplayMessageActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); getActionBar().setDisplayHomeAsUpEnabled(true); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } }