这个问题出现在一次视频开发中。本人将先前开发过的一套完整Android代码复制到一个新的工程目录,将其中有关摄像机认证连接的代码做了整体替换之后重新编译并通过。但是在启动程序后从一个界面调转到另一个界面的时候出现崩溃,JVM抛出runtime异常,日志显示找不到加载类。
新建一个Android程序时,通常程序会带有一个状态栏。如果想要去除状态栏的话只需要在AndroidMainFest中设置相关的Application属性即可:
<application android:allowBackup="true" android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" > <activity android:name="iton.lifecute.activity.SplashScreen" android:configChanges="orientation|keyboardHidden" android:label="@string/app_name" android:screenOrientation="landscape" android:windowSoftInputMode="stateHidden" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
android:theme="@android:style/Theme.NoTitleBar" 表示程序的主题为无状态栏并且是对整个应用程序而言,如果只想为某个Activity设置为无状态栏只需要将改属性添加到对应的Activity声明中。需要说明的是Android系统自带的状态栏还是会显示的,如果需要的话可以将程序设置为全屏,只需要在改属性后加上
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"即可。有时候我们在用eclipse导入一个现有的Android工程时会出现中文字符乱码的现象,这个是因为你选择的workspace的编码方式与你已经存在的工程的编码方式不同,中文就会出现乱码从而可能引发程序报错。我们需要在eclipse中设置相应的编码方式即可。
class ListDeviceAdapter extends BaseAdapter { ChildListView childlist = null; private Context mContext; private List<Map<String, Object>> mDeviceData; // 设备信息集合 public ListDeviceAdapter(Context context, List<Map<String, Object>> listItems) { this.mContext = context; this.mDeviceData = listItems; System.out.println("-- ListDeviceAdapter is running...--"); } @Override public int getCount() { return 0;//return mDeviceData.size();//首先回调getCount()方法,根据其值来决定是否回调getView() } @Override public Object getItem(int position) { return mDeviceData.get(position); } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { System.out.println("-- getView is running...--"); if (convertView == null) { System.out.println("-- list is running...--"); childlist = new ChildListView(); convertView = LayoutInflater.from(mContext).inflate(R.layout.listview_control, null); childlist.mDeviceType = (ImageButton) convertView.findViewById(R.id.list_btn_device_type); childlist.mDeviceName = (TextView) convertView.findViewById(R.id.list_text_device_name); childlist.mDeviceControl = (ImageButton) convertView.findViewById(R.id.list_btn_device_type); convertView.setTag(childlist); } else { childlist = (ChildListView) convertView.getTag(); } childlist.mDeviceType.setBackgroundResource(R.drawable.device_light); childlist.mDeviceName.setText(mDeviceData.get(0).get("title").toString()); childlist.mDeviceControl.setBackgroundResource(R.drawable.device_curtain); childlist.mDeviceType.setOnClickListener(new OnClickListener() { public void onClick(View v) { } }); childlist.mDeviceControl.setOnClickListener(new OnClickListener() { public void onClick(View v) { } }); return convertView; } class ChildListView { ImageButton mDeviceType; TextView mDeviceName; ImageButton mDeviceControl; } }经过反复检查发现自定义Adapter先是回调的getCount()方法,起初返回的是空,Adapter判断其返回值来决定是否回调getView方法。问题就在这里,简单修改其返回值,即返回传人的List数据大小,问题得到解决。
4. android.view.InflateException: ........Caused by: java.lang.StackOverflowError
11-09 15:46:04.410: E/AndroidRuntime(16591): FATAL EXCEPTION: main 11-09 15:46:04.410: E/AndroidRuntime(16591): java.lang.RuntimeException: Unable to start activity ComponentInfo{iton.lifecube/iton.lifecube.activity.MainActivity}: android.view.InflateException: Binary XML file line #38: Error inflating class <unknown> 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.app.ActivityThread.access$600(ActivityThread.java:130) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.os.Handler.dispatchMessage(Handler.java:99) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.os.Looper.loop(Looper.java:137) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.app.ActivityThread.main(ActivityThread.java:4745) 11-09 15:46:04.410: E/AndroidRuntime(16591): at java.lang.reflect.Method.invokeNative(Native Method) 11-09 15:46:04.410: E/AndroidRuntime(16591): at java.lang.reflect.Method.invoke(Method.java:511) 11-09 15:46:04.410: E/AndroidRuntime(16591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 11-09 15:46:04.410: E/AndroidRuntime(16591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 11-09 15:46:04.410: E/AndroidRuntime(16591): at dalvik.system.NativeStart.main(Native Method) 11-09 15:46:04.410: E/AndroidRuntime(16591): Caused by: android.view.InflateException: Binary XML file line #38: Error inflating class <unknown> 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.view.LayoutInflater.createView(LayoutInflater.java:613) 11-09 15:46:04.410: E/AndroidRuntime(16591): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 11-09 15:46:04.410: E/AndroidRuntime(16591): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.app.Activity.setContentView(Activity.java:1867) 11-09 15:46:04.410: E/AndroidRuntime(16591): at iton.lifecube.activity.MainActivity.onCreate(MainActivity.java:78) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.app.Activity.performCreate(Activity.java:5008) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 11-09 15:46:04.410: E/AndroidRuntime(16591): ... 11 more 11-09 15:46:04.410: E/AndroidRuntime(16591): Caused by: java.lang.reflect.InvocationTargetException 11-09 15:46:04.410: E/AndroidRuntime(16591): at java.lang.reflect.Constructor.constructNative(Native Method) 11-09 15:46:04.410: E/AndroidRuntime(16591): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.view.LayoutInflater.createView(LayoutInflater.java:587) 11-09 15:46:04.410: E/AndroidRuntime(16591): ... 26 more 11-09 15:46:04.410: E/AndroidRuntime(16591): Caused by: java.lang.StackOverflowError 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.graphics.Bitmap.getScaledWidth(Bitmap.java:833) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.graphics.drawable.BitmapDrawable.computeBitmapSize(BitmapDrawable.java:179) 11-09 15:46:04.410: E/AndroidRuntime(16591): at android.graphics.drawable.BitmapDrawable.setBitmap(BitmapDrawable.java:187)