我正在开发一个android应用程序(用于jellybean),它有9个与意图相关的活动。当我点击顶部的栏时应用程序崩溃(这应该是我以前的活动)。我不确定该栏的名称是什么,但它显示了当前活动的名称。当我点击硬件“后退”按钮时它不会崩溃,但当我点击该栏时它会显示“应用程序已停止”。我正在添加模拟器的屏幕截图,以显示我正在谈论的栏:
这是我的主要活动代码和个人资料活动代码:
主要活动:
package com.ecotravel.eco_travel;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.content.Intent;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText usernamefield= (EditText) findViewById(R.id.usernamefield);
EditText passwordfield = (EditText) findViewById(R.id.passwordfield);
}
@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;
}
/** Called when the user clicks the Log In button */
public void loginFunc(View view) {
Intent intent = new Intent(this, ProfileActivity.class);
startActivity(intent);
EditText usernamefield= (EditText) findViewById(R.id.usernamefield);
EditText passwordfield = (EditText) findViewById(R.id.passwordfield);
}
/** Called when the user clicks the Register button */
public void registerFunc(View view) {
Intent intent = new Intent(this, RegisterActivity.class);
startActivity(intent);
}
}
PROFILE ACTIVITY(屏幕截图中的那个):
package com.ecotravel.eco_travel;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.support.v4.app.NavUtils;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
public class ProfileActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
// Show the Up button in the action bar.
setupActionBar();
}
/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.profile, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
/** Called when the user clicks the Search button */
public void searchFunc(View view) {
Intent intent = new Intent(this, SearchActivity.class);
startActivity(intent);
}
/** Called when the user clicks the Wishlist button */
public void wishFunc(View view) {
Intent intent = new Intent(this, WishlistActivity.class);
startActivity(intent);
}
}
有人可以解释为什么会这样吗?如果不能如何从我的活动中删除此栏?
编辑:logcat如下:
06-08 17:50:12.140: E/AndroidRuntime(3235): FATAL EXCEPTION: main
06-08 17:50:12.140: E/AndroidRuntime(3235): java.lang.NoClassDefFoundError: android.support.v4.app.NavUtils
06-08 17:50:12.140: E/AndroidRuntime(3235): at com.ecotravel.eco_travel.ProfileActivity.onOptionsItemSelected(ProfileActivity.java:51)
06-08 17:50:12.140: E/AndroidRuntime(3235): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
06-08 17:50:12.140: E/AndroidRuntime(3235): at com.android.internal.widget.ActionBarView$3.onClick(ActionBarView.java:167)
06-08 17:50:12.140: E/AndroidRuntime(3235): at android.view.View.performClick(View.java:4204)
06-08 17:50:12.140: E/AndroidRuntime(3235): at android.view.View$PerformClick.run(View.java:17355)
06-08 17:50:12.140: E/AndroidRuntime(3235): at android.os.Handler.handleCallback(Handler.java:725)
06-08 17:50:12.140: E/AndroidRuntime(3235): at android.os.Handler.dispatchMessage(Handler.java:92)
06-08 17:50:12.140: E/AndroidRuntime(3235): at android.os.Looper.loop(Looper.java:137)
06-08 17:50:12.140: E/AndroidRuntime(3235): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-08 17:50:12.140: E/AndroidRuntime(3235): at java.lang.reflect.Method.invokeNative(Native Method)
06-08 17:50:12.140: E/AndroidRuntime(3235): at java.lang.reflect.Method.invoke(Method.java:511)
06-08 17:50:12.140: E/AndroidRuntime(3235): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-08 17:50:12.140: E/AndroidRuntime(3235): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-08 17:50:12.140: E/AndroidRuntime(3235): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
我找到了解决方案。问题是升级到adt22。在adt22中,android-support-v4.jar的位置发生了变化,导致了这个错误。解决方案在这里:Libraries do not get added to APK anymore after upgrade to ADT 22