我只想测试获取一个String资源等于我认为它应该相等.我的问题似乎是我的项目中有Realm.我知道Robolectric不支持Realm(它在文档中说明了它),但我根本没有调用Realm,所以我觉得可能有办法做到这一点.
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, manifest = "app/src/main/AndroidManifest.xml")
public class ResourceTester {
@Test
public void testingString() {
String resourceString = RuntimeEnvironment.application.getString(R.string.app_name);
assertEquals(resourceString, "Yeah");
}
}
Run Code Online (Sandbox Code Playgroud)
它看起来像它IS试图调用境界
java.lang.UnsatisfiedLinkError: Can't load library:
/var/folders/3x/ddxtg5fs1hxgqrp6h63vsc140000gp/T/android-tmp-
robolectric3612430387389787158/app_lib/librealm-jni.dylib.3.5.0
Run Code Online (Sandbox Code Playgroud)
编辑:我尝试了更多的东西,似乎设置manifest@Config注释是问题,但后来我得到了android.content.res.Resources$NotFoundException: unknown resource 2131362072
还有其他想法吗?我可以创建另一个Realm未调用的Application类吗?/ test目录如何知道?
编辑大卫:
我试过这个:
@RunWith(RobolectricGradleTestRunner.class)
@Config(application = TestingApplication.class, constants = BuildConfig.class, sdk = 21)
public class ResourceTester {
@Test
public …Run Code Online (Sandbox Code Playgroud) 我一直在寻找一段时间,并且没有能够为这一个找到正确的答案.长话短说,我正在从一个网页上搜索用作我的收件箱.我迫切需要跳过每个"消息"之间的行,所以我把
标签放在我的PHP中.它在web浏览器中完美运行,但在我的Android应用程序中,我实际上可以将
标签视为纯文本.试着将它们读作"下一行/新行".有任何想法吗?
我的方法代码:
public String getInbox(String where){
BufferedReader in = null;
String data = null;
try{
HttpClient client = new DefaultHttpClient();
URI website = new URI("http://example.com/getInbox.php?where="+where);
HttpPost post_request = new HttpPost();
post_request.setURI(website);
HttpGet request = new HttpGet();
request.setURI(website);
//executing actual request
//add your implementation here
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while ((l = in.readLine()) != null) {
sb.append(l+nl);
}
in.close();
data = …Run Code Online (Sandbox Code Playgroud) 我想知道什么是处理应用程序超时的最佳方法,例如PayPal.我希望用户在1到5分钟或15分钟的超时时间内进行选择,因此当他们打开应用程序时,他们必须再次登录.
我的onResume方法:
@Override
public void onResume() {
}
Run Code Online (Sandbox Code Playgroud)
它什么都没有.但它崩溃了.
作为注释:我的应用程序有两个活动.第一个活动是登录屏幕.第二个活动是主屏幕.onResume方法位于第二个活动中.
我一直认为HTML5应用程序与本机应用程序相比应该没有任何弱点,但根据今天发布的新Facebook应用程序,当他们切换到本机iOS代码而不是Web应用程序时,速度提升了.
这包括更快地打开应用程序本身,更顺畅和更快速的滚动,以及据说"即时"加载的照片 - 这些变化主要是由于从旧的HTML5代码切换到iOS的本机编程语言.
谁能保证这些速度提升?原生发展更快吗?
面向iOS的Facebook本土化,再见HTML 5 http://www.theverge.com/2012/8/23/3262782/facebook-for-ios-native-app
我没有iPhone,但是我的客户告诉我,他的iPhone上的电话号码(在我为他制作的网站上)变成了蓝色.解决这个问题的最佳方法是什么?
注意:这不是我网站上的链接,但是safari浏览器似乎已经成为一个链接
<span>(873)984-0923</span>
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习SharedPreferences,但我收到了一个错误.
我的布局有一个按钮,可以重现该方法 doThis
这是我的java:
package com.example.sharedprefs;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
int i = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void doThis (View view){
i++;
SharedPreferences sharedPref = getSharedPreferences("FileName",MODE_PRIVATE);
SharedPreferences.Editor prefEditor = sharedPref.edit();
prefEditor.putInt("userChoice",i);
prefEditor.commit();
int number = sharedPref.getInt("userChoice", 0);
Toast.makeText(getApplicationContext(), number, Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
我唯一可以在logcat中查明的是 10-15 19:28:17.707: E/AndroidRuntime(16657): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1
我有:
String sqlite = "SELECT count(_id) AS _lCount FROM answers WHERE phase = 3 and correct_incorrect='1'
Run Code Online (Sandbox Code Playgroud)
作为查询,但我需要correct_incorrect列也要考虑"1*"
这是一个有效的方法来解释它吗?
String sqlite = "SELECT count(_id) AS _lCount FROM answers WHERE phase = 3 and correct_incorrect='1'or'1*'
Run Code Online (Sandbox Code Playgroud)
我会测试它,但是"1*"的可能性很少,需要几个小时的测试.所以我想确保我不只是浪费时间.
我有textView,我想把它变成一个简单的日志,告诉程序当前循环的哪个阶段.
例如,如果我按下按钮:
public void doThis(View view) {
for (int j = 1; j <= 10; j++) {
my_text.setText(j+"");
}
}
Run Code Online (Sandbox Code Playgroud)
这会覆盖textView中的文本.我将如何创建textView所说的内容:
1
2
3
4
5
6
7
8
9
10
Run Code Online (Sandbox Code Playgroud) 我正在学习如何使用http://developer.android.com/guide/topics/media/audio-capture.html#example录制音频
一切正常,但我想切换:
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/audiorecordtest.3gp";
Run Code Online (Sandbox Code Playgroud)
至
mFileName = getFilesDir().getAbsolutePath();
mFileName += "/audiorecordtest.3gp";
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个错误
08-19 15:51:44.212: E/MediaPlayer(6654): error (1, -2147483648)
08-19 15:51:44.212: E/AudioRecordTest(6654): prepare() failed
Run Code Online (Sandbox Code Playgroud)
我试着记录我的新代码(以确保我使用的是有效路径).
这适用于我的三星Galaxy,但不适用于我的Nexus One.我希望这适用于2.x,3.x和4.x.
更新: 我在startRecording()中添加了一个日志:
mRecorder.setOutputFile(mFileName);
Log.e("LOG", mFileName);
Run Code Online (Sandbox Code Playgroud)
该日志的输出是:
08-22 12:28:40.112: E/LOG(9666): /data/data/com.example.testrecorder/files/audiorecordtest.3gp
Run Code Online (Sandbox Code Playgroud)
尝试记录异常:
private void startPlaying() {
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(mFileName);
mPlayer.prepare();
mPlayer.start();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed", e);
}
}
08-22 13:08:03.158: E/MediaPlayer(10093): error (1, -2147483648)
08-22 13:08:03.168: …Run Code Online (Sandbox Code Playgroud) 如果尝试调用onUpgrade,我将尝试完全删除数据库。根据这个SO问题:如何以编程方式从Android删除SQLite数据库,我只能调用context.deleteDatabase(String dbName),但无法在onUpgrade方法中访问上下文。在onUpgrade中,传入了一个db对象,我看到您可以使用一个db.deleteDatabase()方法,但是它需要一个文件。我没有数据库文件。有什么办法db.deleteSelf或类似的方法吗?我知道我可以删除表等而不是完全删除数据库,但是我的数据库结构已经完全更改,我宁愿先调用deleteDb();然后onCreate(db);再调用。