小编Its*_*ank的帖子

String.xml或Constants类

在设计Android应用程序时,以下更好的方法是什么?

  1. 将所有String常量放在res/values/Strings.xml 或中
  2. 创建一个类似Constant.java所有字符串的类public static final

选择哪一个更有效?

android android-xml

24
推荐指数
1
解决办法
5693
查看次数

ActionBar抛出NullPointerException

我无法弄清楚这个.我正在定制我的ActionBar(是的,我的应用程序是3.0+)代码在Device上运行正常(使用Motorola xoom,如果它很重要).但是当我在模拟器上运行它时会抛出NPE.这是我的ActionBar代码

/**
 * Customizes Action bar sets background color and assigns a layout to it
 */
private void customActionBar() {
    Log.v(TAG, "customizing ActionBar Entry");
    ActionBar actionBar = getActionBar();
    Log.v(TAG, "customizing ActionBar : "+actionBar.toString());
            //This is where i get NPE
    actionBar.setBackgroundDrawable(new ColorDrawable(Color
            .parseColor(Constants.COLOR)));
    Log.v(TAG, "customizing ActionBar -Background color : ");

    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.custom_action, null);
    // lay.setLayoutParams(new ActionBar.LayoutParams(
    // android.app.ActionBar.LayoutParams.MATCH_PARENT,
    // android.app.ActionBar.LayoutParams.MATCH_PARENT));
    actionBar.setCustomView(view);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    Log.v(TAG, "customizing ActionBar Exit");
}
Run Code Online (Sandbox Code Playgroud)

编辑:logcat

V/>>> FullPdfViewerActivity(438): customizing ActionBar Entry …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception android-emulator android-actionbar

4
推荐指数
1
解决办法
6955
查看次数

订阅样本缺少对purchaseToken的JSON解析

我最近一直在研究In-App-Billing v2的代码.并发现了一些问题.我之前已实施In-App-Billing但希望升级到订阅.在我的研究中,我发现购买令牌与成功购买订阅的JSON(签名数据)一起收到.

成功验证签名的演示版Security.java解析了Json,但是这里缺少元素Purchase-token的解析.

            JSONObject jElement = jTransactionsArray.getJSONObject(i);
            int response = jElement.getInt("purchaseState");
            PurchaseState purchaseState = PurchaseState.valueOf(response);
            String productId = jElement.getString("productId");
            String packageName = jElement.getString("packageName");
            long purchaseTime = jElement.getLong("purchaseTime");
            String orderId = jElement.optString("orderId", "");
            String notifyId = null;
//          purchaseToken part that I have added
            String purchaseToken = jElement.optString("purchaseToken", "");
Run Code Online (Sandbox Code Playgroud)

我还没有运行代码,因为订阅没有测试产品-id并且需要实际购买.我想知道的是这个令牌在这里被解析,或者提供的示例代码是否正确实现了这部分.

android subscription in-app-billing

4
推荐指数
1
解决办法
1602
查看次数

在升级时创建表

我一直在努力做到这一点,但我不知道我错过了什么.我有一个Android应用程序,我希望再添加1个表.但是我无法做到这一点,我也没有例外(不喜欢这些沉默的杀手!!).

下面是我的代码我的SQLiteHelper类

public class DbCreator extends SQLiteOpenHelper {

public DbCreator(Context context) {

    super(context, Constants.DB_NAME, null, Constants.NEW_VERSION);//NEW_VERSION=2

    this.myContext = context;
}

//Rest of code

//Checks if DB is present and create if reqd.
public void createDataBase() throws IOException {

    boolean dbExist = checkDataBase();
    if (dbExist) {
        // do nothing - database already exist
    } else {

        // By calling this method and empty database will be created into
        // the default system path
        // of your application so we are gonna …
Run Code Online (Sandbox Code Playgroud)

sqlite android

2
推荐指数
1
解决办法
669
查看次数