- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我试图获取实时板球得分,但我在启动文件中收到以下错误。有人可以帮我吗
05-31 08:35:56.833: D/AndroidRuntime(1089): Shutting down VM
05-31 08:35:56.833: W/dalvikvm(1089): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
05-31 08:35:56.843: E/AndroidRuntime(1089): FATAL EXCEPTION: main
05-31 08:35:56.843: E/AndroidRuntime(1089): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cricketscores/com.example.cricketscores.Launching}: java.lang.NullPointerException
05-31 08:35:56.843: E/AndroidRuntime(1089): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
05-31 08:35:56.843: E/AndroidRuntime(1089): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
05-31 08:35:56.843: E/AndroidRuntime(1089): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-31 08:35:56.843: E/AndroidRuntime(1089): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
05-31 08:35:56.843: E/AndroidRuntime(1089): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 08:35:56.843: E/AndroidRuntime(1089): at android.os.Looper.loop(Looper.java:137)
05-31 08:35:56.843: E/AndroidRuntime(1089): at android.app.ActivityThread.main(ActivityThread.java:5103)
05-31 08:35:56.843: E/AndroidRuntime(1089): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 08:35:56.843: E/AndroidRuntime(1089): at java.lang.reflect.Method.invoke(Method.java:525)
05-31 08:35:56.843: E/AndroidRuntime(1089): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
05-31 08:35:56.843: E/AndroidRuntime(1089): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-31 08:35:56.843: E/AndroidRuntime(1089): at dalvik.system.NativeStart.main(Native Method)
05-31 08:35:56.843: E/AndroidRuntime(1089): Caused by: java.lang.NullPointerException
05-31 08:35:56.843: E/AndroidRuntime(1089): at com.example.cricketscores.Launching.onCreate(Launching.java:52)
05-31 08:35:56.843: E/AndroidRuntime(1089): at android.app.Activity.performCreate(Activity.java:5133)
05-31 08:35:56.843: E/AndroidRuntime(1089): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-31 08:35:56.843: E/AndroidRuntime(1089): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
05-31 08:35:56.843: E/AndroidRuntime(1089): ... 11 more
这是代码
public class Launching extends Activity {
private List<Match> matches = new ArrayList<Match>();
private MatchesReceiver receiver;
private IntentFilter filter;
private MatchListState oldState;
private MatchAdapter matchAdapter;
private long lastUpdate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CricScoreApplication.getInstance().setMatchListState(MatchListState.LOADING);
startService(new Intent(this, MatchUpdateService.class));
this.receiver = new MatchesReceiver();
this.filter = new IntentFilter(GenericProperties.INTENT_ML_UPDATE);
this.matchAdapter = new MatchAdapter(this);
this.oldState = MatchListState.LOADING;
RunningInfo.clearSession(getApplicationContext());
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onResume() {
super.onResume();
updateScreen();
registerReceiver(receiver, filter);
}
private void updateScreen() {
Log.i(GenericProperties.TAG, "updating screen");
MatchListState state = CricScoreApplication.getInstance()
.getMatchListState();
Resources resources = getResources();
if (MatchListState.LOADING.equals(state)) {
setContentView(R.layout.launching_loading);
Log.i(GenericProperties.TAG, "updating screen - loading");
} else if (MatchListState.LOADED.equals(state)) {
showMatches();
Log.i(GenericProperties.TAG, "updating screen - show matches");
} else if (MatchListState.NODATA.equals(state)) {
showErrorScreen(resources.getString(R.string.error_title_nodata), resources.getString(R.string.error_msg_nodata));
Log.i(GenericProperties.TAG, "updating screen - show error - nodata");
} else if (MatchListState.NOMATCH.equals(state)) {
showErrorScreen(resources.getString(R.string.error_title_nomatch), resources.getString(R.string.error_msg_nomatch));
Log.i(GenericProperties.TAG, "updating screen - show error - nomatch");
} else if (MatchListState.NOTSUPPORTED.equals(state)) {
showErrorScreen(resources.getString(R.string.error_title_nosupport), resources.getString(R.string.error_msg_nosupport));
Log.i(GenericProperties.TAG, "updating screen - show error - nosupport");
} else if (MatchListState.APPERROR.equals(state)){
showErrorScreen(resources.getString(R.string.error_title_apperror), resources.getString(R.string.error_msg_apperror));
Log.i(GenericProperties.TAG, "updating screen - show error - apperror");
}
oldState = state;
Log.i(GenericProperties.TAG, "updating screen ended");
}
@Override
public void onPause() {
super.onPause();
unregisterReceiver(receiver);
}
@Override
public void onStop() {
super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
stopService(new Intent(this, ScoreUpdateService.class));
}
private class MatchesReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
long start = System.currentTimeMillis();
if(GenericProperties.INTENT_ML_UPDATE.equals(intent.getAction())){
updateScreen();
}
long time = System.currentTimeMillis() - start;
Log.i(GenericProperties.TAG, "On Receive Time Taken : " + time
+ " ms");
}
}
private void showErrorScreen(String title, String message) {
if(MatchListState.LOADING.equals(oldState) || MatchListState.LOADED.equals(oldState)){
setContentView(R.layout.launching_error);
}
Log.v(GenericProperties.TAG, title + " "+ message);
TextView tilteTextView = (TextView)findViewById(R.id.title);
tilteTextView.setText(title);
TextView messageTextView = (TextView)findViewById(R.id.message_body);
messageTextView.setText(message);
Log.v(GenericProperties.TAG, " "+ messageTextView.getText());
Log.v(GenericProperties.TAG, " "+ messageTextView.getTextSize());
}
private void showMatches() {
if(!oldState.equals(MatchListState.LOADED)){
setContentView(R.layout.matchlist);
final ListView l1 = (ListView) findViewById(R.id.ListMatches);
//l1.set
l1.setAdapter(matchAdapter);
l1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
int mid = ((Match) l1.getItemAtPosition(position)).getMatchId();
openLiveScore(mid);
openScoreUpdateService(mid);
}
});
}
long newUpdateTime = CricScoreApplication.getInstance().getMatchListUpdateTime();
if(newUpdateTime != this.lastUpdate){
CricScoreDBAdapter adapter = new CricScoreDBAdapter(
getApplicationContext());
adapter.open();
this.matches = adapter.getMatches();
adapter.close();
this.matchAdapter.notifyDataSetChanged();
if(this.lastUpdate!=0){
Toast.makeText(getApplicationContext(), R.string.toast_update, Toast.LENGTH_SHORT).show();
}
this.lastUpdate = newUpdateTime;
}
}
private void openScoreUpdateService(int mid) {
Intent serviceIntent = new Intent(
GenericProperties.INTENT_START_UPDATE);
serviceIntent.putExtra("matchId", mid);
startService(serviceIntent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.launching_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.hide:
moveTaskToBack(false);
return true;
case R.id.exit:
//alertAndClose();
Launching.this.finish();
return true;
case R.id.feedback:
Launching.this.feedback();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void feedback() {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"spriyan@mychoize.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "MyChoize CricScore: Feedback");
i.putExtra(Intent.EXTRA_TEXT , "Please provide your feedback for improvement of CricScore app here.");
i.setType("message/rfc822");
startActivity(Intent.createChooser(i, "Send Feedback"));
}
private void openLiveScore(int id) {
Intent myIntent = new Intent(this, LiveScore.class);
myIntent.putExtra(GenericProperties.EXTRA_MATCHID, id);
startActivity(myIntent);
}
public void alertAndClose() {
Resources resources = getResources();
String str = resources.getString(R.string.confirm_exit);
String exit = resources.getString(R.string.exit);
String cancel = resources.getString(R.string.cancel);
String hide = resources.getString(R.string.hide);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(str);
builder.setCancelable(true);
builder.setNeutralButton(cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.setPositiveButton(exit, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Launching.this.finish();
}
});
builder.setNegativeButton(hide, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
moveTaskToBack(false);
}
});
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onBackPressed() {
alertAndClose();
return;
}
private class MatchAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public MatchAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return Launching.this.matches.size();
}
public Object getItem(int position) {
return matches.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.matchview, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.TeamOne);
holder.text2 = (TextView) convertView
.findViewById(R.id.TeamTwo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
try {
Match match = matches.get(position);
holder.text.setText(match.getTeamOne());
holder.text2.setText(match.getTeamTwo());
} catch (ArrayIndexOutOfBoundsException e) {
}
return convertView;
}
class ViewHolder {
TextView text;
TextView text2;
}
}
}
*更新*
CricScoreApplication.java
public class CricScoreApplication extends Application {
private static CricScoreApplication singleton;
private MatchListState matchListState;
private long matchListUpdateTime;
private ScoreUpdateState scoreUpdateState;
private long scoreUpdateTime;
private boolean liveOn;
public static CricScoreApplication getInstance(){
return singleton;
}
@Override
public void onCreate() {
super.onCreate();
singleton = this;
this.matchListState = MatchListState.LOADING;
this.matchListUpdateTime = 0;
}
public MatchListState getMatchListState() {
return matchListState;
}
public void setMatchListState(MatchListState matchListState) {
this.matchListState = matchListState;
}
public long getMatchListUpdateTime() {
return matchListUpdateTime;
}
public void setMatchListUpdateTime(long matchListUpdateTime) {
this.matchListUpdateTime = matchListUpdateTime;
}
public ScoreUpdateState getScoreUpdateState() {
return scoreUpdateState;
}
public void setScoreUpdateState(ScoreUpdateState scoreUpdateState) {
this.scoreUpdateState = scoreUpdateState;
this.scoreUpdateTime = System.currentTimeMillis();
}
public long getScoreUpdateTime() {
return scoreUpdateTime;
}
public void clearScoreUpdateState(){
this.scoreUpdateState = null;
this.scoreUpdateTime = 0L;
}
public boolean isLiveOn() {
//System.out.println("getting value "+liveOn);
return liveOn;
}
public void setLiveOn(boolean liveOn) {
//System.out.println("setting value " +liveOn);
this.liveOn = liveOn;
}
}
list
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cricketscores"
android:versionCode="7"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application android:icon="@drawable/icon" android:label="@string/app_name" android:allowBackup="true" >
<activity android:name=".Launching" android:multiprocess="false" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Info" android:label="@string/title_info"></activity>
<activity android:name=".activity.SmsFeature" android:label="@string/title_sms_feature"></activity>
<activity android:name=".LiveScore" android:label="@string/title_live_score" android:launchMode="singleTask"></activity>
<activity android:name=".activity.UserPreference" android:label="@string/title_user_preference"></activity>
<service android:name=".MatchUpdateService" android:enabled="true"></service>
<service android:name=".ScoreUpdateService" android:enabled="true">
<intent-filter>
<action android:name="com.example.cricketscores.START_UPDATE" />
<action android:name="com.example.cricketscores.STOP_UPDATE" />
<action android:name="com.example.cricketscores.UPDATE_VALUES" />
</intent-filter>
</service>
</application>
</manifest>
感谢帮助
最佳答案
扩展 Application
类时,您不需要使用经典的单例方法。相反,如果您的 list 设置正确,您可以:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//notice the change
CricScoreApplication app = (CricScoreApplication)getApplication();
app.setMatchListState(MatchListState.LOADING);
startService(new Intent(this, MatchUpdateService.class));
this.receiver = new MatchesReceiver();
this.filter = new IntentFilter(GenericProperties.INTENT_ML_UPDATE);
this.matchAdapter = new MatchAdapter(this);
this.oldState = MatchListState.LOADING;
RunningInfo.clearSession(getApplicationContext());
}
要使其工作,您需要将此类指向要在 Application
基类上使用的类。这是在 list 中完成的:
<application ... android:name="com.example.cricketscores.CricScoreApplication" >
P.S:如果您确实想使用 getInstance()
方法,它应该如下所示:
public static CricScoreApplication getInstance(Context ctx){
return (CricScoreApplication)(ctx.getApplication());
}
关于java - 应用程序中的 Android 运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23970199/
好的,所以我想从批处理文件运行我的整个工作环境... 我想要实现什么...... 打开新的 powershell,打开我的 API 文件夹并从该文件夹运行 VS Code 编辑器(cd c:\xy;
我正在查看 Cocoa Controls 上的示例并下载了一些演示。我遇到的问题是一些例子,比如 BCTabBarController ,不会在我的设备上构建或启动。当我打开项目时,它看起来很正常,没
我刚刚开始学习 C 语言(擅长 Java 和 Python)。 当编写 C 程序(例如 hello world)时,我在 ubuntu cmd 行上使用 gcc hello.c -o hello 编译
我在 php 脚本从 cron 开始运行到超时后注意到了这个问题,但是当它从命令行手动运行时这不是问题。 (对于 CLI,PHP 默认的 max_execution_time 是 0) 所以我尝试运行
我可以使用命令行运行测试 > ./node_modules/.bin/wdio wdio.conf.js 但是如果我尝试从 IntelliJ 的运行/调试配置运行它,我会遇到各种不同的错误。 Fea
Error occurred during initialization of VM. Could not reserve enough space for object heap. Error: C
将 Anaconda 安装到 C:\ 后,我无法打开 jupyter 笔记本。无论是在带有 jupyter notebook 的 Anaconda Prompt 中还是在导航器中。我就是无法让它工作。
我遇到一个问题,如果我双击我的脚本 (.py),或者使用 IDLE 打开它,它将正确编译并运行。但是,如果我尝试在 Windows 命令行中运行脚本,请使用 C:\> "C:\Software_Dev
情况 我正在使用 mysql 数据库。查询从 phpmyadmin 和 postman 运行 但是当我从 android 发送请求时(它返回零行) 我已经记录了从 android 发送的电子邮件是正确
所以这个有点奇怪 - 为什么从 Java 运行 .exe 文件会给出不同的输出而不是直接运行 .exe。 当 java 在下面的行执行时,它会调用我构建的可与 3CX 电话系统配合使用的 .exe 文
这行代码 Environment.Is64BitProcess 当我的应用单独运行时评估为真。 但是当它在我的 Visual Studio 单元测试中运行时,相同的表达式的计算结果为 false。 我
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improve
我写了一个使用 libpq 连接到 PostgreSQL 数据库的演示。 我尝试通过包含将 C 文件连接到 PostgreSQL #include 在我将路径添加到系统变量 I:\Program F
如何从 Jenkins 运行 Android 模拟器来运行我的测试?当我在 Execiute Windows bath 命令中写入时,运行模拟器的命令: emulator -avd Tester 然后
我已经配置好东西,这样我就可以使用 ssl 登录和访问在 nginx 上运行的 errbit 我的问题是我不知道如何设置我的 Rails 应用程序的 errbit.rb 以便我可以运行测试 nginx
我编写了 flutter 应用程序,我通过 xcode 打开了 ios 部分并且应用程序正在运行,但是当我通过 flutter build ios 通过 vscode 运行应用程序时,我得到了这个错误
我有一个简短的 python 脚本,它使用日志记录模块和 configparser 模块。我在Win7下使用PyCharm 2.7.1和Python 3.3。 当我使用 PyCharm 运行我的脚本时
我在这里遇到了一些难题。 我的开发箱是 64 位的,windows 7。我所有的项目都编译为“任何 CPU”。该项目引用了 64 位版本的第 3 方软件 当我运行不使用任何 Web 引用的单元测试时,
当我注意到以下问题时,我正在做一些 C++ 练习。给定的代码将不会在 Visual Studio 2013 或 Qt Creator 5.4.1 中运行/编译 报错: invalid types 'd
假设我有一个 easteregg.py 文件: from airflow import DAG from dateutil import parser from datetime import tim
我是一名优秀的程序员,十分优秀!