Gradle Build fail with java.lang.IllegalStateException: expected BEGIN_ARRAY 但在第 1 行第 1 列路径处是 STRING $
我正在构建一个应用程序,该应用程序从Firebase获取数据,将其添加到数组适配器中并在列表视图中显示。当我尝试构建应用程序时,它失败了:
错误:任务“:app:transformClassesWithInstantRunForDebug”的执行失败。java.lang.IllegalStateException: expected BEGIN_ARRAY 但在第 1 行第 1 列路径 $
我的活动:
package app.nert;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;
public class display extends AppCompatActivity {
private AdView mAdView;
private ArrayList<String> ttable = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
MobileAds.initialize(this, "ca-app-pub-...");
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-...");
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
//Shared Preference declaration
SharedPreferences sprefs = getSharedPreferences("nert.app", MODE_PRIVATE);
String sid = sprefs.getString("school_id", "Not defined yet");//get schoolid
String sch = sprefs.getString("school", "Not defined yet");//get schoolname
String cl = sprefs.getString("class", "Not defined yet");// get classname
String clid = sprefs.getString("class_id", "Not defined yet");//get classid
TextView tod = findViewById(R.id.today);
TextView tom = findViewById(R.id.tom);
tod.setVisibility(View.VISIBLE);
tom.setVisibility(View.VISIBLE);
}
protected void onStart() {
super.onStart();
//Begin Shared Preferences
SharedPreferences sprefs = getSharedPreferences("nert.app", MODE_PRIVATE);
String sid = sprefs.getString("school_id", "Not defined yet");//get schoolid
String sch = sprefs.getString("school", "Not defined yet");//get schoolname
String cl = sprefs.getString("class", "Not defined yet");// get classname
String clid = sprefs.getString("class_id", "Not defined yet");//get classid
//End Shared Preferences
//Begin get Day
String weekDay;
SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE", Locale.US);
Calendar calendar = Calendar.getInstance();
weekDay = dayFormat.format(calendar.getTime());
String day = String.valueOf(weekDay);
//End get Day
ListView tday = findViewById(R.id.day);
tday.setDividerHeight(0);
final ArrayAdapter tdayadapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, ttable);
tday.setAdapter(tdayadapter);
DatabaseReference gettt = FirebaseDatabase.getInstance().getReference().child("schools").child("classes").child(sid).child(clid).child("timetable").child(day);
gettt.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String value = dataSnapshot.getValue(String.class);
tdayadapter.add(value);
tdayadapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
public void homework(View view) {
Intent hw = new Intent(this, homework.class);
startActivity(hw);
}
public void replacement(View view) {
Intent rp = new Intent(this, replacement.class);
startActivity(rp);
}
public void onBackPressed() {
}
public void at(View view) {
Intent an = new Intent(this, anifrom.class);
startActivity(an);
}
public void today(View view) {
ListView lstd = findViewById(R.id.day);
ListView lstt = findViewById(R.id.tmo);
TextView tod = findViewById(R.id.today);
TextView tod2 = findViewById(R.id.today2);
TextView tom = findViewById(R.id.tom);
TextView tom2 = findViewById(R.id.tom2);
lstt.setVisibility(View.GONE);
tod2.setVisibility(View.GONE);
tom2.setVisibility(View.GONE);
lstd.setVisibility(View.VISIBLE);
tod.setVisibility(View.VISIBLE);
tom.setVisibility(View.VISIBLE);
}
public void tom(View view) {
ListView lstd = findViewById(R.id.day);
ListView lstt = findViewById(R.id.tmo);
TextView tod = findViewById(R.id.today);
TextView tod2 = findViewById(R.id.today2);
TextView tom = findViewById(R.id.tom);
TextView tom2 = findViewById(R.id.tom2);
lstd.setVisibility(View.GONE);
tod.setVisibility(View.GONE);
tom.setVisibility(View.GONE);
lstt.setVisibility(View.VISIBLE);
tod2.setVisibility(View.VISIBLE);
tom2.setVisibility(View.VISIBLE);
}
}
和我的 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "app.nert"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0-alpha"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'io.fabric.tools:gradle:1.24.4'
}
}
dependencies {
implementation 'com.android.support:design:26.1.0'
compile 'com.google.firebase:firebase-database:11.8.0'
compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
transitive = true
}
compile 'com.google.firebase:firebase-core:11.8.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-ads:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.google.android.gms:play-services-ads:11.8.0'
}
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
如何防止生成失败?