跳转到一个空的activity没问题, 但是跳转到下面这个会出错,程序退出
package com.example.energysavingofmobilephone;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.telephony.TelephonyManager;
import android.text.format.Formatter;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
public class SysInformation extends Activity {
private ScrollView mScrollView;
private LinearLayout mLinearLayout;
private TextView txt, txt2, txt3;
private String batteryLevel = null;
private String getAvailMemory() {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo mi = new MemoryInfo();
am.getMemoryInfo(mi);
return Formatter.formatFileSize(getBaseContext(), mi.availMem);
}
private String getTotalMemory() {
String str1 = "/proc/meminfo";
String str2;
String[] arrayOfString;
long initial_memory = 0;
try {
FileReader localFileReader = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader(
localFileReader, 8192);
str2 = localBufferedReader.readLine();
arrayOfString = str2.split("\\s+");
for (String num : arrayOfString) {
Log.i(str2, num + "\t");
initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;
localBufferedReader.close();
}
} catch (IOException e) {
}
return Formatter.formatFileSize(getBaseContext(), initial_memory);
}
private String readCpuInfo() {
String result = "";
ProcessBuilder cmd;
try {
String[] args = { "system/bin/cat", "proc/cpuinfo" };
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while (in.read(re) != -1) {
System.out.println(new String(re));
result = result + new String(re);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sysinfo);
this.setTitle("获取设备信息");
registerReceiver(batteryChangedReceiver, new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));
mScrollView = (ScrollView) findViewById(R.id.scrollView);
mLinearLayout = (LinearLayout) findViewById(R.id.layout);
// 判断是否存在SD卡
txt = (TextView) findViewById(R.id.text);
txt2 = (TextView) findViewById(R.id.system_memory);
txt3 = (TextView) findViewById(R.id.cpuinfo);
txt.setTextColor(Color.GREEN);
setDeviceInfo();
System.out.println("all sdcard path===" + showAllSDCardPath());
/*
* txt2.setText("系统总内存:"+this.getTotalMemory()+"\n可用内存:"+this.getAvailMemory
* ()); txt3.setText(readCpuInfo());
*/
/*
* if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED
* )){ File path = Environment.getExternalStorageDirectory(); //StatFs
* statfs = new StatFs(path.getPath()); }
*/
}
private void setDeviceInfo(){
File sdDir = null;
boolean sdCardExist = Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED);
if (sdCardExist) {
sdDir = Environment.getExternalStorageDirectory();
}
String sdPath = sdDir.toString();
// Log.e("lhl", "===="+sdPath);
// 获取屏幕分辨率
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
TelephonyManager tm = (TelephonyManager) this
.getSystemService(TELEPHONY_SERVICE);
txt.setText("设备屏幕分辨率:" + metrics.widthPixels + "*"
+ metrics.heightPixels + "\n外置SD卡路径:" + sdPath + showSDCardSize()
+ "\n\n设备型号:" + android.os.Build.MODEL + "\nAPI Level:"
+ android.os.Build.VERSION.SDK + "\n系统版本号:"
+ android.os.Build.VERSION.RELEASE + "\n设备 ID:"
+ tm.getDeviceId() + "\n手机号:" + tm.getLine1Number()
+ "\n软件版本号:" + tm.getDeviceSoftwareVersion() + "\n 内核版本: "
+ getKernalVersion() + "\n 基带版本:" + getBaseBand() + "\n电池电量:"
+ batteryLevel + "\n服务商名称:" + tm.getNetworkOperatorName()
+"\n当前Wifi状态:"+(wifiManager.isWifiEnabled()?"可用":"不可用")
+getUSBDebugStatue()
+getInstallNonMarketAPPStatue()
+"\n语言国家:"+Locale.getDefault().getLanguage()+"-"+Locale.getDefault().getCountry()
+"\n时期和时间:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime())
+"\n是否漫游:"+(tm.isNetworkRoaming()?"是":"否")
+ "\n国际长途区号:"+ tm.getNetworkCountryIso()
/*
* SIM_STATE_UNKNOWN 未知状态 0 SIM_STATE_ABSENT 没插卡 1
* SIM_STATE_PIN_REQUIRED 锁定状态,需要用户的PIN码解锁 2
* SIM_STATE_PUK_REQUIRED 锁定状态,需要用户的PUK码解锁 3
* SIM_STATE_NETWORK_LOCKED 锁定状态,需要网络的PIN码解锁 4 SIM_STATE_READY
* 就绪状态 5
*/
+ "\nSIM状态信息:" + tm.getSimState() + "\n系统总内存:"
+ this.getTotalMemory() + "\n可用内存:" + this.getAvailMemory()
+ "\n" + readCpuInfo());
}
private String getInstallNonMarketAPPStatue(){
try {
return "\n未知来源应用程序安装开启: " + ((Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS) == 0 )?"否":"是");
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
private String getUSBDebugStatue(){
try {
return "\nUSB调试是否开启: " + ((Settings.Secure.getInt(getContentResolver(), Settings.Secure.ADB_ENABLED) == 0 )?"否":"是");
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
private String getKernalVersion() {
String FILENAME_PROC_VERSION = "/proc/version";
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(FILENAME_PROC_VERSION),
256);
return reader.readLine();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (null != reader) {
reader.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
reader = null;
}
}
return null;
}
private String getBaseBand() {
try {
Class cl = Class.forName("android.os.SystemProperties");
Object invoker = cl.newInstance();
Method m = cl.getMethod("get", new Class[] { String.class,
String.class });
Object result = m.invoke(invoker, new Object[] {
"gsm.version.baseband", "no message" });
return (String) result;
} catch (Exception e) {
}
return null;
}
private String showAllSDCardPath() {
String mount = new String();
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if (line.contains("secure"))
continue;
if (line.contains("asec"))
continue;
if (line.contains("fat")) {
String columns[] = line.split(" ");
System.out.println("line2====" + line);
if (columns != null && columns.length > 1) {
mount = mount.concat(columns[1] + " ");
}
} else if (line.contains("fuse")) {
String columns[] = line.split(" ");
System.out.println("line====" + line);
if (columns != null && columns.length > 1) {
mount = mount.concat(columns[1] + " ");
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return mount;
}
private String showSDCardSize() {
File sdcard = Environment.getExternalStorageDirectory();
/**
* 我们可以通过StatFs访问文件系统的空间容量等信息
*/
StatFs statFs = new StatFs(sdcard.getPath());
/**
* statFs.getBlockSize可以获取当前的文件系统中,一个block所占有的字节数
*/
long blockSize = statFs.getBlockSize();
/**
* statFs.getAvaliableBlocks方法可以返回尚未使用的block的数量
*/
long avaliableBlocks = statFs.getAvailableBlocks();
/**
* statFs.getBlockCount可以获取总的block数量
*/
long totalBlocks = statFs.getBlockCount();
String result = "";
result += "\n 总空间大小:" + totalBlocks * blockSize / 1024 / 1024 + "M";
result += "\n 尚未被使用的空间大小:" + avaliableBlocks * blockSize / 1024 / 1024
+ "M";
return result;
}
private String showInternalSDCardSize() {
File sdcard = Environment.getExternalStorageDirectory();
/**
* 我们可以通过StatFs访问文件系统的空间容量等信息
*/
StatFs statFs = new StatFs(sdcard.getPath());
/**
* statFs.getBlockSize可以获取当前的文件系统中,一个block所占有的字节数
*/
long blockSize = statFs.getBlockSize();
/**
* statFs.getAvaliableBlocks方法可以返回尚未使用的block的数量
*/
long avaliableBlocks = statFs.getAvailableBlocks();
/**
* statFs.getBlockCount可以获取总的block数量
*/
long totalBlocks = statFs.getBlockCount();
String result = "";
result += "\n 总空间大小:" + totalBlocks * blockSize / 1024 / 1024 + "M";
result += "\n 尚未被使用的空间大小:" + avaliableBlocks * blockSize / 1024 / 1024
+ "M";
return result;
}
请问里面有什么问题么?应该怎么改
9 个解决方案
#1
测试了下发现直接用button来intent到新activity也出错,那应该是跳转后的activity的问题么?
#2
// 接受广播 电池电量监听
private BroadcastReceiver batteryChangedReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
int level = intent.getIntExtra("level", 0);
int scale = intent.getIntExtra("scale", 100);
batteryLevel = (level * 100 / scale) + "%";
setDeviceInfo();
}
}
};
#3
你的Activity没有注册吧
#4
第一,你看这个activity在AndroidManifest.xml里面注册没有;
第二,把报错的log贴出来看下哈
第二,把报错的log贴出来看下哈
#5
注册了的,后来发现是
虚拟机运行这个会出错。注销了这几行就没问题了。但是单独运行,直接打开这个activity,不用intent跳转到这个activity就没问题。这是为什么
+ "\n设备 ID:"+ tm.getDeviceId()/
+ "\n手机号:" + tm.getLine1Number()
+ "\n软件版本号:" + tm.getDeviceSoftwareVersion()
虚拟机运行这个会出错。注销了这几行就没问题了。但是单独运行,直接打开这个activity,不用intent跳转到这个activity就没问题。这是为什么
#6
03-04 04:53:00.447: E/AndroidRuntime(1759): FATAL EXCEPTION: main
03-04 04:53:00.447: E/AndroidRuntime(1759): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.energysavingofmobilephone/com.example.energysavingofmobilephone.SysInformation}: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10047 nor current process has android.permission.READ_PHONE_STATE.
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Looper.loop(Looper.java:137)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-04 04:53:00.447: E/AndroidRuntime(1759): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 04:53:00.447: E/AndroidRuntime(1759): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-04 04:53:00.447: E/AndroidRuntime(1759): at dalvik.system.NativeStart.main(Native Method)
03-04 04:53:00.447: E/AndroidRuntime(1759): Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10047 nor current process has android.permission.READ_PHONE_STATE.
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Parcel.readException(Parcel.java:1425)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Parcel.readException(Parcel.java:1379)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getDeviceSvn(IPhoneSubInfo.java:203)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.telephony.TelephonyManager.getDeviceSoftwareVersion(TelephonyManager.java:187)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.example.energysavingofmobilephone.SysInformation.setDeviceInfo(SysInformation.java:153)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.example.energysavingofmobilephone.SysInformation.onCreate(SysInformation.java:112)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.Activity.performCreate(Activity.java:5104)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-04 04:53:00.447: E/AndroidRuntime(1759): ... 11 more
03-04 04:53:44.937: I/Process(1759): Sending signal. PID: 1759 SIG: 9
03-04 04:53:00.447: E/AndroidRuntime(1759): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.energysavingofmobilephone/com.example.energysavingofmobilephone.SysInformation}: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10047 nor current process has android.permission.READ_PHONE_STATE.
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Looper.loop(Looper.java:137)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-04 04:53:00.447: E/AndroidRuntime(1759): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 04:53:00.447: E/AndroidRuntime(1759): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-04 04:53:00.447: E/AndroidRuntime(1759): at dalvik.system.NativeStart.main(Native Method)
03-04 04:53:00.447: E/AndroidRuntime(1759): Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10047 nor current process has android.permission.READ_PHONE_STATE.
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Parcel.readException(Parcel.java:1425)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Parcel.readException(Parcel.java:1379)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getDeviceSvn(IPhoneSubInfo.java:203)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.telephony.TelephonyManager.getDeviceSoftwareVersion(TelephonyManager.java:187)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.example.energysavingofmobilephone.SysInformation.setDeviceInfo(SysInformation.java:153)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.example.energysavingofmobilephone.SysInformation.onCreate(SysInformation.java:112)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.Activity.performCreate(Activity.java:5104)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-04 04:53:00.447: E/AndroidRuntime(1759): ... 11 more
03-04 04:53:44.937: I/Process(1759): Sending signal. PID: 1759 SIG: 9
#7
需要添加权限吧, Requires READ_PHONE_STATE
#8
同意楼上,发生错误,请先看错误提示 里面都写的很清楚
#9
原来是这个问题,错误提示不知道哪条是重点。在学着看。谢谢各位的帮助!
#1
测试了下发现直接用button来intent到新activity也出错,那应该是跳转后的activity的问题么?
#2
// 接受广播 电池电量监听
private BroadcastReceiver batteryChangedReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
int level = intent.getIntExtra("level", 0);
int scale = intent.getIntExtra("scale", 100);
batteryLevel = (level * 100 / scale) + "%";
setDeviceInfo();
}
}
};
#3
你的Activity没有注册吧
#4
第一,你看这个activity在AndroidManifest.xml里面注册没有;
第二,把报错的log贴出来看下哈
第二,把报错的log贴出来看下哈
#5
注册了的,后来发现是
虚拟机运行这个会出错。注销了这几行就没问题了。但是单独运行,直接打开这个activity,不用intent跳转到这个activity就没问题。这是为什么
+ "\n设备 ID:"+ tm.getDeviceId()/
+ "\n手机号:" + tm.getLine1Number()
+ "\n软件版本号:" + tm.getDeviceSoftwareVersion()
虚拟机运行这个会出错。注销了这几行就没问题了。但是单独运行,直接打开这个activity,不用intent跳转到这个activity就没问题。这是为什么
#6
03-04 04:53:00.447: E/AndroidRuntime(1759): FATAL EXCEPTION: main
03-04 04:53:00.447: E/AndroidRuntime(1759): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.energysavingofmobilephone/com.example.energysavingofmobilephone.SysInformation}: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10047 nor current process has android.permission.READ_PHONE_STATE.
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Looper.loop(Looper.java:137)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-04 04:53:00.447: E/AndroidRuntime(1759): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 04:53:00.447: E/AndroidRuntime(1759): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-04 04:53:00.447: E/AndroidRuntime(1759): at dalvik.system.NativeStart.main(Native Method)
03-04 04:53:00.447: E/AndroidRuntime(1759): Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10047 nor current process has android.permission.READ_PHONE_STATE.
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Parcel.readException(Parcel.java:1425)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Parcel.readException(Parcel.java:1379)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getDeviceSvn(IPhoneSubInfo.java:203)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.telephony.TelephonyManager.getDeviceSoftwareVersion(TelephonyManager.java:187)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.example.energysavingofmobilephone.SysInformation.setDeviceInfo(SysInformation.java:153)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.example.energysavingofmobilephone.SysInformation.onCreate(SysInformation.java:112)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.Activity.performCreate(Activity.java:5104)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-04 04:53:00.447: E/AndroidRuntime(1759): ... 11 more
03-04 04:53:44.937: I/Process(1759): Sending signal. PID: 1759 SIG: 9
03-04 04:53:00.447: E/AndroidRuntime(1759): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.energysavingofmobilephone/com.example.energysavingofmobilephone.SysInformation}: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10047 nor current process has android.permission.READ_PHONE_STATE.
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Looper.loop(Looper.java:137)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-04 04:53:00.447: E/AndroidRuntime(1759): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 04:53:00.447: E/AndroidRuntime(1759): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-04 04:53:00.447: E/AndroidRuntime(1759): at dalvik.system.NativeStart.main(Native Method)
03-04 04:53:00.447: E/AndroidRuntime(1759): Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10047 nor current process has android.permission.READ_PHONE_STATE.
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Parcel.readException(Parcel.java:1425)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.os.Parcel.readException(Parcel.java:1379)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getDeviceSvn(IPhoneSubInfo.java:203)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.telephony.TelephonyManager.getDeviceSoftwareVersion(TelephonyManager.java:187)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.example.energysavingofmobilephone.SysInformation.setDeviceInfo(SysInformation.java:153)
03-04 04:53:00.447: E/AndroidRuntime(1759): at com.example.energysavingofmobilephone.SysInformation.onCreate(SysInformation.java:112)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.Activity.performCreate(Activity.java:5104)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-04 04:53:00.447: E/AndroidRuntime(1759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-04 04:53:00.447: E/AndroidRuntime(1759): ... 11 more
03-04 04:53:44.937: I/Process(1759): Sending signal. PID: 1759 SIG: 9
#7
需要添加权限吧, Requires READ_PHONE_STATE
#8
同意楼上,发生错误,请先看错误提示 里面都写的很清楚
#9
原来是这个问题,错误提示不知道哪条是重点。在学着看。谢谢各位的帮助!