Ant doesn't seem to find package: android.support.v4.app.NavUtils
Here's the compiler errors:
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);
I have the android directory in sdk with the class files.
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); } }
Coolcfan is (almost) correct. android.support.v4.NavUtils is not included by default.
Anyway, you need to add the library into the build path. It's located in:
android-sdk\extras\android\support\v4\android-support-v4.jar
Once you've done that, it should all work fine.
Note: also make sure that you've defined the parent class in your Manifest using meta-data tags like so:
<activity
android:name=".ChildActivity"
android:label="@string/childActivity_title" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ParentActivity" >
</meta-data>
</activity>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With