ANDROID 开发中的错误

error: No resource identifier found for attribute ‘targetSdkVersion’ in package ‘android’
– error: No resource identifier found for attribute ‘largeScreens’ in package ‘android’
– error: No resource identifier found for attribute ‘normalScreens’ in package ‘android’
– error: No resource identifier found for attribute ‘smallScreens’ in package ‘android’
– error: No resource identifier found for attribute ‘anyDensity’ in package ‘android’
================================================================
<uses-sdk android:minSdkVersion=”3″ android:targetSdkVersion=”4″ />
<!– <supports-screens android:largeScreens=”true”
android:normalScreens=”true” android:smallScreens=”true”
android:anyDensity=”true” /> –>

删掉
<!– <supports-screens android:largeScreens=”true”
android:normalScreens=”true” android:smallScreens=”true”
android:anyDensity=”true” /> –>
就可以运行了


======================================================
thread exiting with uncaught exception
======================================================
android Menifest.xml中没有声明activity

 

 

 

=====================================================
android mediaPlayer error (-38,0)
=====================================================

出现这个错误发现在mediaPlayer.reset()后调用了mediaPlayer.getDuration()
在没有给mediaPlayer对象设置数据源之前,是不能使用getDuration等这些方法的

05-05 09:35:01.861: W/dalvikvm(1618): threadid=45: thread exiting with uncaught exception (group=0x4001aa28)
05-05 09:35:01.861: E/AndroidRuntime(1618): Uncaught handler: thread Thread-38 exiting due to uncaught exception
05-05 09:35:01.861: E/AndroidRuntime(1618): java.lang.IllegalStateException
05-05 09:35:01.861: E/AndroidRuntime(1618): at android.media.MediaPlayer.getCurrentPosition(Native Method)
05-05 09:35:01.861: E/AndroidRuntime(1618): at chris.mediaPlayer.service.Mp3PlayerService$SeekBarRunnable.run(Mp3PlayerService.java:180)
05-05 09:35:01.861: E/AndroidRuntime(1618): at java.lang.Thread.run(Thread.java:1060)
当然还有可能是其他原因因其这类错误:

http://blog.csdn.net/ranger1111/article/details/6284806

在android开发中,经常会用到MediaPlayer。
在使用MediaPlayer时,有时候会遇到:MediaPlayer(362): error (-38, 0) 类似的错误。
这时,需要检查一下在设置MediaPlayer的数据源时,使用的是那种方式:
1.在初始化MediaPlayer时,通过create方法设置数据源。则不能写MediaPlayer.prepare()方法,这时,会报错。
2.如果是使用MediaPlayer构造函数初始化MediaPlayer,然后通过setDataSource方法设置数据源时,就需要在start()之前,使用MediaPlayer.prepare()方法,对数据源进行一次编译。能够避免出现(-38,0)这种错误。

ps:如果是apk里,写好的文件。可能还需要“”chmod 777 ”修复一下权限。

 

=========================================================
The connection to adb is down, and a severe error has occured.
=========================================================

启动android模拟器时.有时会报The connection to adb is down, and a severe error has occured.的错误.
1.先把eclipse关闭.
2.在管理器转到你的android SDK 的platform-tools下, 如图:

cdplatform

3.键入adb kill-server ,如果adb关闭了会提示 server not running *
4.再输入 adb start-server 如果不成功会提示 daemon not running. starting it now on port ***的
而如果成功的话不提示任何语句的.这时再重新打开eclipse就可以正常运行模拟器的了.

还有一种情况,真机调试的时候,你开了腕豆夹,导致端口冲突了,前面一直没留意这个问题 ,解决办法:安装完手机的驱动后,关闭腕豆夹,重启eclipse,应该就可以了。腕豆夹与eclipse一般不同时打开。

 

 

===========================================================
android.os.NetworkOnMainThreadException
===========================================================

Android在4.0之前的版本 支持在主线程中访问网络,4.0以后不支持。
解决方法:
1.通过新的线程访问网络,
2.Handler更新View

 

 


//在onCreate 方法中:
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.vpdn_app);
		handler = new Handler(){
			public void handleMessage(Message msg) {
				      if (msg.what == 1) {
					java.lang.System.out.println("xml-->" + xml);
					if (null == xml) {
						Toast toast = Toast.makeText(vpdnListsActivity.this,
                                                             "无法连接远程服务器", Toast.LENGTH_SHORT);
						toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 220);
						toast.show();

					}
					apnInfos = parse(xml);
					SimpleAdapter simpleAdapter = buildSimpleAdapter(apnInfos);
					// 将这个SimpleAdapter对象设置到ListActivity当中
					setListAdapter(simpleAdapter);
				}
				super.handleMessage(msg);
			}

		};
	}

//调用的方法:
	private int updateListView() {
		// 下载包含所有apn基本信息的xml文件
		 new Thread(){
			 public void run(){
				 xml =downloadXML("yourAllPathTest.xml");
                      //10.0.2.2模拟器上用10.0.2.2访问你的电脑本机
                      //http://192.168.50.23:80/test.xml

                    Message msg = new Message();
                    msg.what = 1;
                    handler.sendMessage(msg);
                    }
           }.start();
     return 0;
 }

=====================================================================

Service
Caution: A service runs in the main thread of its hosting process—the service does not create its own thread and does not run in a separate process (unless you specify otherwise). This means that, if your service is going to do any CPU intensive work or blocking operations (such as MP3 playback or networking), you should create a new thread within the service to do that work. By using a separate thread, you will reduce the risk of Application Not Responding (ANR) errors and the application’s main thread can remain dedicated to user interaction with your activities.
如过在主线程调用service,并进行网络链接此类的长时间操作,由于service还在主线程中,会造成主线程阻塞,所以4.0以后的系统无法访问网络。
在service中如果想要做耗时的操作,就要新建线程,或者使用IntentService类(源码分析),否则会造成主线程阻塞,无响应。
继承IntentService后,注意:
public int onStartCommand (Intent intent, int flags, int startId)
Added in API level 5
You should not override this method for your IntentService. Instead, override onHandleIntent(Intent), which the system calls when the IntentService receives a start request.

eg1
继承service

public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    //经测试,Service里面是不能进行耗时的操作的,必须要手动开启一个工作线程来处理耗时操作
    System.out.println("onStart");
    try {
        Thread.sleep(20000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("睡眠结束");
}

继承intentService

public class MyIntentService extends IntentService {  

    public MyIntentService() {
        super("yyyyyyyyyyy");                      //构造函数如果没有super("yyyyyyyyyyy");就会出现如下错误
//intentservice java.lang.InstantiationException: can't instantiate class... no empty constructor
    }  

    @Override
    protected void onHandleIntent(Intent intent) {
        // 经测试,IntentService里面是可以进行耗时的操作的
        //IntentService使用队列的方式将请求的Intent加入队列,然后开启一个worker thread(线程)来处理队列中的Intent
        //对于异步的startService请求,IntentService会处理完成一个之后再处理第二个
        System.out.println("onStart");
        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("睡眠结束");
    }
} 

 

=============================================================================
引入第三方jar,java.lang.noclassdeffounderror
=============================================================================

http://blog.csdn.net/liushaogeng/article/details/6641704

Eclipse下,
右键工程,
Build path,
java build path,选择libraries
在右边的按钮中点击“Add Library”
选择“User library”,点击“下一步”
点击“User librarys”按钮
在出现的界面中点击“New..”按钮
在弹出的界面中随便起一个名字,点击“确定”
点击“Add jars”按钮选择第三方jar包,点击“确定”完成。
后面的步骤很重要,如果不进行后面的操作。在Eclipse里显示编译通过,不会有错误,但在模拟器或真机上运行的时候可能就会出现java.lang.noclassdeffounderror之类的错误:
1、在Android项目根目录下新建一个libs文件夹;
2、把你需要的导入的第三方Jar包复制进这个目录;
3、在libs目录上点右键,选Bulid path –> Use as source folder。

 

 

 

====================================================================================
unable to get system library for the project
====================================================================================
当我们从别处引入android工程时,会出现 unable to get system library for the project 的提示。
可能原因一:可能是由于sdk版本不兼容导致的。假设引入的工程sdk版本是7,而自己eclipse关联的sdk中没有版本7,便会出现找不到库的错误,此时需要更改
更改android工程的sdk版本的方式有2种:
①打开工程中的default.properties文件,在里面修改 ———不推荐
②右击工程–properties–Android,对话框右侧会列出各个sdk版本,点击选择就可以了,这种方式要比第一种方式好,因为会自动在default.properties文件中填写sdk版本名称,例如
Google的sdk版本名是target=Google Inc.:Google APIs:8

defaultproperty

 

解决方法二:clean工程,关闭工程,再打开工程

R文件没有生成的解决方案和上面一样

 

问题三: android INSTALL_FAILED_INSUFFICIENT_STORAGE
这是由于手机内存不足导致的 ,如果是模拟器,则使用下面的命令来实现 扩展emulator -avd 3avd -partition-size 128
===================================================================
设置了权限,但Eclipse 提示没有设置相应的权限
===================================================================
除了根目录的Manifest.xml bin目录里面也有Manifest.xml,
检查发现编译的时候没有自动更新bin目录里面的Manifest.xml文件所以报错。
==================================================================
Camera2-Parameters(184): set: Requested preview size 1080 x 1776 is not supported
==================================================================
用htc one x可以使用二维码,note2也可以使用二维码,但是到nexus5打开二维码扫面,出现不了图像,显示如上错误。
类似如下:
06-25 21:07:03.579: D/CameraConfigurationManager(3227): Setting preview size: Point(1080, 1776)
可以知道是因为在CameraConfigurationManager中没有根据屏幕选取好Carmera Preview
06-25 21:18:23.759: D/CameraConfigurationManager(8273): preview-size-values parameter: 1920×1080,1280×960,1280×768,1280×720,1024×768,800×600,800×480,720×480,640×480,352×288,320×240,176×144

If you want to set a specific size for your camera preview, set this in the surfaceChanged() method as noted in the comments above. When setting preview size, you must use values from getSupportedPreviewSizes(). Do not set arbitrary values in the setPreviewSize() method.
而getSupportedPreviewSizes返回的的是一个可以使用的list
public List<Camera.Size> getSupportedPreviewSizes ()
Added in API level 5
Gets the supported preview sizes.
Returns
· a list of Size object. This method will always return a list with at least one element.

在看看CameraConfigurationManager中

 private static Point findBestPreviewSizeValue(CharSequence previewSizeValueString, Point screenResolution) {
    int bestX = 0;
    int bestY = 0;
    int diff = Integer.MAX_VALUE;
    for (String previewSize : COMMA_PATTERN.split(previewSizeValueString)) {
      previewSize = previewSize.trim();
      int dimPosition = previewSize.indexOf('x');
      if (dimPosition < 0) {
        Log.w(TAG, "Bad preview-size: " + previewSize);
        continue;
      }

      int newX;
      int newY;
      try {
        newX = Integer.parseInt(previewSize.substring(0, dimPosition));
        newY = Integer.parseInt(previewSize.substring(dimPosition + 1));
      } catch (NumberFormatException nfe) {
        Log.w(TAG, "Bad preview-size: " + previewSize);
        continue;
      }

      int newDiff = Math.abs(newX - screenResolution.x) + Math.abs(newY - screenResolution.y);
      if (newDiff == 0) {
        bestX = newX;
        bestY = newY;
        break;
      } else if (newDiff < diff) {
        bestX = newX;
        bestY = newY;
        diff = newDiff;
      }
//      int newDiff = Math.abs(newX - screenResolution.x) + Math.abs(newY - screenResolution.y);
//      boolean isScaleRight = ((double)newX / (double)screenResolution.y == (double)newY / (double)screenResolution.x);
//
//      if (newDiff == 0) {
//      bestX = newX;
//      bestY = newY;
//      break;
//      } else if (isScaleRight && newDiff < diff) {
//      bestX = newX;
//      bestY = newY;
//      diff = newDiff;
//      }
    }

    if (bestX > 0 && bestY > 0) {
      return new Point(bestX, bestY);
    }
    return null;
  }

 

======================================================
android开发乱码情况
======================================================
像是歌词这类文件,虚拟机里面中文显示不出来,而是乱码。只需用记事本打开,文件另存为时,选择UTF-8编码方式就可以了。

 

 

 

 

 

 

Tagged on: ,

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>