"不幸的是,应用程序(名称)已停止"信息

时间:2014-06-04 05:49:03

标签: android android-logcat

每当我运行此应用程序(探索ca)时,我收到此消息“不幸探索Ca已经停止”。 这个应用程序显示一个旅游列表,并通过单击菜单栏(花式/便宜/全部)为您提供过滤它的选项

我找到了解决方案:

第一步: 右键单击项目 - > java - >内置路径 - >来源 - >添加文件夹 - >点击gen和src - >点击确定

第二步: 右键单击项目 - >去属性 - >库 - >添加罐子 - > 然后从libs文件夹中添加项目的jar文件

MainActivity:

package com.exploreca.tourfinder;

import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;

import com.exploreca.tourfinder.db.ToursDataSource;
import com.exploreca.tourfinder.model.Tour;
import com.exploreca.tourfinder.xml.ToursPullParser;

public class MainActivity extends ListActivity {

    public static final String LOGTAG="EXPLORECA";
    public static final String USERNAME="pref_username";
    public static final String VIEWIMAGE="pref_viewimages";

    private SharedPreferences settings;
    private OnSharedPreferenceChangeListener listener;
    private List<Tour> tours;

    ToursDataSource datasource;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        settings = PreferenceManager.getDefaultSharedPreferences(this);

        listener = new OnSharedPreferenceChangeListener() {

            @Override
            public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
                    String key) {
                MainActivity.this.refreshDisplay();
            }
        };
        settings.registerOnSharedPreferenceChangeListener(listener);

        datasource = new ToursDataSource(this);
        datasource.open();

        tours = datasource.findAll();
        if (tours.size() == 0) {
            createData();
            tours = datasource.findAll();
        }

        refreshDisplay();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.menu_all:
            tours = datasource.findAll();
            refreshDisplay();
            break;

        case R.id.menu_cheap:
            tours = datasource.findFiltered("price <= 300", "price ASC");
            refreshDisplay();
            break;

        case R.id.menu_fancy:
            tours = datasource.findFiltered("price >= 1000", "price DESC");
            refreshDisplay();
            break;

        default:
            break;
        }
        return super.onOptionsItemSelected(item);
    }

    public void setPreference(View v) {
        Log.i(LOGTAG, "Clicked set");
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);
    }

    public void refreshDisplay() {
        ArrayAdapter<Tour> adapter = new ArrayAdapter<Tour>(this, 
                android.R.layout.simple_list_item_1, tours);
        setListAdapter(adapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        datasource.open();
    }

    @Override
    protected void onPause() {
        super.onPause();
        datasource.close();
    }

    private void createData() {
        ToursPullParser parser = new ToursPullParser();
        List<Tour> tours = parser.parseXML(this);

        for (Tour tour : tours) {
            datasource.create(tour);
        }

    }
}

logcat的:

06-04 08:39:51.231: D/AndroidRuntime(26469): Shutting down VM
 06-04 08:39:51.231: W/dalvikvm(26469): threadid=1: thread exiting with uncaught     exception (group=0x40ff4930)
 06-04 08:39:51.231: E/AndroidRuntime(26469): FATAL EXCEPTION: main
 06-04 08:39:51.231: E/AndroidRuntime(26469): java.lang.RuntimeException: Unable to instantiate activity    ComponentInfo{com.exploreca.tourfinder/com.exploreca.tourfinder.MainActivity}:  java.lang.ClassNotFoundException: Didn't find class "com.exploreca.tourfinder.MainActivity" on path: /data/app/com.exploreca.tourfinder-1.apk
 06-04 08:39:51.231: E/AndroidRuntime(26469):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2172)
 06-04 08:39:51.231: E/AndroidRuntime(26469):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
 06-04 08:39:51.231: E/AndroidRuntime(26469):   at android.app.ActivityThread.access$700(ActivityThread.java:151)
 06-04 08:39:51.231: E/AndroidRuntime(26469):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
 06-04 08:39:51.231: E/AndroidRuntime(26469):   at android.os.Handler.dispatchMessage(Handler.java:99)
 06-04 08:39:51.231: E/AndroidRuntime(26469):   at android.os.Looper.loop(Looper.java:137)
 06-04 08:39:51.231: E/AndroidRuntime(26469):   at android.app.ActivityThread.main(ActivityThread.java:5293)
 06-04 08:39:51.231: E/AndroidRuntime(26469):   at java.lang.reflect.Method.invokeNative(Native Method)
 06-04 08:39:51.231: E/AndroidRuntime(26469):   at java.lang.reflect.Method.invoke(Method.java:511)
  06-04 08:39:51.231: E/AndroidRuntime(26469):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
  06-04 08:39:51.231: E/AndroidRuntime(26469):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
  06-04 08:39:51.231: E/AndroidRuntime(26469):  at dalvik.system.NativeStart.main(Native Method)
  06-04 08:39:51.231: E/AndroidRuntime(26469): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.exploreca.tourfinder.MainActivity" on path: /data/app/com.exploreca.tourfinder-1.apk
  06-04 08:39:51.231: E/AndroidRuntime(26469):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
  06-04 08:39:51.231: E/AndroidRuntime(26469):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
  06-04 08:39:51.231: E/AndroidRuntime(26469):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
  06-04 08:39:51.231: E/AndroidRuntime(26469):  at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
  06-04 08:39:51.231: E/AndroidRuntime(26469):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)
  06-04 08:39:51.231: E/AndroidRuntime(26469):  ... 11 more

清单

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_exploreca"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.exploreca.tourfinder.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>
 </application>

</manifest>

0 个答案:

没有答案