更新Android Studio后,我在viewpager的xml中收到此错误。 奇怪的是,它可以正常工作,并且项目构建没有任何问题。
“ @ string / appbar_scrolling_view_behavior” 是什么原因? 未解决的课程?
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
我的viewpager位于 CoordinatorLayout 中。
答案 0 :(得分:1)
使用或迁移到AndroidX的用户可以使用以下修复程序来消除此错误。在Android Studio 3.4中也可以使用
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
答案 1 :(得分:1)
正如Barry Staes指出的那样,它看起来像是IDE中的错误。但是,如果您使用的是设计库,则此语法应使错误消失:
private fun loadDate(){
mLineChart = findViewById(R.id.chart)
dataList = ArrayList()
val stringRequest = StringRequest(
Request.Method.GET, URL,
Listener { response ->
Log.d("JSONResult", response.toString())
try {
//converting the string to json array object
var array = JSONArray(response)
//traversing through all the object
for (i in 0 until array.length()) {
var stationData = array.getJSONObject(i)
//adding the product to product list
dataList.add(Data(
stationData.getString("id"),
stationData.getString("station_name"),
stationData.getString("date_time"),
stationData.getString("pm25_10min_avg")
))
}
var i = 0
val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH)
for (data in dataList) {
if (data.name == navBarTitle) {
val date = df.parse(data.date)
val pm = java.lang.Float.parseFloat(data.pm)
entries.add(Entry(date.time.toFloat(), water))
}
}
val set1 = LineDataSet(entries, "pm25_10min_avg")
set1.fillAlpha = 110
var dataSet = java.util.ArrayList<ILineDataSet>()
dataSet.add(set1)
val lineData = LineData(dataSet)
mLineChart.data = lineData
set1.color = Color.RED
set1.mode = LineDataSet.Mode.HORIZONTAL_BEZIER
set1.setCircleColor(Color.RED)
set1.setDrawCircleHole(false)
set1.setDrawValues(false)
mLineChart.description.text = ""
mLineChart.invalidate()
mLineChart.axisRight.isEnabled = false
mLineChart.axisLeft.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART)
mLineChart.axisRight.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART)
val legend = mLineChart.legend
legend.isEnabled = true
legend.verticalAlignment = Legend.LegendVerticalAlignment.TOP
legend.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
legend.orientation = Legend.LegendOrientation.HORIZONTAL
legend.textSize = 15f
val xAxis = mLineChart.xAxis
xAxis.position = XAxis.XAxisPosition.BOTTOM
xAxis.setDrawGridLines(false)
xAxis.labelCount = 6
xAxis.granularity = 1F
xAxis.isGranularityEnabled = true
val dateFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH)
val sdf = SimpleDateFormat("HH:mm", Locale.ENGLISH)
for (data in dataList) {
if (data.name == navBarTitle) {
val date = dateFormatter.parse(data.date)
val time = sdf.format(date)
formatedXVal.add(time)
}
}
xAxis.valueFormatter = IndexAxisValueFormatter(formatedXVal)
val mv = MyMarkerView(this, R.layout.markerview)
mv.chartView = chart // For bounds control
chart!!.marker = mv
} catch (e: NullPointerException) {
e.printStackTrace()
} catch (e: JSONException) {
e.printStackTrace()
}
},
Response.ErrorListener { error ->
error.printStackTrace()
Toast.makeText(this@AqiAnalysisActivity, error.message, Toast.LENGTH_LONG).show()})
Volley.newRequestQueue(this).add(stringRequest)
}
答案 2 :(得分:0)
这里也一样。看起来像是IDE中的错误,而不是应用程序中的错误。
Android Studio 3.4中的新项目(默认选项卡)显示警告:
未解决的类'@ string / appbar_scrolling_view_behavior'
检查信息:验证Android XML文件中的资源引用。
无法通过使缓存无效,清理构建,项目同步来解决。
代码:
// Incorrect: setTimeout(this.setState({data}), 3000);
setTimeout(() => this.setState({data}), 3000);
当我删除最后一行时,选项卡无法正常工作:
因此IDE找不到它,但是该应用程序肯定使用了字符串/类。
答案 3 :(得分:0)
我多次遇到相同的问题。
我总是使用public class TTSInputStream extends DataInputStream {
public TTSInputStream(InputStream in) {
super(in);
}
public final int readFullyUntilEof(byte b[]) throws IOException {
return readFullyUntilEof(b, 0, b.length);
}
public final int readFullyUntilEof(byte b[], int off, int len) throws IOException {
if (len < 0)
throw new IndexOutOfBoundsException();
int n = 0;
while (n < len) {
int count = in.read(b, off + n, len - n);
if (count < 0)
break;
n += count;
}
return n;
}
}
而不是new Thread(
new Runnable() {
@Override
public void run() {
try {
URI uri = URI.create("http://192.168.1.6:5000/api/tts");
HttpURLConnection urlConnection = (HttpURLConnection) uri.toURL().openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("x-access-token", credentials.getAccessToken());
urlConnection.setRequestProperty("Accept", "*");
urlConnection.setChunkedStreamingMode(bufferSize);
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.connect();
OutputStreamWriter osw = new OutputStreamWriter(urlConnection.getOutputStream());
String body = "{\"text\": \"" + text + "\", \"ttsLang\": \"" + language + "\"}";
Log.d("TTS_HTTP", body);
osw.write(body);
osw.flush();
osw.close();
Log.d("TTS_OUT", credentials.getAccessToken());
Log.d("TTS_OUT", urlConnection.getResponseCode() + " " + urlConnection.getResponseMessage());
// define the buffer size for audio track
int SAMPLE_RATE = 16000;
int bufferSize = AudioTrack.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT);
if (bufferSize == AudioTrack.ERROR || bufferSize == AudioTrack.ERROR_BAD_VALUE) {
bufferSize = SAMPLE_RATE * 2;
}
bufferSize *= 2;
TTSInputStream bis = new TTSInputStream(urlConnection.getInputStream());
AudioTrack audioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC,
SAMPLE_RATE,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT,
bufferSize * 2,
AudioTrack.MODE_STREAM);
byte[] buffer = new byte[bufferSize];
audioTrack.play();
int count;
while ((count = bis.readFullyUntilEof(buffer)) > 0) {
Log.d("TTS_COUNT", "Read " + count + " bytes.");
audioTrack.write(buffer, 0, buffer.length);
}
bis.close();
audioTrack.stop();
audioTrack.release();
} catch (IOException e) {
e.printStackTrace();
}
}
}
).start();
答案 4 :(得分:0)
转到应用程序级别 build.gradle 并添加:
def support_version="28.0.0"
implementation "com.android.support:design:$support_version"
如果不起作用,请仅修改support_version