Android Null点异常错误

时间:2014-11-18 08:43:29

标签: android android-intent android-activity

enter image description here我正在尝试使用intent打开一个活动但是会出现以下错误

java.lang.NoClassDefFoundError:

我正在使用三个库 1.谷歌播放库 2.滑动菜单库 3.圆形计数器库

logcat的

           11-18 13:37:20.781: E/AndroidRuntime(17867): FATAL EXCEPTION: main
           11-18 13:37:20.781: E/AndroidRuntime(17867): Process: com.sayminicabdriver.driverapp, PID: 17867
           11-18 13:37:20.781: E/AndroidRuntime(17867): java.lang.NoClassDefFoundError: com.sayminicabdriver.driverapp.sliding
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at com.sayminicabdriver.driverapp.Login$1.onClick(Login.java:150)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at android.view.View.performClick(View.java:4438)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at android.view.View$PerformClick.run(View.java:18422)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at android.os.Handler.handleCallback(Handler.java:733)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at android.os.Handler.dispatchMessage(Handler.java:95)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at android.os.Looper.loop(Looper.java:136)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at android.app.ActivityThread.main(ActivityThread.java:5001)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at java.lang.reflect.Method.invokeNative(Native Method)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at java.lang.reflect.Method.invoke(Method.java:515)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
           11-18 13:37:20.781: E/AndroidRuntime(17867):     at dalvik.system.NativeStart.main(Native Method)

我的java代码

登录

     @Override
     protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.login);
     UserFunctions userFunction = new UserFunctions();
     JSONObject json = userFunction.loginUser(email,
                        password);

     try {
     if (json.getString(KEY_SUCCESS) != null) {

     String res = json.getString(KEY_SUCCESS);
     if (Integer.parseInt(res) == 1) {
     // user successfully logged in
     // Store user details in SQLite Database
     DatabaseHandler db = new DatabaseHandler(
     getApplicationContext());
     JSONObject json_user = json
                                        .getJSONObject("user");
     Intent dashboard = new Intent(Login.this,
                                        sliding.class);
                                // dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(dashboard);
       catch (JSONException e) {
                        e.printStackTrace();

                    }

以下是我的滑动活动..

滑动活动

    @Override
    public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
      setBehindContentView(R.layout.content_frame);
     SlidingMenu menu_bus = new SlidingMenu(this);
     SlidingMenu sm = getSlidingMenu();
     sm.setShadowWidthRes(R.dimen.shadow_width);
     sm.setShadowDrawable(R.drawable.shadow);
     sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
     sm.setFadeDegree(0.35f);
     sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

    //    menu_bus.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
   //firs slide menu, then second
   getSlidingMenu().setMode(SlidingMenu.LEFT_RIGHT);
  getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new                            MenuFragment()).commit();//mode two menus

        getSlidingMenu().setBehindOffset(50);                  
     //   getSupportActionBar().setDisplayShowCustomEnabled(true);
      //  getSupportActionBar().setDisplayHomeAsUpEnabled(true);        

        getSlidingMenu().setSecondaryMenu(R.layout.right_main);
        getSlidingMenu().setSecondaryShadowDrawable(R.drawable.shadowright);
 //start fragment for second menu
 getSupportFragmentManager()
 .beginTransaction()
 .add(R.id.right_container, new RightFragment(),"test_bus")
 .commit();

 Button csButton=(Button)findViewById(R.id.button1);


   csButton.setOnClickListener(new OnClickListener() {


    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        getSlidingMenu().showMenu();

    }//inside csButton1 onclick listener just need to call 

});
   // inside csButton onclick listener just need to call slidingMenu.showSecondaryMenu();
     Button csButton1=(Button)findViewById(R.id.button2);
   csButton1.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        getSlidingMenu().showSecondaryMenu();

    }
}) ;

当我的应用程序开始跟随警告和一个错误

logcat的

     11-18 16:19:04.596: W/dalvikvm(8732): Unable to resolve superclass of Landroid/support/v4/app/Watson; (113)
     11-18 16:19:04.596: W/dalvikvm(8732): Link of class 'Landroid/support/v4/app/Watson;' failed
     11-18 16:19:04.596: W/dalvikvm(8732): Unable to resolve superclass of Lcom/actionbarsherlock/app/SherlockFragmentActivity; (121)
     11-18 16:19:04.596: W/dalvikvm(8732): Link of class 'Lcom/actionbarsherlock/app/SherlockFragmentActivity;' failed
      11-18 16:19:04.596: W/dalvikvm(8732): Unable to resolve superclass of Lcom/jeremyfeinstein/slidingmenu/lib/app/SlidingFragmentActivity; (275)
      11-18 16:19:04.596: W/dalvikvm(8732): Link of class 'Lcom/jeremyfeinstein/slidingmenu/lib/app/SlidingFragmentActivity;' failed
      11-18 16:19:04.596: W/dalvikvm(8732): Unable to resolve superclass of Lcom/siliconicpro/sayminicab/sliding; (556)
      11-18 16:19:04.596: W/dalvikvm(8732): Link of class 'Lcom/siliconicpro/sayminicab/sliding;' failed
      11-18 16:19:04.606: E/dalvikvm(8732): Could not find class 'com.siliconicpro.sayminicab.sliding', referenced from method com.siliconicpro.sayminicab.Login$1.onClick
      11-18 16:19:04.606: W/dalvikvm(8732): VFY: unable to resolve const-class 600 (Lcom/siliconicpro/sayminicab/sliding;) in Lcom/siliconicpro/sayminicab/Login$1;

清单

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Widget.Sherlock.ActionBar.Solid" >

    <activity
     android:name="com.siliconicpro.sayminicab.MainActivity"
     android:label="@string/app_name"
      android:windowSoftInputMode="adjustPan"
         >

      <intent-filter>
       <action android:name="android.intent.action.MAIN" />

       <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        </activity>


       <activity android:name="com.siliconicpro.sayminicab.Register"
        android:windowSoftInputMode="adjustPan"
        android:configChanges="keyboardHidden|orientation|screenSize"/>
        <activity android:name="com.siliconicpro.sayminicab.Login"
        android:windowSoftInputMode="adjustPan"
        android:configChanges="keyboardHidden|orientation|screenSize"/>
        <activity android:name="com.siliconicpro.sayminicab.sliding"
        android:hardwareAccelerated="true"
         android:windowSoftInputMode="adjustPan"
         android:configChanges="keyboardHidden|orientation|screenSize"
          />

我想清除我的应用程序在测试期间成功运行的一件事我现在从设备上卸载它此错误即将来临

由于跟随错误

,我取消选中了私有库
         Unable to execute dex: Multiple dex files define              Lcom/jeremyfeinstein/slidingmenu/lib/CanvasTransformerBuilder$1;

提前致谢..

1 个答案:

答案 0 :(得分:0)

第一个错误Android Null点异常可能表示您在执行代码时未设置classpath选项。请点击此链接以了解如何设置类路径。 http://en.wikipedia.org/wiki/Classpath_%28Java%29

现在, 如果你使用外部罐子

将其复制到项目的“libs”文件夹中。 Android Tools应该完成其余的工作。 如果要使用的库是工作区中的单独项目。

在您的图书馆项目中:进入Properties-&gt; Android并选中“Is Library”复选框。 在您的应用项目中:转到Properties-&gt; Android并在同一部分添加库项目(单击“添加...”)。不要在这里查看“Is Library”! 这个问题的一些答案说你需要转到Properties-&gt; Java Build Path-&gt; Projects并在那里添加库项目。对于普通的Java项目,您可以这样做,但Android工具似乎不需要或不使用它。

最后,您可能希望确保lib包含在导出的应用程序中

转到属性 - > Java构建路径 - >订单和导出,确保选中库。