Android在访问字符串的值时出错

Android在访问字符串的值时出错,android,Android,我在安卓上工作。我想从服务器访问该文件。如果我以这种方式编写url: URL sourceUrl = new URL("http://192.168.1.214/MusicApplication/searchsongxml.php?"); 然后它就正常工作了 但是如果我在strings.xml中声明服务器名称,如下所示: <resources> <string name="SERVER_NAME">http://192.168.1.214/</stri

我在安卓上工作。我想从服务器访问该文件。如果我以这种方式编写url:

URL sourceUrl = new URL("http://192.168.1.214/MusicApplication/searchsongxml.php?");
然后它就正常工作了

但是如果我在strings.xml中声明服务器名称,如下所示:

<resources>  
    <string name="SERVER_NAME">http://192.168.1.214/</string>
</resources>
然后,这将创建一个异常,我的应用程序将停止

请告诉我我犯了什么错误。

试试这个

URL sourceUrl = new URL(your_context.getString(R.string.SERVER_NAME)+"MusicApplication/searchsongxml.php");
试试这个

URL sourceUrl = new URL(your_context.getString(R.string.SERVER_NAME)+"MusicApplication/searchsongxml.php");

请从
logcat
发布异常的堆栈跟踪。无法启动活动com.perient.musicapp.HelloTabWidget}:java.lang.NullPointerException,并且仅当我使用getString(strings.R.SERVER\u NAME)时才会发生此错误。请从
logcat
发布异常的堆栈跟踪。无法启动活动com.perient.musicapp.HelloTabWidget}:java.lang.NullPointerException,此错误仅在我使用getString(strings.R.SERVER_NAME)时发生。啊,我没有注意到这一点。我想可能是一些逃避问题+1啊,我没注意到。我想可能是一些逃避问题+1.