當前位置:首頁 » 安卓系統 » androidthis錯誤

androidthis錯誤

發布時間: 2022-08-01 19:01:50

① Android this會不會為空

不會,this是代表這個activity類,只要activity實例化了,就不會為空的。如果包裝在方法類,需要類名點this調用才不會報錯。

② TextView tv = new (this);在Android開發中,為什麼總顯示語法錯誤呢!應該怎麼改

這個構造函數要求參數是Context類型的,你的this不一定是這個類型。
比如你在HomeActivity這個java類中使用的時候,參數可以傳HomeActivity.this,因為Activity也是Context的子類。

③ android添加按鈕出錯,Button bn = new Button(this);報錯

把this換成MainActivity.this,因為你是在匿名內部類使用this,你的this是指OnClickListener

④ Android this問題

從Intenti=newIntent(this,Sang_h2.class)的原意看,應該指向上下文Context(如Activity,Service,Application等)。但這里是否使用正確要看方法onClick所在的類。

假如

{
//……
classmyListenerimplementsView.onClickListener{
publicvoidonClick(Viewv){
//這時this指向myListener,那麼正確的用法是
Intenti=newIntent(MyActivity.this,Sang_h2.class);
startActivity(i);
}
}
//……
}

⑤ 使用android怎樣查看錯誤提示信息

或許困擾很多Android開發者最大的問題莫過於Bug的修改了,調Bug 改Bug,想想都頭疼,以下就是一位對Bug很有經驗的開發者總結出來的有關Android錯誤的解決方法。

1 android java.net.UnknownHostException: Unable to resolve host "...": No address associated 錯誤
在android開發的時候經常會遇到這個錯誤,一般來說,造成這種錯誤的最普遍情況有兩種:

1.android設備網路連接沒打開,例如3G網路和WIFI網路

所以,如果遇到這種錯誤時,請先查看網路是否已正常連接.

2.Manifest文件沒有標明網路訪問許可權

如果確認網路已經正常連接並且還是出這種錯誤的話,那麼請看下自己的Manifest文件是否標明應用需要網路訪問許可權,如果沒標明的話,也訪問不了網路,也會造成這種情況的.

//網路訪問許可權

2 Failed to install *.apk on device 'emulator-5554': timeout

錯誤提示:

Failed to install helloworld.apk on device 'emulator-5554': timeout

或者

the user data image is used

原因:

由於模擬器已經開啟而沒有關閉或者非法關閉引起的。

解決方法:

刪除 C:Documents and SettingsAdministrator.androidavd對應版本.avd

下所有以.lock結尾的文件夾

或者

Failed to install *.apk on device *:

timeout Launch canceled!

還有一種辦法:

在window->preferences->Android->DDMS->ADB connection time out (ms):

將這個值設置的大一些,默認為5000,設置成500000,然後就OK了。

3 This Android SDK requires Andriod Developer Toolkit version 20.0.0 or above
打開Eclipse(Android 開發環境),發現以下報錯:

圖片顯示信息為:Android SDK要求ADT(Android Developer Toolkit)版本在20.0.0或以上版本,檢測到當前版本為18.0.0,請更新最新的ADT。

出現這樣的提示,根本原因是Eclipse啟動時檢測E:Program Filesandroid-sdk-windowstoolslibplugin.prop文件 文件內容為:

begin plugin.prop
plugin.version=20.0.0

# end plugin.prop

這就很容易理解了,需求插件版本為20.0.0,這時候咱們只需要改成:

begin plugin.prop
plugin.version=18.0.0

# end plugin.prop

OK了,重新啟動下Eclipse,看看是不是解決了這個問題

4 [Accessibility] Missing contentDescription attribute on image

今天使用了下ADT 16.0 在定義一個ImageVIew的時候 總是提示這個[Accessibility] Missing contentDescription attribute on image警告,雖說可以不理 但總是感覺怪怪的,在網上一搜 發現原來這是ADT 16.0的新特性,在一些沒有文本顯示的控制項里,如imageView和imageButton等,ADT會提示定義一個android:contentDescription屬性,用來描述這個控制項的作用。英文原文如下,如有翻譯的不對的地方,敬請批評指正。

Resolved this warning by setting attribute android:contentDescription for my ImageView

android:contentDescription="@string/desc"

Android Lint support in ADT 16 throws this warning to ensure that image widgets provide a contentDescription

This defines text that briefly describes content of the view. This property is used primarily for accessibility. Since some views do not have textual representation this attribute can be used for providing such.

Non-textual widgets like ImageViews and ImageButtons should use the contentDescription attribute to specify a textual description of the widget such that screen readers and other accessibility tools can adequately describe the user interface.

5 java.lang.NoClassDefFoundError: com..mapapi.BMapManager解決辦法

⑥ Android的這句代碼報錯,inflate()顯示紅色,問題出在哪裡

一、自帶清除緩存
點擊AndroidStudio菜單File -> Invalidate Caches/Restar… ,在彈出的對話框中點擊Invalidate and Restar
。等待AS清理並自動重啟。

二、刪除user目錄下.AndroidStudio中的文件
關閉AndroidStudio,進入C:\Users\xUser.AndroidStudio3.1(3.1為當前AS版本號),刪除除了config以外的文件。重新打開AndroidStudio會自動Sync,等待同步完成。
三、刪除user目錄下.gradle
關閉AndroidStudio,刪除C:\Users\xUser\.gradle。重新打開AndroidStudio會自動Sync,等待同步完成。
注意:刪除該文件夾所有的classpath、gradle、compile、implementation等,都需要重新從網上同步。
四、刪除工程目錄下.gradle、.idea
關閉AndroidStudio,進入工程根目錄,刪除.gradle、.idea兩個文件夾。重新打開AndroidStudio會自動Sync,等待同步完成。
-------------------
原文鏈接:https://blog.csdn.net/hx7013/article/details/79971980
原文鏈接:https://blog.csdn.net/hx7013/article/details/79971980

⑦ 關於android開發(java開發)中this的問題

通俗講,this指本類,如:
public
class
Main
extends
Activity
{
。。。
GridView
gridview
=(GridView)
findViewById(R.id.gridview);
gridview.setAdapter(newImageAdapter(this));
。。。
}
代碼第二行的this指Main.this
Android很多控制項運行是有條件的,就是所謂的運行環境,就是Context(上下文),Context就是一系列環境變數,控制項的運行是基於這些變數的。
我也是花很多時間才真正體會到this,Context概念的,這個概念非常重要,慢慢體會吧。

⑧ 關於Android模擬器運行報錯的問題

問題一,解決辦法有如下這些:
1.
重啟Eclipse,方法File—>Restart。
2.
嘗試重啟ADB服務。
你可以在sdk目錄如c:\Program
Files\Android\android-sdk-windows\platform-tools\下建一個叫restartADB.bat的windows批處理文件,文件中寫入:
adb kill-server && adb start-server
pause
需要重啟ADB,只要雙擊運行文件即可,注意adb.exe須在platform-tools目錄下,不然腳本可能運行不了
3.
刪除Run
Configuration,在Run—>Run
Configuration中,選擇刪除已經配置的Activity。
4.
嘗試刪除你的.android文件下的一些鏡像文件。按你問題提供的信息,應該在:C:\Users\lgs\.android\avd\androidAddresslist.avd/sdcard.img
C:\Users\lgs\.android\avd\androidAddresslist.avd/sdcard.img
C:\Users\lgs\.android\avd\androidAddresslist.avd/userdata-qemu.img
問題二,解決方法有:
1.重啟Eclipse,重啟ADB。
2.如果上面方法不行,看一下有沒有類似91手機助手,騰訊手機助手等工具正在開啟,有的話就結束掉這些工具對應的進程。
3.如果你的sdk還是2.3以下的舊版本,那麼就是把tools文件夾中的adb.exe復制到platform-tools文件夾中。

⑨ Android開發,Dialog dialog=new AlertDialog.Builder(this)出錯。

比如你的
源碼
文件名是
Activity.java,就改成
Dialog
dialog=new
AlertDialog.Builder(Activity.this);

名稱
而異。在listener中的this
指代
的並不是Activity里的this,而兩個this成員和方法是完全不一樣的,所以會出錯,需要告訴IDE即將訪問的是Activity的this,這樣就不會出問題了。

熱點內容
qq刷紅包腳本 發布:2024-05-03 16:16:54 瀏覽:769
c服務編譯耗時優化原理及實例 發布:2024-05-03 15:35:26 瀏覽:15
ue編程 發布:2024-05-03 15:34:40 瀏覽:610
經典的c語言程序 發布:2024-05-03 15:03:24 瀏覽:859
工程加密網 發布:2024-05-03 14:59:55 瀏覽:292
吃冰球解壓 發布:2024-05-03 14:59:10 瀏覽:895
編譯晶元發燙 發布:2024-05-03 14:59:05 瀏覽:549
優化演算法pdf 發布:2024-05-03 14:18:10 瀏覽:291
python演算法書 發布:2024-05-03 14:14:25 瀏覽:736
方舟怎麼加入伺服器閃退 發布:2024-05-03 14:05:27 瀏覽:491