Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException on build when adding new Table #72

Open
iamareebjamal opened this issue Feb 24, 2017 · 1 comment
Open

NullPointerException on build when adding new Table #72

iamareebjamal opened this issue Feb 24, 2017 · 1 comment

Comments

@iamareebjamal
Copy link

I added one table and everything was working great.
Added two more tables and build start failing with NullPointerException without any message. I ran the build with --stacktrace and it said that the error was occurring at TableWriter.java:154 of the annotation processor.

Can you please look at the issue or guide me in the right direction if it is any known one.

Thanks

@baisong
Copy link

baisong commented Jun 16, 2017

Hi @iamareebjamal, I ran into the same problem, and after changing my @Database() annotation parameters and gradle files, I finally got past it. Not sure what it was, but here's my current setup.

@database() class

@Database(className = RecipeDatabase.CLASS, fileName = RecipeDatabase.NAME, version = RecipeDatabase.VERSION, packageName = RecipeDatabase.PACKAGE)
public class RecipeDatabase {
    public static final String NAME = "bakingapp.db";
    public static final String CLASS = "BakingAppDatabase";
    public static final int VERSION = 1;
    public static final String PACKAGE = "com.example.android.bakingapp.provider";
    private RecipeDatabase() {};

    @Table(RecipeColumns.class) public static final String RECIPES = "recipes";
    @OnCreate
    public static void onCreate(Context context, SQLiteDatabase db) {
    }

    @OnUpgrade
    public static void onUpgrade(Context c, SQLiteDatabase db, int oldVersion, int newVersion) {
    }

    @OnConfigure
    public static void onConfigure(SQLiteDatabase db) {
    }

    @ExecOnCreate
    public static final String EXEC_ON_CREATE = "SELECT * FROM " + RECIPES;
}

Columns interface

public interface RecipeColumns {
    @DataType(INTEGER) @PrimaryKey
    @AutoIncrement
    static final String ID = "_id";

    @DataType(TEXT) public static final String NAME = "name";
    @DataType(INTEGER) String SERVINGS = "servings";
    @DataType(TEXT) String IMAGE = "image_url";
}

Project build.gradle

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Module build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'android-apt'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.android.bakingapp"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    annotationProcessor 'net.simonvt.schematic:schematic-compiler:0.7.0'
    compile 'net.simonvt.schematic:schematic:0.7.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
    testCompile 'junit:junit:4.12'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants