SimonVT / schematic

Automatically generate ContentProviders
1.34k stars 135 forks source link

NullPointerException on build when adding new Table #72

Open iamareebjamal opened 7 years ago

iamareebjamal commented 7 years ago

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 commented 7 years ago

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'
}