Java I/O 讀寫單位為何用 int 而非 byte/char?JVM 預設運算單元與歷史緣由
現象 InputStream.read() // 回傳 int (0-255 或 -1) OutputStream.write(int b) // 參數 in
Android 自訂 Toast 顯示異常?LayoutInflater 需從 Context 取得、類別勿繼承 Activity
錯誤代碼分析 public class SMSToast extends Activity { // ❌ 錯誤:Toast 工具類不應繼承 Activity
Android Shell 開啟開發者選項:用 Intent 啟動設定頁面
場景 部分 ROM 隱藏了「開發者選項」入口,需以程式碼或 Shell 指令開啟。 程式碼啟動(最通用) Intent intent = new Intent
Java URL 獲取圖片位元組:需用 HttpURLConnection 而非 openStream
問題代碼 URL url = new URL(https://example.com/image.jpg); InputStream in = url.open
Android SQLite 重複呼叫 CREATE TABLE 會覆蓋舊表嗎?onCreate 只在資料庫首次建立時執行
核心結論 不會覆蓋。SQLiteOpenHelper.onCreate(SQLiteDatabase db) **只有在資料庫檔案不存在時** 才會被呼叫一次。
FragmentPagerAdapter ViewPager 無法顯示資料?移除 isViewFromObject 覆寫
問題現象 使用 ViewPager + FragmentPagerAdapter 實現分頁切換,頁面能滑動但 Fragment 內容空白,onCreateVie
Android 自訂通知佈局 Style 父樣式找不到?加上 @android:style/ 前綴
錯誤訊息 error: Error retrieving parent for item: No resource found that matches the
iOS UISearchBar 鍵盤搜尋按鈕響應:實作 searchBarSearchButtonClicked 代理方法
核心解法 讓控制器遵循 UISearchBarDelegate,並實作 searchBarSearchButtonClicked: 方法。 完整代碼 Swif
PHP JSON 正則提取鍵值對:貪婪匹配陷阱與非貪婪模式解析
問題復現 輸入字符串: {a:aaaaaaaaa,aa:baaaaaaaaa,aa:caaaaaaaaa,b:{c:1,d:ddddd},e:[1,2,5,9,
Android OnClickListener 正確寫法:View 必須在 setContentView 後初始化
錯誤代碼分析 public class MainActivity extends Activity implements OnClickListener {
Android addPreferencesFromResource 報錯?類別必須繼承 PreferenceActivity
錯誤訊息 Cannot resolve method addPreferencesFromResource(int) import android.prefer
iOS 數字轉中文大寫/指示性字符:陣列映射法
需求 資料庫讀取的數值為 1, 2, 3...,需在 Label 顯示為 一, 二, 三... 或 one, two, three...。 核心思路:建立映射
iOS UITableViewCell 文字水平偏移:自訂 Cell 或調整 textLabel frame
兩種實作方式 方式一:調整 textLabel frame(快速、輕量) - (UITableViewCell *)tableView:(UITableView
C++ struct 含 string 陣列輸入失敗?清除緩衝區換行符
問題現象 cin >> d_number; // 讀取整數,留下 \n 在緩衝區 getline(cin, p[i].name);
iOS 隱藏 UINavigationController 導航列
場景 使用 UINavigationController 作為根視圖控制器,但不想顯示頂部導航列。 一行代碼解決 navigationController.i
Android Button 圓角樣式在 style 中不生效?改用 Shape Drawable 做背景
問題現象 在 styles.xml 設定 <item name=android:radius>6dp</item> 試圖讓 Button
iOS 點擊關閉按鈕移除或隱藏 subView
場景 將自訂 UIView 作為子視圖加到主視窗,需在關閉按鈕點擊時移除或隱藏該子視圖。 核心 API removeFromSuperview():從父視圖