AndroidStudio禁用"字符串类型#34的预期资源;

时间:2016-01-26 08:44:01

标签: android android-studio butterknife

我刚尝试为我的某个项目生成已签名的apk(之前我已经这样做了),但是(可能自更新Android Studio以来)我得到了

  

错误:错误:字符串[ResourceType]

类型的预期资源

这是因为我使用Butterknife的@BindString,生成类似的东西

<string>

如何让工作室不将此检测为错误?我尝试过在设置中搜索,但没有成功。

5 个答案:

答案 0 :(得分:66)

对此的回答是:在build.gradle中禁用lint规则

Public Class Voice_recognition

    Public Function convertTotext(ByVal path As String, ByVal output As String) As String
        Dim request As HttpWebRequest = DirectCast(HttpWebRequest.Create("https://www.google.com/speech-api/v1/recognize?xjerr=1&client=speech2text&lang=en-US&maxresults=10"), HttpWebRequest)
        'path = Application.StartupPath & "curinputtmp.mp3"
        request.Timeout = 60000
        request.Method = "POST"
        request.KeepAlive = True
        request.ContentType = "audio/x-flac; rate=8000"  
        request.UserAgent = "speech2text"

        Dim fInfo As New FileInfo(path)
        Dim numBytes As Long = fInfo.Length
        Dim data As Byte()

        Using fStream As New FileStream(path, FileMode.Open, FileAccess.Read)
            data = New Byte(CInt(fStream.Length - 1)) {}
            fStream.Read(data, 0, CInt(fStream.Length))
            fStream.Close()
        End Using

        Using wrStream As Stream = request.GetRequestStream()
            wrStream.Write(data, 0, data.Length)
        End Using

        Try
            Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
            Dim resp = response.GetResponseStream()

            If resp IsNot Nothing Then
                Dim sr As New StreamReader(resp)
                MessageBox.Show(sr.ReadToEnd())

                resp.Close()
                resp.Dispose()
            End If
        Catch ex As System.Exception
            MessageBox.Show(ex.Message)
        End Try

        Return 0
    End Function
End Class

编辑: 特别是在从Eclipse迁移到Android Studio时,可能会发生这种情况。

答案 1 :(得分:8)

报告on the GitHub project。 它将在下一版ButterKnife中修复。

解决方法显示为there,并在lint.xml模块上添加app文件,其中包含以下内容,以忽略*$$ViewBinder类上的错误( ButterKnife生成的):

<issue id="ResourceType">
    <!-- Remove this when this is fixed: https://github.com/JakeWharton/butterknife/issues/338 -->
    <ignore path="**/*$$ViewBinder.java" />
</issue>

答案 2 :(得分:5)

也许更好的解决方案是在方法定义之前使用@SuppressLint("ResourceType")临时禁用错误/警告。

答案 3 :(得分:0)

我有类似的问题。使用getString方法。原来我试图获取字符串值不是来自strings.xml而是来自ids.xml,因为我得到的是getString(R.id.MYSTRING),当它应该是R.string.MYSTRING

答案 4 :(得分:0)

这是针对某些视图使用相同的ID,并尝试更改其中一个属性。 当试图生成apk安卓时找到一些关于resours id的错误

要解决这个问题

更好地找到代码并尝试从另一种方式解决这个问题

好运