- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为另一个问题道歉,但似乎我又陷入了死胡同。我的应用程序已经在两个独立的项目中进行了测试,它们运行良好。但是,将它们组合后,我在打开应用程序时遇到致命异常错误。我花了最后几个小时试图解决问题并研究解决方案,但到目前为止没有任何效果。请记住,我是编程新手,不确定问题出在哪里。
也为这么多代码道歉。我确实考虑过只发布错误日志,但不确定代码或 xml 文件是否有用。代码确实工作正常,我已经在个别项目中对其进行了测试,但是在仔细组合代码之后,由于某种原因,它出现了这个错误。谢谢!!!
编辑:解决了评论中的问题。可能会很快删除问题。感谢看过的人:)
错误日志
03-20 02:08:54.761: E/AndroidRuntime(12530): FATAL EXCEPTION: main
03-20 02:08:54.761: E/AndroidRuntime(12530): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.motionsense/com.example.motionsense.MainActivity}: java.lang.NullPointerException
03-20 02:08:54.761: E/AndroidRuntime(12530): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2517)
03-20 02:08:54.761: E/AndroidRuntime(12530): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2574)
03-20 02:08:54.761: E/AndroidRuntime(12530): at android.app.ActivityThread.access$600(ActivityThread.java:162)
03-20 02:08:54.761: E/AndroidRuntime(12530): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1413)
03-20 02:08:54.761: E/AndroidRuntime(12530): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 02:08:54.761: E/AndroidRuntime(12530): at android.os.Looper.loop(Looper.java:158)
03-20 02:08:54.761: E/AndroidRuntime(12530): at android.app.ActivityThread.main(ActivityThread.java:5789)
03-20 02:08:54.761: E/AndroidRuntime(12530): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 02:08:54.761: E/AndroidRuntime(12530): at java.lang.reflect.Method.invoke(Method.java:525)
03-20 02:08:54.761: E/AndroidRuntime(12530): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
03-20 02:08:54.761: E/AndroidRuntime(12530): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:843)
03-20 02:08:54.761: E/AndroidRuntime(12530): at dalvik.system.NativeStart.main(Native Method)
03-20 02:08:54.761: E/AndroidRuntime(12530): Caused by: java.lang.NullPointerException
03-20 02:08:54.761: E/AndroidRuntime(12530): at com.example.motionsense.SaveTimer.<init>(SaveTimer.java:18)
03-20 02:08:54.761: E/AndroidRuntime(12530): at com.example.motionsense.MainActivity.onCreate(MainActivity.java:66)
03-20 02:08:54.761: E/AndroidRuntime(12530): at android.app.Activity.performCreate(Activity.java:5195)
03-20 02:08:54.761: E/AndroidRuntime(12530): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
03-20 02:08:54.761: E/AndroidRuntime(12530): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2473)
03-20 02:08:54.761: E/AndroidRuntime(12530): ... 11 more
03-20 02:08:55.963: D/Process(12530): killProcess, pid=12530
03-20 02:11:57.106: W/asset(12774): Copying FileAsset 0x69a900f8 (zip:/data/app/com.example.motionsense-2.apk:/resources.arsc) to buffer size 2312 to make it aligned.
03-20 02:11:57.156: W/dalvikvm(12774): threadid=1: thread exiting with uncaught exception (group=0x4169d970)
程序
package com.example.motionsense;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class MainActivity extends ListActivity implements SensorEventListener {
//private FragmentActivity mClass;
private List<String> item = null;
private List<String> path = null;
private String root;
private TextView myPath;
Timer timer = new Timer();
File myFile;
FileOutputStream fOut;
OutputStreamWriter myOutWriter;
BufferedWriter myBufferedWriter;
PrintWriter myPrintWriter;
ArrayList<String> motionData;
float[] acceleration = new float[3];
float[] rotationRate = new float[3];
float[] magneticField = new float[3];
boolean startScan = false;
boolean isFirstSet = true;
private SensorManager sensorManager;
private long currentTime;
private long startTime;
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//get file directory
myPath = (TextView)findViewById(R.id.path);
//root = Environment.getExternalStorageDirectory().getPath();
root = getFilesDir().getPath();
//set save data timer
SaveTimer savetimer = new SaveTimer(motionData, this);
timer.schedule(savetimer, 1000, 60000);
getDir(root);
}
private void getDir(String dirPath)
{
myPath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for(int i=0; i < files.length; i++)
{
File file = files[i];
if(!file.isHidden() && file.canRead()){
path.add(file.getPath());
if(file.isDirectory()){
item.add(file.getName() + "/");
}else{
item.add(file.getName());
}
}
}
ArrayAdapter<String> fileList =
new ArrayAdapter<String>(this, R.layout.row, item);
setListAdapter(fileList);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
File file = new File(path.get(position));
if (file.isDirectory())
{
if(file.canRead()){
getDir(path.get(position));
}else{
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "] folder can't be read!")
.setPositiveButton("OK", null).show();
}
}else {
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "]")
.setPositiveButton("OK", null).show();
}
}
@Override
public void onSensorChanged (SensorEvent event) {
//
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
acceleration[0] = event.values[0];
acceleration[1] = event.values[1];
acceleration[2] = event.values[2];
}
if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
rotationRate[0] = event.values[0];
rotationRate[1] = event.values[1];
rotationRate[2] = event.values[2];
}
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
magneticField[0] = event.values[0];
magneticField[1] = event.values[1];
magneticField[2] = event.values[2];
}
if (isFirstSet) {
startTime = System.currentTimeMillis();
isFirstSet = false;
}
currentTime = System.currentTimeMillis();
record();
}
private void record() {
motionData.add("Acceleration= " + "X: " + acceleration[0] + " " + "Y: " + acceleration[1] + " " + "Z: " + acceleration[2] + "\n "
+ "GyroScope= " + " " + "X: " + rotationRate[0] + " " + "Y: " + rotationRate[1] + " " + "Z: " + rotationRate[2] + "\n "
+ "Magnetic Field= " + " " + "X: " + magneticField[0] + " " + "Y: " + magneticField[1] + " " + "Z: " + magneticField[2] + "\n\n");
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
}
XML 文件 1:Activity_Main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="No Data"
/>
</LinearLayout>
XML 文件 2:行.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rowtext"
android:layout_width="fill_parent"
android:layout_height="30sp"
android:textSize="25sp" />
最佳答案
SaveTimer savetimer = new SaveTimer(motionData, this);
motionData
为null
,你还没初始化?
关于Java.lang.RuntimeException : Unable to start activity ComponentInfo Error in Android 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22522738/
我正在尝试为 Android 设置 JUnit 测试并且我有 list 等设置但我不断收到此错误: java.lang.RuntimeException: Unable to instantiate
我的问题是当我运行应用程序并单击注册按钮时突然显示弹出窗口:“强制关闭” 这是我的代码: Main.java package com.example.server; import java.util.
当我运行我的 Activity registeration.java 或 login.java 时,它将 Intent 中的用户名传递给名为 profile.java 的新 Activity > 关于
这个问题已经有答案了: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo (47 个回答) 已关闭 8
以下 Android Studio 1.5 MainActivity.java 代码会在标题中生成错误,并带有 You need to use a Theme.AppCompat theme publ
尝试从文本消息 URL 在 Android 上启动 Xamarin 表单应用程序时,我收到此错误。我一直在遵循 THIS 中提到的步骤文章。 这里是我 AppManifest.xml 中的应用程序节点
我在我的应用程序中创建了一个 map View ,但出现了这个错误: 09-07 21:24:08.886: INFO/ActivityManager(243): Starting: Intent {
我的应用程序运行正常,但当应用程序进入后台时,它在应该恢复时崩溃了。正如您在源代码中看到的那样,我记录了 onStart、onStop 等事件。 在我的日志中,当我启动应用程序时,我可以看到 onSt
我正在处理从其他人那里导入的 Android 项目。我已经对所有依赖项进行排序,项目中没有错误,但是当我尝试启动它时,我得到: 04-08 16:49:41.761: E/AndroidRuntime
在我的应用程序中,当我选择按钮时,它会将我指向 mapView 类,它会显示用户的当前位置。 但是,它抛出 java.lang.RuntimeException: Unable to instanti
我在开发 Android 应用程序时遇到问题。我首先对我的错误进行了研究,然后发现还有其他人和我有同样的问题。我阅读了所有评论并尝试了所有方法,但我仍然遇到同样的错误。 这里是我的错误 05-29 1
我有一个 Google 云消息的接收器,它已在 AndroidManifest.xml 中注册:
我正在开发一个应用程序,最低版本为 Froyo,目标版本为 Gingerbread。因此, list 显示: 我有一个模拟器和一个带有 Gingerbread 的 Nexus One,应用程序部署和
我正在尝试将其作为我的主要 Activity 以打开另一个 Activity (ListAtivity)。但是,当我单击按钮时,应用程序崩溃并出现以下异常: 01-26 17:12:58.341: E
我正在制作一个可以搜索表“员工”并返回结果的应用程序。我正在使用 searchdialog 进行搜索。但是我在搜索对话框上按下搜索按钮时得到了 FC。请帮帮我。 代码: public class Si
我是 Android 开发的新手,所以我确信这会变成我错过的愚蠢的事情,但我有两个 Activity :StartScreen 和 Map。 StartScreen 只是简单的文本和一个按钮,然后应该
我修改了来自 http://www.elektor.com/magazines/2012/march/android-switch-interface.2084156.lynkx 的示例蓝牙通信应用程
我创建了一个应用程序,该应用程序应该从我的Thingspeak channel 接收数据。 首先,我只是使用了webview小部件,但我想走得更远,并使用Thingspeak Java api自己处理
可以找到 list 文件here . 可以找到DeviceAdminReceiver类here agent_device_xml 定义如下:
01-05 18:35:42.754: E/AndroidRuntime(5814): java.lang.RuntimeException: 无法实例化 Activity ComponentInfo
我是一名优秀的程序员,十分优秀!