Android开发小问题总结

时间:2023-03-09 00:18:36
Android开发小问题总结

Android开发遇到的小问题之小解;

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

eclipse里console里提示The launch will only sync the application package on the device

经查找是AndroidManifest.xml里的主activity里红色部分没加,,

<activity
            android:label="@string/XXX"
            android:name=".XXX">
            <intent-filter> 
                <action android:name="android.intent.action.MAIN" /> 
                <category android:name="android.intent.category.LAUNCHER" /> 
            </intent-filter> 
        </activity>

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Unreachable code 错误

不可达代码,比如在循环的break或者return后面的代码就是不可达代码,因为执行它们之前就已经跳出循环了,只要把这段代码移到break或者return之前就好了

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Problem:The nested type HelloWorld cannot hide an enclosing type

回答:You have defined the HelloWorld class twice. Remove one level and you should be fine.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

class ButtonListener implements OnClickListener
如果按照上面写就会报错了,改成如下形式才行
class ButtonListener extends Activity  implements Button.OnClickListener

报错提示:
The type ProgressHandle.ButtonListener must implement the inherited abstract method DialogInterface.OnClickListener.onClick(DialogInterface, int)

结论:使用快捷键时导包导错了,应该导入android.view.View.OnClickListener包,而不是android.content.DialogInterface.OnClickListener包。

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

未完待续...