android新手,No content provider found for permission revoke: file:///data/local/tmp/rssreader.apk

Java_Liam 发布于 2013/08/01 17:31
阅读 18K+
收藏 1
  • 最近在进军android,按照教程上写了一点小代码,一个很简易的RSS阅读器。在2.3.3的AVD上能够运行,在2.3.5的实体机上运行正常,但是在4.0的AVD上无法运行,直接停止工作,在4.0.4的实体机上也是这样
  • 运行日志如下:
  • 07-31 16:42:21.614: WARN/ActivityManager(82): No content provider found for permission revoke: file:///data/local/tmp/rssreader.apk
    07-31 16:42:21.652: WARN/ActivityManager(82): No content provider found for permission revoke: file:///data/local/tmp/rssreader.apk
    07-31 16:42:24.632: WARN/RecognitionManagerService(82): no available voice recognition services found
    07-31 16:42:30.382: WARN/WindowManager(82): Failure taking screenshot for (240x394) to layer 21005
    07-31 16:42:31.131: WARN/NetworkManagementSocketTagger(82): setKernelCountSet(10043, 1) failed with errno -2
    07-31 16:42:32.461: WARN/System.err(18285): android.os.NetworkOnMainThreadException
    07-31 16:42:32.471: WARN/System.err(18285):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084)
    07-31 16:42:32.471: WARN/System.err(18285):     at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
    07-31 16:42:32.471: WARN/System.err(18285):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
    07-31 16:42:32.471: WARN/System.err(18285):     at java.net.InetAddress.getAllByName(InetAddress.java:220)
    07-31 16:42:32.471: WARN/System.err(18285):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
    07-31 16:42:32.471: WARN/System.err(18285):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
    07-31 16:42:32.471: WARN/System.err(18285):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
    07-31 16:42:32.481: WARN/System.err(18285):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
    07-31 16:42:32.481: WARN/System.err(18285):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
    07-31 16:42:32.481: WARN/System.err(18285):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
    07-31 16:42:32.481: WARN/System.err(18285):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
    07-31 16:42:32.481: WARN/System.err(18285):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
    07-31 16:42:32.481: WARN/System.err(18285):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
    07-31 16:42:32.481: WARN/System.err(18285):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
    07-31 16:42:32.491: WARN/System.err(18285):     at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:479)
    07-31 16:42:32.491: WARN/System.err(18285):     at com.Liam.servicers.NetTool.getStream(NetTool.java:14)
    07-31 16:42:32.491: WARN/System.err(18285):     at com.Liam.rssreader.RssShowActivity.onCreate(RssShowActivity.java:41)
    07-31 16:42:32.491: WARN/System.err(18285):     at android.app.Activity.performCreate(Activity.java:4465)
    07-31 16:42:32.491: WARN/System.err(18285):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    07-31 16:42:32.491: WARN/System.err(18285):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
    07-31 16:42:32.491: WARN/System.err(18285):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
    07-31 16:42:32.491: WARN/System.err(18285):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
    07-31 16:42:32.491: WARN/System.err(18285):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
    07-31 16:42:32.491: WARN/System.err(18285):     at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 16:42:32.491: WARN/System.err(18285):     at android.os.Looper.loop(Looper.java:137)
    07-31 16:42:32.491: WARN/System.err(18285):     at android.app.ActivityThread.main(ActivityThread.java:4340)
    07-31 16:42:32.516: WARN/System.err(18285):     at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 16:42:32.516: WARN/System.err(18285):     at java.lang.reflect.Method.invoke(Method.java:511)
    07-31 16:42:32.516: WARN/System.err(18285):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    07-31 16:42:32.516: WARN/System.err(18285):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    07-31 16:42:32.524: WARN/System.err(18285):     at dalvik.system.NativeStart.main(Native Method)
    07-31 16:42:32.524: WARN/dalvikvm(18285): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285): FATAL EXCEPTION: main
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Liam.rssreader/com.Liam.rssreader.RssShowActivity}: java.lang.NullPointerException
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at android.os.Looper.loop(Looper.java:137)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at android.app.ActivityThread.main(ActivityThread.java:4340)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at java.lang.reflect.Method.invoke(Method.java:511)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at dalvik.system.NativeStart.main(Native Method)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285): Caused by: java.lang.NullPointerException
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at com.Liam.rssreader.RssShowActivity.onCreate(RssShowActivity.java:47)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at android.app.Activity.performCreate(Activity.java:4465)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
    07-31 16:42:32.543: ERROR/AndroidRuntime(18285):     ... 11 more
    07-31 16:42:32.562: WARN/ActivityManager(82):   Force finishing activity com.Liam.rssreader/.RssShowActivity
    07-31 16:42:32.572: WARN/WindowManager(82): Failure taking screenshot for (240x394) to layer 21010
    07-31 16:42:33.137: WARN/ActivityManager(82): Activity pause timeout for ActivityRecord{418d32c8 com.Liam.rssreader/.RssShowActivity}
    07-31 16:42:33.541: WARN/NetworkManagementSocketTagger(82): setKernelCountSet(10043, 0) failed with errno -2
    07-31 16:42:43.556: WARN/ActivityManager(82): Activity destroy timeout for ActivityRecord{418d32c8 com.Liam.rssreader/.RssShowActivity}
    07-31 16:43:18.571: WARN/InputManagerService(82): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@41975450
    07-31 16:43:19.811: ERROR/PinyinDecoderService(18386): WARNING: Could not load jni_pinyinime natives
    07-31 16:43:19.881: WARN/dalvikvm(18386): No implementation found for native Lcom/android/inputmethod/pinyin/PinyinDecoderService;.nativeImOpenDecoderFd (Ljava/io/FileDescriptor;JJ[B)Z
    07-31 16:43:19.881: WARN/dalvikvm(18386): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386): FATAL EXCEPTION: main
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386): java.lang.UnsatisfiedLinkError: nativeImOpenDecoderFd
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at com.android.inputmethod.pinyin.PinyinDecoderService.nativeImOpenDecoderFd(Native Method)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at com.android.inputmethod.pinyin.PinyinDecoderService.initPinyinEngine(PinyinDecoderService.java:141)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at com.android.inputmethod.pinyin.PinyinDecoderService.onCreate(PinyinDecoderService.java:162)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2252)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at android.app.ActivityThread.access$1600(ActivityThread.java:122)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at android.os.Looper.loop(Looper.java:137)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at android.app.ActivityThread.main(ActivityThread.java:4340)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at java.lang.reflect.Method.invoke(Method.java:511)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    07-31 16:43:19.943: ERROR/AndroidRuntime(18386):     at dalvik.system.NativeStart.main(Native Method)
    07-31 16:43:39.582: WARN/ActivityManager(82): Timeout executing service: ServiceRecord{41a85d00 com.android.inputmethod.pinyin/.PinyinDecoderService}
    No content provider found for permission revoke: file:///data/local/tmp/rssreader.apk
    这句话没怎么看懂,我已经设置了权限了,下面是AndroidMainfest.xml文件:
  • <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.Liam.rssreader"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="14" />
    
        <uses-permission android:name="android.permission.INTERNET" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.Liam.rssreader.RssShowActivity"
                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="com.Liam.rssreader.DetailsActivity"
                android:label="@string/app_name"></activity>
        </application>
    
    </manifest>
    Pull解析xml的工具类    PullParseServicer.java:
  • package com.Liam.servicers;
    
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.xmlpull.v1.XmlPullParser;
    
    import android.util.Xml;
    
    import com.Liam.beans.News;
    
    public class PullParseServicer {
    
    	public static List<News> readXml(InputStream inStream) throws Throwable {
    		boolean flag = false;
    		List<News> resultNews = null;
    		/** 实例化XmlPullParser */
    		XmlPullParser parser = Xml.newPullParser();
    		/** 配置Xml输入流及文本格式 */
    		parser.setInput(inStream, "UTF-8");
    		News news = null;
    		/** 获取事件类型 */
    		int eventCode = parser.getEventType();
    		/** 事件类型不为XML文本结束事件时始终读取文件 */
    		while (eventCode != XmlPullParser.END_DOCUMENT) {
    			switch (eventCode) {
    			case XmlPullParser.START_DOCUMENT:
    				resultNews = new ArrayList<News>();
    				break;
    			case XmlPullParser.START_TAG:
    				if ("item".equals(parser.getName())) {
    					flag = true;
    					news = new News();
    				}
    				if (flag) {
    					if ("title".equals(parser.getName())) {
    						news.setTitle(parser.nextText());
    					} else if ("link".equals(parser.getName())) {
    						news.setLink(parser.nextText());
    					} else if ("pubDate".equals(parser.getName())) {
    						news.setPubDate(parser.nextText());
    					} else if ("description".equals(parser.getName())) {
    						news.setContent(parser.nextText());
    					}
    				}
    				break;
    			case XmlPullParser.END_TAG:
    				if ("item".equals(parser.getName())) {
    					flag = false;
    					resultNews.add(news);
    					news = null;
    				}
    				break;
    			default:
    				break;
    			}
    			eventCode = parser.next();
    		}
    		return resultNews;
    	}
    }
    获取InputStream的工具类  NetTool.java: 
  • package com.Liam.servicers;
    
    import java.io.InputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    public class NetTool {
    
    	public static InputStream getStream(String urlPath, String encodin) throws Exception {
    		URL url = new URL(urlPath);
    		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    		conn.setRequestMethod("GET");
    		conn.setConnectTimeout(6*1000);
    		if(conn.getResponseCode() == 200) {
    			InputStream stream = conn.getInputStream();
    			return stream;
    		} else {
    			return null;
    		}
    	}
    }
    主界面的Activity: 
  • package com.Liam.rssreader;
    
    import java.io.InputStream;
    import java.util.List;
    
    import com.Liam.beans.News;
    import com.Liam.servicers.NetTool;
    import com.Liam.servicers.PullParseServicer;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    import android.widget.Toast;
    
    public class RssShowActivity extends Activity {
    	private ListView listView;
    	private String rssPath = "http://rss.sina.com.cn/roll/edu/hot_roll.xml";
    	//http://rss.sina.com.cn/sports/global/focus.xml
    	//http://rss.sina.com.cn/roll/edu/hot_roll.xml
    	//http://www.oschina.net/news/rss
    	private String[] newsTitles;
    	private int count = 0;
    	private List<News> newsList;
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_rss_show);
    		listView = (ListView) findViewById(R.id.newsList);
    		
    		try {
    			InputStream stream = NetTool.getStream(rssPath, "UTF-8");
    			newsList = PullParseServicer.readXml(stream);
    		} catch (Throwable e) {
    			Log.i("XmlParser", "Xml文件获取或读取错误!");
    			e.printStackTrace();
    		}
    		newsTitles = new String[newsList.size()];
    		for(News n:newsList) {
    			newsTitles[count] = n.getTitle().trim();
    			count ++;
    		}
    		
    		listView.setAdapter(new ArrayAdapter<String>(RssShowActivity.this,
    			android.R.layout.simple_list_item_1, newsTitles));
    		
    		listView.setOnItemClickListener(new OnItemClickListener() {
    			@Override
    			public void onItemClick(AdapterView<?> parent, View view, int position,
    					long id) {
    				News demo = newsList.get(position);
    				Intent intent = new Intent(RssShowActivity.this, DetailsActivity.class);
    				intent.putExtra("title", demo.getTitle());
    				intent.putExtra("pubDate", demo.getPubDate());
    				intent.putExtra("content", demo.getContent());
    				intent.putExtra("link", demo.getLink());
    				startActivity(intent);
    			}
    		});
    	}
    	
    	public void show(String str) {
    		Toast.makeText(RssShowActivity.this, str, Toast.LENGTH_LONG).show();
    	}
    
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		menu.add(0, 1, 0, "退出");
    		getMenuInflater().inflate(R.menu.rss_show, menu);
    		return true;
    	}
    
    	@Override
    	public boolean onOptionsItemSelected(MenuItem item) {
    		switch (item.getItemId()) {
    		case 1: {
    			new AlertDialog.Builder(RssShowActivity.this)
    					.setTitle("提示")
    					.setMessage("是否确认退出程序?")
    					.setCancelable(false)
    					.setPositiveButton("确定",
    							new DialogInterface.OnClickListener() {
    								@Override
    								public void onClick(DialogInterface dialog,
    										int which) {
    									RssShowActivity.this.finish();
    								}
    							})
    					.setNegativeButton("取消",
    							new DialogInterface.OnClickListener() {
    								@Override
    								public void onClick(DialogInterface dialog,
    										int which) {
    									dialog.cancel();
    								}
    							}).show();
    			break;
    		}
    		}
    		return super.onOptionsItemSelected(item);
    	}
    
    }
    第二页面的Activity: 
  • package com.Liam.rssreader;
    
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class DetailsActivity extends Activity {
    	private TextView title, content, pubDate, link;
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.detailshow);
    		
    		title = (TextView) findViewById(R.id.title);
    		pubDate = (TextView) findViewById(R.id.date);
    		content = (TextView) findViewById(R.id.content);
    		link = (TextView) findViewById(R.id.link);
    		
    		Intent intent = getIntent();
    		String titleVal = intent.getStringExtra("title");
    		String dateVal = intent.getStringExtra("pubDate");
    		String contentVal = intent.getStringExtra("content");
    		String linkVal = intent.getStringExtra("link");
    		
    		title.setText(formatStr(titleVal));
    		pubDate.setText(dateVal);
    		content.setText(formatStr(contentVal));
    		link.setText(linkVal);
    
    	}
    	
    	public String formatStr(String str) {
    		Pattern p = Pattern.compile("\\s*|\t|\r|\n");
    		Matcher m = p.matcher(str);
    		return str;
    	}
    }
    代码如上,敬候大神指导!

        




加载中
0
kenping
kenping
你的代码有两个严重问题:
1、在UI线程里面进行了网络访问,这个在Android新版本里面是直接被禁止的
2、因为上面的错误,导致网络失败,因此你的RssShowActivity第48行代码newsTitles = new String[newsList.size()];这里newsList是一个空指针,然后你懂的
kenping
kenping
补充一下android.os.NetworkOnMainThreadException是从Android 3.0开始的
Java_Liam
Java_Liam
原来如此,谢谢大神!
0
Java_Liam
Java_Liam

引用来自“kenping”的答案

你的代码有两个严重问题:
1、在UI线程里面进行了网络访问,这个在Android新版本里面是直接被禁止的
2、因为上面的错误,导致网络失败,因此你的RssShowActivity第48行代码newsTitles = new String[newsList.size()];这里newsList是一个空指针,然后你懂的
回复 @kenping : 大神,我在代码里加了

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());

StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects().detectLeakedClosableObjects()

.penaltyLog().penaltyDeath().build());
后在4.0以及4.1.2的模拟器上能运行,但是在我的HTC G14 android4.0.4上停止工作,求解释!
Java_Liam
Java_Liam
回复 @步行者传说 : 正在看怎么查看真机日志
步行者传说
步行者传说
貼crash log看看啊
0
深圳_小白菜
深圳_小白菜
你配置权限没有???
0
Java_Liam
Java_Liam

引用来自“深圳_许杰”的答案

你配置权限没有???

    <uses-permission android:name="android.permission.INTERNET" />

这个算吗?

0
kenping
kenping
第二个问题解决没?模拟器用的是电脑自身的网络环境,真机是不是无线不给力导致网络访问失败,然后~
0
Java_Liam
Java_Liam

引用来自“kenping”的答案

第二个问题解决没?模拟器用的是电脑自身的网络环境,真机是不是无线不给力导致网络访问失败,然后~
真机是一打开就停止工作,还有我准备看看真机的日志,然后网上说什么*#*#2846579#*#*根本输不进去,看不到日志。网络状况很好
0
深圳_小白菜
深圳_小白菜
这个是上网的权限
Java_Liam
Java_Liam
我换了个方式,另起线程,已经成功了,谢谢大神!只是很奇怪那个StrictMode方法在我的HTC G14上不行
返回顶部
顶部