Listview 启动后崩溃

Posted

技术标签:

【中文标题】Listview 启动后崩溃【英文标题】:Listview crashed after launch 【发布时间】:2013-08-02 17:13:20 【问题描述】:

我的应用程序在我的列表视图启动后立即崩溃。我的列表视图是程序中运行的第一个活动。我没有编译错误,也不理解收到的 logcat 错误。我认为问题可能在我的清单中。任何援助将不胜感激。下面是我的 logcat 和清单。

Logcat:

 07-16 22:42:55.129: E/androidRuntime(1448): FATAL EXCEPTION: ModernAsyncTask #1
 07-16 22:42:55.129: E/AndroidRuntime(1448): java.lang.RuntimeException: An error occured while executing doInBackground()
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.support.v4.content.ModernAsyncTask$3.done(ModernAsyncTask.java:137)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at java.lang.Thread.run(Thread.java:856)
07-16 22:42:55.129: E/AndroidRuntime(1448): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.loginplus.home.ListProvider from ProcessRecord41c4be20 1448:com.example.listviewrefresh/10041 (pid=1448, uid=10041) that is not exported from uid 10040
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.os.Parcel.readException(Parcel.java:1327)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.os.Parcel.readException(Parcel.java:1281)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2201)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.app.ActivityThread.acquireProvider(ActivityThread.java:4024)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1612)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.content.ContentResolver.acquireProvider(ContentResolver.java:918)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.content.ContentResolver.query(ContentResolver.java:305)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:35)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:240)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:51)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:40)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:123)
07-16 22:42:55.129: E/AndroidRuntime(1448):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-16 22:42:55.129: E/AndroidRuntime(1448):     ... 4 more

列表视图活动:

 public class LoginList extends FragmentActivity implements   AdapterView.OnItemClickListener, OnClickListener, LoaderManager.LoaderCallbacks<Cursor> 

private ListView loginList;
private Button webLogin;
private SimpleCursorAdapter adapter;

@Override 
public void onCreate(Bundle savedInstanceState) 
super.onCreate(savedInstanceState);
setContentView(R.layout.login_listview);

loginList = (ListView)findViewById(R.id.loginlist);
loginList.setOnItemClickListener(this);

webLogin = (Button)findViewById(R.id.button3);
webLogin.setOnClickListener(this);



//Specify fields to display in the list
String[] from = new String[] ListProvider.COLUMN_NAME_SITE;

//Bind fields to listview
int[] to = new int[] R.id.loginlist;

// Create CursorAdapter and set it to display
adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, from, to, 0 );

loginList.setAdapter(adapter);

getSupportLoaderManager().initLoader( 0, null, this);




@Override
public void onItemClick(AdapterView<?> l, View v, int position, long id) 

// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Selected ID :" + position, Toast.LENGTH_SHORT).show();

Intent updateDeleteLoginInfo = new Intent (this, UpdateDeleteLoginList.class);

Cursor clickedObject = (Cursor)loginList.getItemAtPosition(0);

Bundle loginBundle = new Bundle();
loginBundle.putString("clickedWebSite",((LoginDetails) clickedObject).getsName());
loginBundle.putString("clickedWebAddress",((LoginDetails) clickedObject).getwUrl());
loginBundle.putString("clickedUserName",((LoginDetails) clickedObject).getuName());
loginBundle.putString("clickedPassWord",((LoginDetails) clickedObject).getpWord());
loginBundle.putString("clickedNotes",((LoginDetails) clickedObject).getlNotes());

updateDeleteLoginInfo.putExtras(loginBundle);

startActivityForResult(updateDeleteLoginInfo, 0); 
 

@Override
public void onClick(View arg0) 
// TODO Auto-generated method stub
Intent webLoginIntent = new Intent (this, LoginPlusActivity.class);
startActivity(webLoginIntent);


 @Override
 public Loader<Cursor> onCreateLoader(int ignored, final Bundle args) 

String [] columns =  ListProvider.COLUMN_ROWID, ListProvider.COLUMN_NAME_SITE;
CursorLoader cursorloader = new CursorLoader(this, ListProvider.CONTENT_URI, columns, null, null, null);

return cursorloader;


@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) 
adapter.swapCursor(cursor);


@Override
public void onLoaderReset (Loader<Cursor> loader) 
adapter.swapCursor(null);

    

清单:

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

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".LoginList"
        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=".LoginDB"
        android:label="@string/app_name" >
        <intent-filter >
            <action android:name="com.example.listviewrefresh.LOGINDB" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".LoginDetails"
        android:label="@string/app_name" >
        <intent-filter >
            <action android:name="com.example.listviewrefresh.LOGINDETAILS" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".UpdateDeleteLoginList"
        android:label="@string/app_name" >
        <intent-filter >
            <action android:name="com.example.listviewrefresh.UPDATEDELETELOGINLIST" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".LoginPlusActivity"
        android:label="@string/app_name" >
        <intent-filter >
            <action android:name="com.example.listviewrefresh.LOGINPLUSACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".dataStore"
        android:label="@string/app_name" >
        <intent-filter >
            <action android:name="com.example.listviewrefresh.DATASTORE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <provider
android:authorities="com.example.listviewrefresh.ListProvider"
android:multiprocess="true"
android:exported="false"
android:readPermission="com.example.listviewrefresh.ListProvider.READ_DATABASE"
android:writePermission="com.example.listviewrefresh.ListProvider.WRITE_DATABASE"
android:name="com.example.listviewrefresh.ListProvider"></provider>       
</application>
</manifest>

【问题讨论】:

我们需要有关您使用的列表视图适配器的更多信息。 发布异步任务代码 @FD_ listview 活动已添加 【参考方案1】:

这种看起来你可能正在移植一个应用程序,不是吗?

没有看到您正在使用的 ListProvider 类的详细信息,我们无法确定,但您的 ListProvider.CONTENT_URI 似乎是错误的 URI。

错误消息是说您无法访问 com.loginplus.home.ListProvider,而不是清单中的 com.example.listviewrefresh.ListProvider

如果它实际上是来自另一个应用程序的内容提供者,如果 android:exported 属性为 false,则会出现这样的错误。

要修复它,只需更新您的 ListProvider.CONTENT_URI 以匹配清单中的那个,或者,如果您尝试与另一个应用程序通信,请将 android:exported=true 添加到另一个应用程序的内容提供程序。

【讨论】:

【参考方案2】:

根据日志

07-16 22:42:55.129: E/AndroidRuntime(1448): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.loginplus.home.ListProvider from ProcessRecord41c4be20 1448:com.example.listviewrefresh/10041 (pid=1448, uid=10041) that is not exported from uid 10040

它正在尝试打开一些我在您的清单中看不到的提供程序(com.loginplus.home.ListProvider)。

理想情况下应该是打开com.example.listviewrefresh.ListProvider,你还有其他的供应商吗?

【讨论】:

以上是关于Listview 启动后崩溃的主要内容,如果未能解决你的问题,请参考以下文章

启动 ListView 类时应用程序强制关闭

为啥添加listView显示数据后app会崩溃

ListView 内的 ImageButton onclick 列表器不起作用。应用点击后崩溃

滚动时Listview滞后,添加项目时崩溃

自定义 listView 数组,搜索,在 NotifyDataSetChanged 上崩溃,加上 listView 没有得到更新

Android:线程从网络加载数据后更新Listview