导入库后应用程序无法正常工作

时间:2013-09-23 02:23:05

标签: android android-layout android-intent android-emulator

您好我创建了一个主应用程序,它有一个按钮“savenotes”,点击它应该打开Eclipse IDE中给出的“记事本”示例。这是我做的:

  1. 在我的工作区中导入NotesList项目
  2. 右键单击并将其标记为库
  3. 右键单击我的主项目并添加了对库的引用 4.在project.properties中添加了manifestmerger.enabled = true
  4. 现在奇怪的是,当我在清单中提到“savenotes”活动时,我应该声明我的logcat停止显示日志并让错误设备断开连接。当我删除此活动时,它开始显示日志。但是在这两种情况下,每次我点击我的savenotes按钮时,应用程序力都会关闭。我不确定我做错了什么,我错过了什么。

    Mainmenu.java

    package helog.diwesh.NugaBest;
    
    import hellog.diwesh.NugaBest.R;
    
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.TimeZone;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.database.Cursor;
    import android.graphics.Bitmap;
    import android.graphics.Bitmap.CompressFormat;
    import android.media.AudioManager;
    import android.media.SoundPool;
    import android.os.Bundle;
    import android.os.Environment;
    import android.os.Vibrator;
    import android.util.Log;
    import android.view.View;
    import android.view.Window;
    import android.view.animation.AlphaAnimation;
    import android.view.animation.Animation;
    import android.view.animation.ScaleAnimation;
    import android.widget.Button;
    import android.widget.Toast;
    
    import com.example.android.notepad.NotesList;
    
    public class NUGA_MainMenuActivity extends Activity {
    
        SoundPool mpool;
        int mlogon;
    
        Button mBtn1;
        Button mBtn2;
        Button mBtn3;
        Button mBtn4;
        Button mBtn5;
    
    
    
    Button mHistoryButton;
        Animation anim = null;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.mainmenu);
    
            mHistoryButton=(Button) findViewById(R.id.takeashot);
            mBtn1 = (Button) findViewById(R.id.BtnDisplay);
            mBtn2 = (Button) findViewById(R.id.BtnSlave);
            mHistoryButton.setOnClickListener(mClickListener);
            mBtn3=(Button) findViewById(R.id.takehelp);
            mBtn4=(Button) findViewById(R.id.aboutus);
            mBtn5=(Button) findViewById(R.id.savenotes);
    
            mBtn1.setOnClickListener(mClickListener);
            mBtn2.setOnClickListener(mClickListener);
            mBtn3.setOnClickListener(mClickListener);
            mBtn4.setOnClickListener(mClickListener);
            mBtn5.setOnClickListener(mClickListener);
    
            mpool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
            mlogon = mpool.load(this, R.raw.logon, 1);
    
            anim = new AlphaAnimation(0, 1);
            anim.setDuration(1500);
    
    
            mBtn1.startAnimation(anim);
            mBtn2.startAnimation(anim);
            mBtn3.startAnimation(anim);
            mBtn4.startAnimation(anim);
            mBtn5.startAnimation(anim);
    
            mpool.play(mlogon, 1, 1, 0, 0, 1);
    
        }
    
        Button.OnClickListener mClickListener = new View.OnClickListener() {
    
            Animation anim = null;
    
            @Override
            public void onClick(View v) {
                Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                vibe.vibrate(60);
    
                switch (v.getId()) {
                case R.id.BtnDisplay:
                    mpool.play(mlogon, 1, 1, 0, 0, 1);
                    anim = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    anim.setDuration(100);
                    mBtn1.startAnimation(anim);
                    Intent intent = new Intent(NUGA_MainMenuActivity.this, FileSiganlDisplay.class);
                    startActivity(intent);
                    //overridePendingTransition(R.anim.zoom_enter,R.anim.zoom_exit);
                    overridePendingTransition(R.anim.fade, R.anim.hold);
                    break;
    
                case R.id.BtnSlave:
    
                    mpool.play(mlogon, 1, 1, 0, 0, 1);
                    anim = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    anim.setDuration(100);
                    mBtn2.startAnimation(anim);
                    Intent intent1 = new Intent(NUGA_MainMenuActivity.this, BTSmartSlavemodule.class);
                    startActivity(intent1);
                    //overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
                    overridePendingTransition(R.anim.fade, R.anim.hold);
    
                    break ;
                case R.id.takeashot:
                    //snapFunction();
                    Intent intent2=new Intent(NUGA_MainMenuActivity.this,ImagesActivity.class);
                    startActivity(intent2);
                    break;
    
                case R.id.takehelp :
                    mpool.play(mlogon, 1, 1, 0, 0, 1);
                    anim = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    anim.setDuration(100);
                    mBtn3.startAnimation(anim);
                    Intent intent3=new Intent(NUGA_MainMenuActivity.this,HelpActivity.class);
                    startActivity(intent3);
                    overridePendingTransition(R.anim.fade, R.anim.hold);
                    break;
    
                case R.id.aboutus:
                    mpool.play(mlogon, 1, 1, 0, 0, 1);
                    anim = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    anim.setDuration(100);
                    mBtn4.startAnimation(anim);
                    Intent intent4=new Intent(NUGA_MainMenuActivity.this,AboutDevice.class);
                    startActivity(intent4);
                    overridePendingTransition(R.anim.fade, R.anim.hold);
                    break;
    
                    case R.id.savenotes:
                    mpool.play(mlogon, 1, 1, 0, 0, 1);
                    anim = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    anim.setDuration(100);
                    mBtn4.startAnimation(anim);
                    Intent intent5=new Intent(NUGA_MainMenuActivity.this,NotesList.class);
                    startActivity(intent5);
                    overridePendingTransition(R.anim.fade, R.anim.hold);
                    break;
    
                default:
                    break;
                }
    
            }
        };
    
        public void snapFunction()
        {
    
    
                Date currentTime = new Date();
                final SimpleDateFormat sdf =
                        new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss");
            // Give it to me in GMT time.
            sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
            //System.out.println("GMT time: " + sdf.format(currentTime));
            String ss=sdf.format(currentTime);
            Log.v("current time", ss);
    
    
    
    
                View mContent=findViewById(R.id.screenLayout);
                   mContent.setDrawingCacheEnabled(true);
                   Bitmap bitmap = mContent.getDrawingCache();
                   File sdCardDirectory = Environment.getExternalStorageDirectory();
                   File image = new File(sdCardDirectory, ss+".jpg");
                   name=ss;
                  // File file = new File("/sdcard/"+String.valueOf(currentId)+".png");           
                   {
                    if(!image.exists())
                         {
                         try {
    
                            image.createNewFile();
                            FileOutputStream ostream = new FileOutputStream(image);
                              bitmap.compress(CompressFormat.PNG, 10, ostream);                                        
                              ostream.close();
                             mContent.invalidate();
                         DB.insert(ss);
                             Cursor cursor=DB.retrieveFav();
                             if(cursor!=null)
                                 if(cursor.moveToFirst())
                                     new Toast(NUGA_MainMenuActivity.this).makeText(NUGA_MainMenuActivity.this, "DB contains:"+cursor.getCount()+"images", Toast.LENGTH_LONG).show();
                             cursor.close();
                         } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                         }
    
    
                   }
                   } 
        static String name="";
    

    }

    我的清单

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="hellog.diwesh.NugaBest"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk android:minSdkVersion="11" />
    
        <uses-permission android:name="android.permission.VIBRATE" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
        <uses-permission android:name="android.permission.BLUETOOTH" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    
        <application
            android:name="helog.diwesh.NugaBest.MyApplication" 
            android:debuggable="true"
            android:icon="@drawable/nuga"
            android:label="@string/app_name" >
            <activity
                android:name="helog.diwesh.NugaBest.NUGA_HealthCareActivity_Intro"
                android:configChanges="orientation|keyboardHidden"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
    
    
    
    
    
    
    
            // 4. Layout Management
    
            <activity
                android:name="helog.diwesh.NugaBest.FileSiganlDisplay"
                android:label="FileSiganlDisplay" />
            <activity
                android:name="helog.diwesh.NugaBest.NUGA_WebJoinActivity"
                android:label="NUGA_WebJoinActivity"
                android:windowSoftInputMode="stateHidden" />
            <activity
                android:name="helog.diwesh.NugaBest.NUGA_MainMenuActivity"
                android:label="NUGA_MainMenuActivity" />
            <activity
                android:name="helog.diwesh.NugaBest.BTSmartSlavemodule"
                android:configChanges="orientation|keyboardHidden"
                android:label="SmartSlavemodule" />
            <activity
                android:name="helog.diwesh.NugaBest.BTDeviceListActivity"
                android:configChanges="orientation|keyboardHidden"
                android:label="@string/select_device"
                android:theme="@android:style/Theme.Dialog" />
    
            <activity
                android:name="helog.diwesh.NugaBest.SnapActivity"
                android:label="@string/title_activity_snap" >
            </activity>
            <activity
                android:name="helog.diwesh.NugaBest.ImagesActivity"
                android:label="@string/title_activity_images" >
            </activity>
            <activity
                android:name="helog.diwesh.NugaBest.HelpActivity"
                android:label="@string/Help" >
            </activity>
            <activity
                android:name="helog.diwesh.NugaBest.AboutDevice"
                android:label="@string/aboutus" >
            </activity>
    
    
            <activity
                android:name="helog.diwesh.NugaBest.Savenotes"
                android:label="@string/savenotes" >
            </activity>
    
    
    
    
    
    
    
    
    
    
        </application>
    

    project.properties

    # This file is automatically generated by Android Tools.
    # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
    #
    # This file must be checked in Version Control Systems.
    #
    # To customize properties used by the Ant build system use,
    # "ant.properties", and override values to adapt the script to your
    # project structure.
    
    # Project target.
    target=Google Inc.:Google APIs:18
    android.library.reference.1=C:/Users/DPC/Downloads/adt-bundle-windows-x86-20130729/adt-bundle-windows-x86-20130729/sdk/samples/android-18/legacy/NotePad
    manifestmerger.enabled=true
    

    NotesList清单

    <!-- Declare the contents of this Android application.  The namespace
         attribute brings in the Android platform namespace, and the package
         supplies a unique name for the application.  When writing your
         own application, the package name must be changed from "com.example.*"
         to come from a domain that you own or have control over. -->
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.android.notepad" >
    
        <uses-sdk android:minSdkVersion="11" />
    
        <application android:icon="@drawable/app_notes"
            android:label="@string/app_name"
        >
            <provider android:name="NotePadProvider"
                android:authorities="com.google.provider.NotePad"
                android:exported="false">
                <grant-uri-permission android:pathPattern=".*" />
            </provider>
    
            <activity android:name="NotesList" android:label="@string/title_notes_list">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
                <intent-filter>
                    <action android:name="android.intent.action.VIEW" />
                    <action android:name="android.intent.action.EDIT" />
                    <action android:name="android.intent.action.PICK" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
                </intent-filter>
                <intent-filter>
                    <action android:name="android.intent.action.GET_CONTENT" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
                </intent-filter>
            </activity>
    
            <activity android:name="NoteEditor"
                android:theme="@android:style/Theme.Holo.Light"
                android:screenOrientation="sensor"
                android:configChanges="keyboardHidden|orientation"
            >
                <!-- This filter says that we can view or edit the data of
                     a single note -->
                <intent-filter android:label="@string/resolve_edit">
                    <action android:name="android.intent.action.VIEW" />
                    <action android:name="android.intent.action.EDIT" />
                    <action android:name="com.android.notepad.action.EDIT_NOTE" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
                </intent-filter>
    
                <!-- This filter says that we can create a new note inside
                     of a directory of notes.  The INSERT action creates an
                     empty note; the PASTE action initializes a new note from
                     the current contents of the clipboard. -->
                <intent-filter>
                    <action android:name="android.intent.action.INSERT" />
                    <action android:name="android.intent.action.PASTE" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
                </intent-filter>
    
            </activity>
    
            <activity android:name="TitleEditor"
                android:label="@string/title_edit_title"
                android:icon="@drawable/ic_menu_edit"
                android:theme="@android:style/Theme.Holo.Dialog"
                android:windowSoftInputMode="stateVisible">
                <!-- This activity implements an alternative action that can be
                     performed on notes: editing their title.  It can be used as
                     a default operation if the user invokes this action, and is
                     available as an alternative action for any note data. -->
                <intent-filter android:label="@string/resolve_title">
                    <!-- This is the action we perform.  It is a custom action we
                         define for our application, not a generic VIEW or EDIT
                         action since we are not a general note viewer/editor. -->
                    <action android:name="com.android.notepad.action.EDIT_TITLE" />
                    <!-- DEFAULT: execute if being directly invoked. -->
                    <category android:name="android.intent.category.DEFAULT" />
                    <!-- ALTERNATIVE: show as an alternative action when the user is
                         working with this type of data. -->
                    <category android:name="android.intent.category.ALTERNATIVE" />
                    <!-- SELECTED_ALTERNATIVE: show as an alternative action the user
                         can perform when selecting this type of data. -->
                    <category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
                    <!-- This is the data type we operate on. -->
                    <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
                </intent-filter>
            </activity>
    
            <activity android:name="NotesLiveFolder" android:label="@string/live_folder_name"
                android:icon="@drawable/live_folder_notes">
                <intent-filter>
                    <action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
    
        </application>
    
    </manifest>
    

    在清单

    中未添加savenotes时的Logcat详细信息
    09-22 22:07:36.157: D/dalvikvm(799): GC_FOR_ALLOC freed 67K, 7% free 2543K/2728K, paused 87ms, total 88ms
    09-22 22:07:36.237: I/dalvikvm-heap(799): Grow heap (frag case) to 4.939MB for 2457616-byte allocation
    09-22 22:07:36.367: D/dalvikvm(799): GC_FOR_ALLOC freed <1K, 4% free 4943K/5132K, paused 127ms, total 127ms
    09-22 22:07:36.887: W/SoundPool(799):   sample 1 not READY
    09-22 22:07:37.197: D/gralloc_goldfish(799): Emulator without GPU emulation detected.
    09-22 22:07:39.146: E/AudioTrack(799): Could not get audio output for stream type 3
    09-22 22:07:39.146: E/SoundPool(799): Error creating AudioTrack
    09-22 22:07:39.256: D/dalvikvm(799): GC_FOR_ALLOC freed 28K, 3% free 5673K/5828K, paused 21ms, total 23ms
    09-22 22:07:39.336: D/dalvikvm(799): GC_FOR_ALLOC freed 22K, 3% free 6090K/6236K, paused 21ms, total 26ms
    09-22 22:07:39.426: I/Choreographer(799): Skipped 72 frames!  The application may be doing too much work on its main thread.
    09-22 22:07:39.656: I/Choreographer(799): Skipped 54 frames!  The application may be doing too much work on its main thread.
    09-22 22:07:39.826: I/Choreographer(799): Skipped 33 frames!  The application may be doing too much work on its main thread.
    09-22 22:07:40.116: I/Choreographer(799): Skipped 56 frames!  The application may be doing too much work on its main thread.
    09-22 22:07:43.946: E/dalvikvm(799): Could not find class 'com.example.android.notepad.NotesList', referenced from method helog.diwesh.NugaBest.NUGA_MainMenuActivity$1.onClick
    09-22 22:07:43.976: W/dalvikvm(799): VFY: unable to resolve const-class 655 (Lcom/example/android/notepad/NotesList;) in Lhelog/diwesh/NugaBest/NUGA_MainMenuActivity$1;
    09-22 22:07:43.976: D/dalvikvm(799): VFY: replacing opcode 0x1c at 0x01fe
    09-22 22:07:44.186: D/dalvikvm(799): GC_FOR_ALLOC freed 85K, 3% free 6817K/7020K, paused 115ms, total 161ms
    09-22 22:07:44.236: I/dalvikvm-heap(799): Grow heap (frag case) to 9.113MB for 2457616-byte allocation
    09-22 22:07:44.426: D/dalvikvm(799): GC_FOR_ALLOC freed 2K, 3% free 9215K/9424K, paused 195ms, total 195ms
    09-22 22:07:44.726: W/SoundPool(799):   sample 1 not READY
    09-22 22:07:44.946: I/Choreographer(799): Skipped 43 frames!  The application may be doing too much work on its main thread.
    09-22 22:07:45.426: I/Choreographer(799): Skipped 49 frames!  The application may be doing too much work on its main thread.
    09-22 22:07:51.186: E/AudioTrack(799): Could not get audio output for stream type 3
    09-22 22:07:51.186: E/SoundPool(799): Error creating AudioTrack
    09-22 22:07:51.546: D/dalvikvm(799): GC_FOR_ALLOC freed 46K, 2% free 9476K/9640K, paused 39ms, total 68ms
    09-22 22:07:51.596: I/dalvikvm-heap(799): Grow heap (frag case) to 12.317MB for 3094560-byte allocation
    09-22 22:07:51.756: D/dalvikvm(799): GC_FOR_ALLOC freed 4220K, 35% free 8277K/12664K, paused 154ms, total 154ms
    09-22 22:07:51.977: I/Choreographer(799): Skipped 173 frames!  The application may be doing too much work on its main thread.
    09-22 22:07:52.106: I/Choreographer(799): Skipped 30 frames!  The application may be doing too much work on its main thread.
    09-22 22:07:52.476: I/Choreographer(799): Skipped 82 frames!  The application may be doing too much work on its main thread.
    09-22 22:07:59.586: E/AudioTrack(799): Could not get audio output for stream type 3
    09-22 22:07:59.586: E/SoundPool(799): Error creating AudioTrack
    09-22 22:07:59.586: D/AndroidRuntime(799): Shutting down VM
    09-22 22:07:59.586: W/dalvikvm(799): threadid=1: thread exiting with uncaught exception (group=0x41465700)
    09-22 22:07:59.626: E/AndroidRuntime(799): FATAL EXCEPTION: main
    09-22 22:07:59.626: E/AndroidRuntime(799): java.lang.NoClassDefFoundError: com.example.android.notepad.NotesList
    09-22 22:07:59.626: E/AndroidRuntime(799):  at helog.diwesh.NugaBest.NUGA_MainMenuActivity$1.onClick(NUGA_MainMenuActivity.java:152)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at android.view.View.performClick(View.java:4240)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at android.view.View$PerformClick.run(View.java:17721)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at android.os.Handler.handleCallback(Handler.java:730)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at android.os.Handler.dispatchMessage(Handler.java:92)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at android.os.Looper.loop(Looper.java:137)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at android.app.ActivityThread.main(ActivityThread.java:5103)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at java.lang.reflect.Method.invokeNative(Native Method)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at java.lang.reflect.Method.invoke(Method.java:525)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    09-22 22:07:59.626: E/AndroidRuntime(799):  at dalvik.system.NativeStart.main(Native Method)
    

1 个答案:

答案 0 :(得分:0)

问题是您的应用无法找到库并因异常java.lang.NoClassDefFoundError: com.example.android.notepad.NotesList

而崩溃

要检查的一些事项。

  1. 右键单击您的项目和属性。 在“android”选项卡中,您是否在“Library”部分下看到了您的库(NoteList)。

  2. 在“Java构建路径”下,您启用了“Android私有库”。 这应该针对两个项目完成。即。为Notelist和您的项目。