1

我正在尝试从另一个活动(MainAcitivty)开始一项活动,但这不起作用,只要我单击按钮,它就会立即停止。

MainActivity.java 的代码:

public class MainActivity extends Activity implements OnClickListener {
    EditText title,body;
    Button btn,getnotes;
    NotepadDb notepad;
    Cursor cursor;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        title=(EditText)findViewById(R.id.title);
        body=(EditText)findViewById(R.id.body);
        btn=(Button)findViewById(R.id.btn);
        getnotes=(Button)findViewById(R.id.getnotes);
        btn.setOnClickListener(this);
        getnotes.setOnClickListener(this);
        notepad=new NotepadDb(this);
        notepad=notepad.open();
    }

    @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;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
            case R.id.btn:
                notepad.insert(title.getText().toString(), body.getText().toString());
                notepad.close();
                break;
            case R.id.getnotes:
                Intent i=new Intent("com.example.notepad2.FETCH");
                startActivity(i);
                break;
        }

    }


}

清单.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.notepad2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:screenOrientation="portrait"
            android:name="com.example.notepad2.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name=".Fetch"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="com.example.notepad2.FETCH" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

请帮我解决这个LogCat:

10-20 08:31:52.425: D/ExchangeService(621): !!! EAS ExchangeService, onCreate
10-20 08:31:52.425: D/ExchangeService(621): !!! EAS ExchangeService, onStartCommand, startingUp = false, running = false
10-20 08:31:52.425: D/ExchangeService(621): !!! EAS ExchangeService, onStartCommand, startingUp = true, running = false
10-20 08:31:52.435: W/ActivityManager(278): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
10-20 08:31:52.435: D/ExchangeService(621): !!! Email application not found; stopping self
10-20 08:31:52.455: W/ActivityManager(278): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
10-20 08:31:52.455: E/ActivityThread(621): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40ce2778 that was originally bound here
10-20 08:31:52.455: E/ActivityThread(621): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40ce2778 that was originally bound here
10-20 08:31:52.455: E/ActivityThread(621):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
10-20 08:31:52.455: E/ActivityThread(621):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
10-20 08:31:52.455: E/ActivityThread(621):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
10-20 08:31:52.455: E/ActivityThread(621):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
10-20 08:31:52.455: E/ActivityThread(621):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
10-20 08:31:52.455: E/ActivityThread(621):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
10-20 08:31:52.455: E/ActivityThread(621):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
10-20 08:31:52.455: E/ActivityThread(621):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
10-20 08:31:52.455: E/ActivityThread(621):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
10-20 08:31:52.455: E/ActivityThread(621):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
10-20 08:31:52.455: E/ActivityThread(621):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
10-20 08:31:52.455: E/ActivityThread(621):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
10-20 08:31:52.455: E/ActivityThread(621):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-20 08:31:52.455: E/ActivityThread(621):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-20 08:31:52.455: E/ActivityThread(621):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-20 08:31:52.455: E/ActivityThread(621):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-20 08:31:52.455: E/ActivityThread(621):  at java.lang.Thread.run(Thread.java:856)
10-20 08:31:52.466: E/StrictMode(621): null
10-20 08:31:52.466: E/StrictMode(621): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40ce2778 that was originally bound here
10-20 08:31:52.466: E/StrictMode(621):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
10-20 08:31:52.466: E/StrictMode(621):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
10-20 08:31:52.466: E/StrictMode(621):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
10-20 08:31:52.466: E/StrictMode(621):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
10-20 08:31:52.466: E/StrictMode(621):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
10-20 08:31:52.466: E/StrictMode(621):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
10-20 08:31:52.466: E/StrictMode(621):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
10-20 08:31:52.466: E/StrictMode(621):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
10-20 08:31:52.466: E/StrictMode(621):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
10-20 08:31:52.466: E/StrictMode(621):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
10-20 08:31:52.466: E/StrictMode(621):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
10-20 08:31:52.466: E/StrictMode(621):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
10-20 08:31:52.466: E/StrictMode(621):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-20 08:31:52.466: E/StrictMode(621):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-20 08:31:52.466: E/StrictMode(621):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-20 08:31:52.466: E/StrictMode(621):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-20 08:31:52.466: E/StrictMode(621):  at java.lang.Thread.run(Thread.java:856)
10-20 08:31:52.466: W/ActivityManager(278): Unbind failed: could not find connection for android.os.BinderProxy@410713e8
10-20 08:31:52.476: E/ActivityThread(621): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cede60 that was originally bound here
10-20 08:31:52.476: E/ActivityThread(621): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cede60 that was originally bound here
10-20 08:31:52.476: E/ActivityThread(621):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
10-20 08:31:52.476: E/ActivityThread(621):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
10-20 08:31:52.476: E/ActivityThread(621):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
10-20 08:31:52.476: E/ActivityThread(621):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
10-20 08:31:52.476: E/ActivityThread(621):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
10-20 08:31:52.476: E/ActivityThread(621):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
10-20 08:31:52.476: E/ActivityThread(621):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
10-20 08:31:52.476: E/ActivityThread(621):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
10-20 08:31:52.476: E/ActivityThread(621):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
10-20 08:31:52.476: E/ActivityThread(621):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
10-20 08:31:52.476: E/ActivityThread(621):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
10-20 08:31:52.476: E/ActivityThread(621):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-20 08:31:52.476: E/ActivityThread(621):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-20 08:31:52.476: E/ActivityThread(621):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-20 08:31:52.476: E/ActivityThread(621):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-20 08:31:52.476: E/ActivityThread(621):  at java.lang.Thread.run(Thread.java:856)
10-20 08:31:52.486: E/StrictMode(621): null
10-20 08:31:52.486: E/StrictMode(621): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cede60 that was originally bound here
10-20 08:31:52.486: E/StrictMode(621):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
10-20 08:31:52.486: E/StrictMode(621):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
10-20 08:31:52.486: E/StrictMode(621):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
10-20 08:31:52.486: E/StrictMode(621):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
10-20 08:31:52.486: E/StrictMode(621):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
10-20 08:31:52.486: E/StrictMode(621):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
10-20 08:31:52.486: E/StrictMode(621):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
10-20 08:31:52.486: E/StrictMode(621):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
10-20 08:31:52.486: E/StrictMode(621):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
10-20 08:31:52.486: E/StrictMode(621):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
10-20 08:31:52.486: E/StrictMode(621):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
10-20 08:31:52.486: E/StrictMode(621):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-20 08:31:52.486: E/StrictMode(621):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-20 08:31:52.486: E/StrictMode(621):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-20 08:31:52.486: E/StrictMode(621):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-20 08:31:52.486: E/StrictMode(621):  at java.lang.Thread.run(Thread.java:856)
10-20 08:31:52.496: W/ActivityManager(278): Unbind failed: could not find connection for android.os.BinderProxy@40f5c128
10-20 08:31:55.095: D/AndroidRuntime(3734): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
10-20 08:31:55.095: D/AndroidRuntime(3734): CheckJNI is ON
10-20 08:31:55.125: D/dalvikvm(3734): Trying to load lib libjavacore.so 0x0
10-20 08:31:55.135: D/dalvikvm(3734): Added shared lib libjavacore.so 0x0
10-20 08:31:55.155: D/dalvikvm(3734): Trying to load lib libnativehelper.so 0x0
10-20 08:31:55.155: D/dalvikvm(3734): Added shared lib libnativehelper.so 0x0
10-20 08:31:55.745: D/AndroidRuntime(3734): Calling main entry com.android.commands.pm.Pm
10-20 08:31:55.805: W/ActivityManager(278): No content provider found for permission revoke: file:///data/local/tmp/Notepad2.apk
10-20 08:31:55.825: W/ActivityManager(278): No content provider found for permission revoke: file:///data/local/tmp/Notepad2.apk
10-20 08:31:55.825: I/PackageManager(278): Copying native libraries to /data/app-lib/vmdl-1772376627
10-20 08:31:55.965: D/dalvikvm(278): GC_CONCURRENT freed 675K, 18% free 5665K/6848K, paused 7ms+10ms, total 91ms
10-20 08:31:56.105: I/PackageManager(278): Removing non-system package:com.example.notepad2
10-20 08:31:56.105: I/ActivityManager(278): Force stopping package com.example.notepad2 appid=10051 user=-1
10-20 08:31:56.185: I/PackageManager(278): Package com.example.notepad2 codePath changed from /data/app/com.example.notepad2-2.apk to /data/app/com.example.notepad2-1.apk; Retaining data and using new
10-20 08:31:56.195: I/PackageManager(278): Running dexopt on: com.example.notepad2
10-20 08:31:56.945: D/dalvikvm(3745): DexOpt: load 134ms, verify+opt 442ms, 814852 bytes
10-20 08:31:56.965: I/ActivityManager(278): Force stopping package com.example.notepad2 appid=10051 user=-1
10-20 08:31:56.965: W/PackageManager(278): Code path for pkg : com.example.notepad2 changing from /data/app/com.example.notepad2-2.apk to /data/app/com.example.notepad2-1.apk
10-20 08:31:56.965: W/PackageManager(278): Resource path for pkg : com.example.notepad2 changing from /data/app/com.example.notepad2-2.apk to /data/app/com.example.notepad2-1.apk
10-20 08:31:57.045: D/PackageManager(278): New package installed in /data/app/com.example.notepad2-1.apk
10-20 08:31:57.165: D/dalvikvm(278): GC_FOR_ALLOC freed 512K, 18% free 5654K/6848K, paused 66ms, total 66ms
10-20 08:31:57.205: I/ActivityManager(278): Force stopping package com.example.notepad2 appid=10051 user=0
10-20 08:31:57.275: D/dalvikvm(407): GC_EXPLICIT freed 265K, 21% free 3397K/4280K, paused 3ms+6ms, total 60ms
10-20 08:31:57.405: I/ActivityManager(278): Start proc com.android.keychain for broadcast com.android.keychain/.KeyChainBroadcastReceiver: pid=3746 uid=1000 gids={41000, 1015, 1028, 3002, 3001, 3003}
10-20 08:31:57.476: D/dalvikvm(37): GC_EXPLICIT freed 38K, 8% free 2365K/2544K, paused 3ms+14ms, total 88ms
10-20 08:31:57.516: I/InputReader(278): Reconfiguring input devices.  changes=0x00000010
10-20 08:31:57.545: D/dalvikvm(37): GC_EXPLICIT freed <1K, 8% free 2365K/2544K, paused 3ms+4ms, total 74ms
10-20 08:31:57.605: E/Trace(3746): error opening trace file: No such file or directory (2)
10-20 08:31:57.625: D/dalvikvm(37): GC_EXPLICIT freed <1K, 8% free 2365K/2544K, paused 3ms+4ms, total 78ms
10-20 08:31:57.645: W/ContextImpl(3746): Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1352 android.content.ContextWrapper.startService:450 android.content.ContextWrapper.startService:450 com.android.keychain.KeyChainBroadcastReceiver.onReceive:12 android.app.ActivityThread.handleReceiver:2376 
10-20 08:31:57.675: W/AccountTypeManager(3543): No authenticator found for type=com.android.exchange, ignoring it.
10-20 08:31:57.685: I/AccountTypeManager(3543): Loaded meta-data for 0 account types, 0 accounts in 56ms(wall) 2ms(cpu)
10-20 08:31:57.725: D/dalvikvm(2259): GC_EXPLICIT freed 236K, 12% free 2779K/3156K, paused 4ms+18ms, total 481ms
10-20 08:31:57.925: I/InputReader(278): Reconfiguring input devices.  changes=0x00000010
10-20 08:31:58.085: W/InputMethodManagerService(278): Found no subtypes in a system IME: com.android.inputmethod.pinyin
10-20 08:31:58.095: W/AccountTypeManager(3543): No authenticator found for type=com.android.exchange, ignoring it.
10-20 08:31:58.125: I/AccountTypeManager(3543): Loaded meta-data for 0 account types, 0 accounts in 30ms(wall) 3ms(cpu)
10-20 08:31:58.145: I/ActivityManager(278): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=3760 uid=10014 gids={50014, 1015, 1028}
10-20 08:31:58.245: E/Trace(3760): error opening trace file: No such file or directory (2)
10-20 08:31:58.516: D/dalvikvm(278): GC_EXPLICIT freed 553K, 18% free 5616K/6848K, paused 35ms+28ms, total 266ms
10-20 08:31:58.545: D/AndroidRuntime(3734): Shutting down VM
10-20 08:31:58.555: D/dalvikvm(3734): GC_CONCURRENT freed 94K, 18% free 467K/564K, paused 1ms+1ms, total 10ms
10-20 08:31:58.555: D/jdwp(3734): Got wake-up signal, bailing out of select
10-20 08:31:58.555: D/dalvikvm(3734): Debugger has detached; object registry had 1 entries
10-20 08:31:58.645: I/ActivityManager(278): Start proc com.android.quicksearchbox for broadcast com.android.quicksearchbox/.CorporaUpdateReceiver: pid=3773 uid=10001 gids={50001, 3003, 1028}
10-20 08:31:58.755: E/Trace(3773): error opening trace file: No such file or directory (2)
10-20 08:31:59.145: I/Choreographer(407): Skipped 526 frames!  The application may be doing too much work on its main thread.
10-20 08:31:59.295: W/RecognitionManagerService(278): no available voice recognition services found for user 0
10-20 08:31:59.305: D/AndroidRuntime(3793): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
10-20 08:31:59.305: D/AndroidRuntime(3793): CheckJNI is ON
10-20 08:31:59.365: D/dalvikvm(3793): Trying to load lib libjavacore.so 0x0
10-20 08:31:59.385: D/dalvikvm(3793): Added shared lib libjavacore.so 0x0
10-20 08:31:59.415: D/dalvikvm(3793): Trying to load lib libnativehelper.so 0x0
10-20 08:31:59.425: D/dalvikvm(3793): Added shared lib libnativehelper.so 0x0
10-20 08:32:00.145: I/Choreographer(407): Skipped 117 frames!  The application may be doing too much work on its main thread.
10-20 08:32:00.255: D/AndroidRuntime(3793): Calling main entry com.android.commands.am.Am
10-20 08:32:00.265: D/dalvikvm(3793): Note: class Landroid/app/ActivityManagerNative; has 157 unimplemented (abstract) methods
10-20 08:32:00.285: I/ActivityManager(278): Force stopping package com.example.notepad2 appid=10051 user=-1
10-20 08:32:00.285: I/ActivityManager(278): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.notepad2/.MainActivity} from pid 3793
10-20 08:32:00.315: W/WindowManager(278): Failure taking screenshot for (123x205) to layer 21010
10-20 08:32:00.355: D/dalvikvm(3804): Not late-enabling CheckJNI (already on)
10-20 08:32:00.365: D/AndroidRuntime(3793): Shutting down VM
10-20 08:32:00.375: D/dalvikvm(3793): GC_CONCURRENT freed 95K, 17% free 502K/600K, paused 1ms+1ms, total 10ms
10-20 08:32:00.375: D/jdwp(3793): Got wake-up signal, bailing out of select
10-20 08:32:00.375: D/dalvikvm(3793): Debugger has detached; object registry had 1 entries
10-20 08:32:00.395: I/ActivityManager(278): Start proc com.example.notepad2 for activity com.example.notepad2/.MainActivity: pid=3804 uid=10051 gids={50051, 1015, 1028}
10-20 08:32:00.575: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
10-20 08:32:00.735: E/Trace(3804): error opening trace file: No such file or directory (2)
10-20 08:32:00.815: W/ActivityThread(3804): Application com.example.notepad2 is waiting for the debugger on port 8100...
10-20 08:32:00.885: I/System.out(3804): Sending WAIT chunk
10-20 08:32:00.895: I/dalvikvm(3804): Debugger is active
10-20 08:32:01.095: I/System.out(3804): Debugger has connected
10-20 08:32:01.095: I/System.out(3804): waiting for debugger to settle...
10-20 08:32:01.295: I/System.out(3804): waiting for debugger to settle...
10-20 08:32:01.395: I/Choreographer(278): Skipped 62 frames!  The application may be doing too much work on its main thread.
10-20 08:32:01.395: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
10-20 08:32:01.495: I/System.out(3804): waiting for debugger to settle...
10-20 08:32:01.695: I/System.out(3804): waiting for debugger to settle...
10-20 08:32:01.905: I/System.out(3804): waiting for debugger to settle...
10-20 08:32:02.107: I/System.out(3804): waiting for debugger to settle...
10-20 08:32:02.305: I/System.out(3804): waiting for debugger to settle...
10-20 08:32:02.511: I/System.out(3804): waiting for debugger to settle...
10-20 08:32:02.715: I/System.out(3804): debugger has settled (1466)
10-20 08:32:02.735: I/Choreographer(278): Skipped 33 frames!  The application may be doing too much work on its main thread.
10-20 08:32:04.175: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
10-20 08:32:04.305: I/Choreographer(3804): Skipped 93 frames!  The application may be doing too much work on its main thread.
10-20 08:32:04.426: D/gralloc_goldfish(3804): Emulator without GPU emulation detected.
10-20 08:32:04.506: I/ActivityManager(278): Displayed com.example.notepad2/.MainActivity: +4s168ms
10-20 08:32:04.555: I/Choreographer(278): Skipped 33 frames!  The application may be doing too much work on its main thread.
10-20 08:32:08.815: I/Choreographer(3804): Skipped 105 frames!  The application may be doing too much work on its main thread.
10-20 08:32:09.075: I/ActivityManager(278): START u0 {act=com.example.notepad2.FETCH cmp=com.example.notepad2/.Fetch} from pid 3804
10-20 08:32:09.085: W/WindowManager(278): Failure taking screenshot for (123x205) to layer 21015
10-20 08:32:09.165: I/Choreographer(3804): Skipped 51 frames!  The application may be doing too much work on its main thread.
10-20 08:32:19.095: W/ActivityManager(278): Launch timeout has expired, giving up wake lock!
10-20 08:32:19.145: W/ActivityManager(278): Activity idle timeout for ActivityRecord{40f079c0 u0 com.example.notepad2/.Fetch}

获取.java

package com.example.notepad2;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Fetch extends ListActivity{
//NotepadDb notes=new NotepadDb(this);
Cursor cursor;
String[] title;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    //notes.open();
    //cursor=notes.fetch();
    /*cursor.moveToFirst();
    for(int i=0;i<cursor.getCount();i++){
        title[i]=cursor.getString(1);
        cursor.moveToNext();
    }*/
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, title));
    list=getListView();
    list.setTextFilterEnabled(true);
    list.setChoiceMode(1);
}
}

NotepadDb.java:

public class NotepadDb extends Activity {
private static final String DATABASE_NAME="Notepad";
private static final String TABLE_NAME="note";
private final int DATABASE_VERSION=1;
private static final String KEY_TITLE="title";
private static final String KEY_BODY="body";
private static final String ID="_id";
private static final String Query="create table note(_id integer auto_increment primary key,title text not null,body text not null);";
DatabaseHelper dbHelper;
SQLiteDatabase mydb;
Cursor cursor;
private Context cntxt;
public class DatabaseHelper extends SQLiteOpenHelper{

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME,null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(Query);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("drop table note");
        onCreate(db);
    }

}
public NotepadDb(Context context){
    cntxt=context;
}
public NotepadDb open() throws SQLException{
    dbHelper=new DatabaseHelper(cntxt);
    mydb=dbHelper.getWritableDatabase();
    return this;
}
public void insert(String title,String body){
    mydb.execSQL("insert into note values(null,'"+title+"','"+body+"');");
}
public Cursor fetch() throws SQLException{
    return mydb.query("note", new String[]{"title","body"},null,null,null,null,null);
}
public void close(){
    dbHelper.close();
}

}
4

2 回答 2

1

改变这个

<activity 
        android:name=".Fetch" // change to FETCH
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="com.example.notepad2.FETCH" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

   <activity 
        android:name="com.example.notepad2.FETCH"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="com.example.notepad2.FETCH" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

编辑1:

从您的评论中,您说您的活动类名称是Fetch.java

      Intent i=new Intent("com.example.notepad2.Fetch");

在清单更改中

  <activity 
        android:name="com.example.notepad2.Fetch"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="com.example.notepad2.Fetch" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

String title[]的没有初始化

您在适配器初始化中使用相同的title

编辑2:

更改 Fetch.java

public class Fetch extends ListActivity{
Cursor cursor;
ArrayList<String> aa = new ArrayList<String>();
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    NotepadDb notes=new NotepadDb(this);
    notes.open();
    cursor=notes.fetch();
    if(cursor!=null)
    {
        Log.i("................",""+cursor.getCount());
         if (cursor.moveToFirst()) {
                do {
                    Log.i("",""+cursor.getString(0));
                    Log.i("",""+cursor.getString(1));
                    aa.add(cursor.getString(0));
                    aa.add(cursor.getString(1));
                } while (cursor.moveToNext());
            }
    }
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, aa));
    list=getListView();
    list.setTextFilterEnabled(true);
    list.setChoiceMode(1);
}
}

我改变了你NotePadDB.class一点

public class NotepadDb{
private static final String DATABASE_NAME="NotepadTest";
private static final String TABLE_NAME="note1";
private final int DATABASE_VERSION=2;
private static final String KEY_TITLE="title";
private static final String KEY_BODY="body";
private static final String ID="_id";
DatabaseHelper dbHelper;
SQLiteDatabase mydb;
Cursor cursor;
private Context cntxt;
public class DatabaseHelper extends SQLiteOpenHelper{

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME,null, DATABASE_VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + TABLE_NAME + " (" 
                + ID + " INTEGER PRIMARY KEY, " +
                KEY_TITLE + " TEXT NOT NULL , " +
                KEY_BODY + " TEXT NOT NULL );");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table note");
        onCreate(db);
    }

}
public NotepadDb(Context context){
    cntxt=context;
}
public NotepadDb open() throws SQLException{
    dbHelper=new DatabaseHelper(cntxt);
    mydb=dbHelper.getWritableDatabase();
    return this;
}
public void insert(String title,String body){
    ContentValues values = new ContentValues();
    values.put(KEY_TITLE, title); // Contact Name
    values.put(KEY_BODY, body);
    mydb.insert(TABLE_NAME, null, values);
    mydb.close(); 
}
public Cursor fetch() throws SQLException{
    Cursor cursor =mydb.query(TABLE_NAME, new String[]{KEY_TITLE,KEY_BODY},null,null,null,null,null);
    return cursor;
}
public void close(){
    dbHelper.close();
}
}

此外,Edit 3 仅用于演示。我使用了一个数组列表。如果您需要在单行中显示标题和正文,请使用自定义适配器。现在它在单独的行中显示标题和正文在另一个下方,这是不好的。

除此之外,您NotePadDb无需扩展Activity

于 2013-10-20T08:30:52.677 回答
1

您是否尝试过擦除模拟器,甚至尝试过另一个?我不明白为什么您的应用程序应该泄漏服务,因为它没有使用!

或者尝试禁用 Exchange:

一个更简单的解决方法是在设置下的模拟设备中禁用“交换服务”:应用程序:全部

引自五子雀。这有点断章取义,但(至少我希望)你不能泄露一个不存在的服务

于 2013-10-20T09:29:30.163 回答