Android中遇到的需求与解决方案二

来源:互联网 发布:阿里巴巴在线编程测验 编辑:程序博客网 时间:2024/06/06 00:38

1.需求:Eclipse开启同一参数或同一函数在其中一个引用的地方被选中,其余的也会自动高亮醒目。


解决方案:eclipse里,选择windows-> preferences-> java-> Editor-> Mark Occurences ,全部都勾选。


2.需求:Arcgis for android中,设置地图最大最小放级别。

经常地图加载之后,不想让用户使用到指定的缩放级别以外的图层。然后通常是去设置地图Scale的最大最小值。往往发现不管用。尝试着更改成设置地图的最大最小Resolution值,似乎就可以了。


设置了最大最小的Resolution后,地图初始化的显示级别,似乎变成了最小的resolution的级别。

接着,如何获取地图当前的Resolution呢:

mapView.getResolution()

3.需求:JsonArray数据中出现Null的子项。如何过滤?

例如:[Null,{"name":"赵小亮" , "age":22 , "male":false}],如果直接for如何取出JsonObject这会报错。

解决方案:

ylArray = new JSONArray(ylDistribution);for (int i = 0; i < ylArray.length(); i++) {  if (ylArray.isNull(i)) {Log.e("图层加载", "该json数据为Null");  }

4.需求:BitmapFactory.decodeFile()加载图片报异常

01-21 11:13:16.283: W/OpenGLRenderer(5174): Bitmap too large to be uploaded into a texture

这个异常还比较奇葩,并不是Error而是warn。


网络上说是因为当开启硬件加速的时候,GPU对于openglRender 有一个限制,这个不同的手机会有不同的限制。就是硬件加速的时候,对图片的大小有限制。不同设备可能有不同的最大值。这个问题悲催的地方是,程序貌似没有捕获到这个exception, 结果是程序也不报错,图片也显示不出来。

解决方案:

禁用掉设备的硬件加速功能:

<application android:hardwareAccelerated="false" ...>

5.需求:需要比较两个List是否相等。

/** * 比较两个list的相同与否 *  * @param bt1 * @param bt2 * @author vaecer * @return boolean */private boolean judgeEqual(ArrayList<String> bt1, ArrayList<String> bt2) {int length = bt1.size();boolean b = true;for (int i = 0; i < length; i++) {if (bt1.get(i) != bt2.get(i)) {b = false;}}return b;}

6.需求:EditView中的属性inputType有哪些取值。

    android:inputType="none"//输入普通字符    android:inputType="text"//输入普通字符    android:inputType="textCapCharacters"//输入普通字符    android:inputType="textCapWords"//单词首字母大小    android:inputType="textCapSentences"//仅第一个字母大小    android:inputType="textAutoCorrect"//前两个自动完成    android:inputType="textAutoComplete"//前两个自动完成    android:inputType="textMultiLine"//多行输入    android:inputType="textImeMultiLine"//输入法多行(不一定支持)    android:inputType="textNoSuggestions"//不提示    android:inputType="textUri"//URI格式    android:inputType="textEmailAddress"//电子邮件地址格式    android:inputType="textEmailSubject"//邮件主题格式    android:inputType="textShortMessage"//短消息格式    android:inputType="textLongMessage"//长消息格式    android:inputType="textPersonName"//人名格式    android:inputType="textPostalAddress"//邮政格式    android:inputType="textPassword"//密码格式    android:inputType="textVisiblePassword"//密码可见格式    android:inputType="textWebEditText"//作为网页表单的文本格式    android:inputType="textFilter"//文本筛选格式    android:inputType="textPhonetic"//拼音输入格式    android:inputType="number"//数字格式    android:inputType="numberSigned"//有符号数字格式    android:inputType="numberDecimal"//可以带小数点的浮点格式    android:inputType="phone"//拨号键盘    android:inputType="datetime"//日期+时间格式    android:inputType="date"//日期键盘    android:inputType="time"//时间键盘


7.eclipse加载指定的jdk(不是环境变量设置的默认JDK)

修改Eclipse中的eeclipse.ini配置文件,在里面的-vmargs参数之前添加上
-vmC:\Program Files\Java\jdk1.8.0_31\bin

这样就摆脱了环境变量中的默认JDK了,就可以多个Eclipse加载不同版本的JDK。

8.Eclipse Java EE透视图下看不见Referenced Libraries解决办法


其实这是Project Explorer与Package Explorer的区别,在Package Explorer窗口中会出现Referenced Libraries,但Java EE 透视图中默认左边只有Project Explorer窗口。因此只要打开Package Explorer窗口即可,打开方法:菜单Window->Show View->Other->Java->Package Explorer,如果Package Explorer窗口中仍不见Referenced Libraries目录,则可以点击Package Explorer窗口右上角的倒三角箭头,在弹出的菜单中选择“Show 'Referenced Libraries' Node.” 。

9.BitMap如何关联到Dreable中的一个图片文件的方法。

需求:
       经常会忘记代码的操作细节,唉~~!需求如题。
解决方案:
      
 Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.cover);//link the drable image

10.去除Activity的标题栏

需求:
         去除Activity上的标题栏。
解决方案:
 1.在配置文件中的该Activity中设置:
android:theme="@android:style/Theme.NoTitleBar"

2.在Oncreat中关联布局文件之前设置:
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.home_activity);}

11.获取手机设备的状态栏的高度像素多少

需求:
对手机的状态栏占了多少像素值,需要获取到这个具体数值。
解决方案:
直接跑代码获取到数值即可:
public static int getStatusHeight(Activity activity) {int statusHeight = 0;Rect localRect = new Rect();activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);statusHeight = localRect.top;if (0 == statusHeight) {Class<?> localClass;try {localClass = Class.forName("com.android.internal.R$dimen");Object localObject = localClass.newInstance();int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString());statusHeight = activity.getResources().getDimensionPixelSize(i5);} catch (ClassNotFoundException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (InstantiationException e) {e.printStackTrace();} catch (NumberFormatException e) {e.printStackTrace();} catch (IllegalArgumentException e) {e.printStackTrace();} catch (SecurityException e) {e.printStackTrace();} catch (NoSuchFieldException e) {e.printStackTrace();}}return statusHeight;}

12.android switch语句报case expressions must be constant expressions

private OnClickListener taskClickListener = new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch (v.getId()) {case R.id.get_voices:CommonHelper.Msg.sendMsg(handler,Constants.MsgWhat.GO_CASE_FILE_CHOICE_ACTIVITY,Constants.CaseCommon.take_tape);break;case R.id.get_picture:CommonHelper.Msg.sendMsg(handler,Constants.MsgWhat.GO_CASE_FILE_CHOICE_ACTIVITY,Constants.CaseCommon.take_pic);break;case R.id.submit:handler.sendMessage(handler.obtainMessage(Constants.CaseCreate.upload));break;default:break;}}};

项目代码里面报了  case R.id.get_voices :  出现了错误

错误提示为:case expressions must be constant expressions

发现是在Build Path --Android的SDK选择中  勾选了isLibrary  的原因


将Is Library的勾去掉,OK下后回到项目Clear一下。


13.android Unable to resolve target 'android-XX'错误的解决方法

当用eclipse 导入一个已经存在的项目时,经常会遇见:
Unable to resolve target 'android-XX' 类似的错误。
这是因为导入的项目代码中project.properties 的 Project target 设置与当前eclipse环境设置不一致所致。
解决办法:
打开项目代码中的Project target,将
# Project target.  target=android-7
修改为你当前支持的ADK版本即可。
# Project target.target=android-19

14.应用程序报错Installation error:INSTALL_FAILED_VERSION_DOWNGRADE

[2016-08-31 15:53:13 - FzkcyDrainGCS] Installation error: INSTALL_FAILED_VERSION_DOWNGRADE[2016-08-31 15:53:13 - FzkcyDrainGCS] Please check logcat output for more details.[2016-08-31 15:53:13 - FzkcyDrainGCS] Launch canceled![2016-08-31 15:57:43 - FzkcyDrainGCS] Error in an XML file: aborting build.

这是因为手机中安装的GCS的app的版本号比这个要安装的高。更改AndroidManifest.xml->VersionCode 的值。

15.adb.exe服务无法启动

  [2012-07-18 16:18:26 - ] The connection to adb is down, and a severe error has occured.    [2012-07-18 16:18:26 - ] You must restart adb and Eclipse.    [2012-07-18 16:18:26 - ] Please ensure that adb is correctly located at 'D:\adt-bundle-windows-x86_64-20130219\sdk\platform-tools\adb.exe' and can be executed.

ADB是一个 客户端-服务器端 程序, 其中客户端是你用来操作的电脑, 服务器端是android设备.

当你启动一个adb客户端,客户端首先确认是否已有一个adb服务进程在运行。如果没有,则启动服务进程。当服务器运行, adb服务器就会绑定本地的TCP端口5037并监听adb客户端发来的命令,—所有的adb客户端都是用端口 5037与adb服务器对话的.

解决:

5037为adb默认端口 查看该端口情况如下:

       netstat -aon|findstr "5037"

      TCP    127.0.0.1:5037         0.0.0.0:0              LISTENING       6540

发现6540占用了 5037端口,继续查看6540的task,发现是wandoujia  .如下所示

        tasklist|findstr "6540"

        wandoujia_daemon.exe          6540 Console                    1      4,276 K

接下来问题就好解决了,在任务管理器kill掉wandoujia_daemon.exe  .




0 0
原创粉丝点击