有人可以帮助我,不管我做什么我无法解决这个应用程序无法正常工作的问题。我正在使用Android工作室。
我的Logcat
10-23 07:29:21.312 31399-31399/org.jaco.todo D/dalvikvm﹕ Late-enabling CheckJNI
10-23 07:29:21.512 31399-31402/org.jaco.todo D/dalvikvm﹕ GC_CONCURRENT freed 82K, 2% free 11049K/11271K, paused 11ms+0ms, total 16ms
10-23 07:29:21.532 31399-31399/org.jaco.todo D/AndroidRuntime﹕ Shutting down VM
10-23 07:29:21.536 31399-31399/org.jaco.todo W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa62d9288)
10-23 07:29:21.540 31399-31399/org.jaco.todo E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.jaco.todo/org.jaco.todo.TodoActivity}: java.lang.IllegalStateException: To use this functionality, add this to your AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: To use this functionality, add this to your AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
at com.parse.Parse.requirePermission(Parse.java:495)
at com.parse.ParseCommandCache.runEventuallyAsync(ParseCommandCache.java:250)
at com.parse.ParseAnalytics.trackAppOpened(ParseAnalytics.java:61)
at com.parse.ParseAnalytics.trackAppOpened(ParseAnalytics.java:32)
at org.jaco.todo.TodoActivity.onCreate(TodoActivity.java:41)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
... 11 more
10-23 07:29:58.452 31399-31399/? I/Process﹕ Sending signal. PID: 31399 SIG: 9
我的TodoActivity.java
public class TodoActivity extends Activity implements OnItemClickListener {
private EditText mTaskInput;
private ListView mListView;
private TaskAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_todo);
Parse.initialize(this, "9YsgDgjMOqulfH9JYXVWZG5a6EBVf1SbMyz7gXH4", "CZ60kHo0V9cG190DAoIhB781BL3mRfdy6FSSPy6D");
ParseAnalytics.trackAppOpened(getIntent());
ParseObject.registerSubclass(Task.class);
ParseUser currentUser = ParseUser.getCurrentUser();
if(currentUser == null){
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
}
mAdapter = new TaskAdapter(this, new ArrayList<Task>());
mTaskInput = (EditText) findViewById(R.id.task_input);
mListView = (ListView) findViewById(R.id.task_list);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
updateData();
}
public void updateData(){
ParseQuery<Task> query = ParseQuery.getQuery(Task.class);
query.whereEqualTo("user", ParseUser.getCurrentUser());
query.setCachePolicy(CachePolicy.CACHE_THEN_NETWORK);
query.findInBackground(new FindCallback<Task>() {
@Override
public void done(List<Task> tasks, ParseException error) {
if(tasks != null){
mAdapter.clear();
for (int i = 0; i < tasks.size(); i++) {
mAdapter.add(tasks.get(i));
}
}
}
});
}
public void createTask(View v) {
if (mTaskInput.getText().length() > 0){
Task t = new Task();
t.setACL(new ParseACL(ParseUser.getCurrentUser()));
t.setUser(ParseUser.getCurrentUser());
t.setDescription(mTaskInput.getText().toString());
t.setCompleted(false);
t.saveEventually();
mAdapter.insert(t, 0);
mTaskInput.setText("");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.todo, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.sign_in:
ParseUser.logOut();
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
return true;
}
return false;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Task task = mAdapter.getItem(position);
TextView taskDescription = (TextView) view.findViewById(R.id.task_description);
task.setCompleted(!task.isCompleted());
if(task.isCompleted()){
taskDescription.setPaintFlags(taskDescription.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}else{
taskDescription.setPaintFlags(taskDescription.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
task.saveEventually();
}
}
我的activity_todo.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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
tools:context=".TodoActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/task_input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="text"
android:hint="input_hint">
<requestFocus />
</EditText>
<Button
android:id="@+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="createTask"
android:text="submit_button" />
</LinearLayout>
<ListView
android:id="@+id/task_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.jaco.todo" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".TodoActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
有什么想法吗?
答案 0 :(得分:5)
在TodoActivity
文件中添加包含姓名的Manifest
课程,并添加下一个权限:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>