我是一個Android開發初學者。
我使用parse.com
從服務器和列表視圖中檢索數據以顯示活動主頁中的數據。
但是,當我打開我的應用程序時,它崩潰。我的Android應用程序崩潰,當我打開應用程序(不幸的應用程序已停止)
我已經正確地初始化了所有東西,但仍然無法正常工作。
出於安全原因,我已從此代碼刪除parse.initialize(keys)
。
package com.example.sangram.nearbyapp;
import android.app.Activity;
import android.app.ListActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.parse.FindCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import java.util.List;
public class HomepageActivity extends ListActivity {
protected List<ParseObject> mprofessional;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homepage);
ParseUser currentUser = ParseUser.getCurrentUser();
if(currentUser!=null)
{
//show user homepage
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Professionals");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> professional, ParseException e) {
if(e==null)
{
//success
mprofessional = professional;
ProfessionalAdaptor adaptor = new ProfessionalAdaptor(getListView().getContext(),mprofessional);
setListAdapter(adaptor);
}
else
{
//there is a problem
}
}
});
}
else
{
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
professionaladapter.java
package com.example.sangram.nearbyapp;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.parse.Parse;
import com.parse.ParseObject;
import java.util.List;
/**
* Created by SANGRAM on 12/04/2015.
*/
public class ProfessionalAdaptor extends ArrayAdapter <ParseObject> {
protected Context mcontext;
protected List<ParseObject> mProfessionals;
public ProfessionalAdaptor(Context context, List<ParseObject> professionals)
{
super(context, R.layout.homepagecustomlayout, professionals);
mcontext= context;
mProfessionals=professionals;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if(convertView==null)
{
convertView = LayoutInflater.from(mcontext).inflate(R.layout.homepagecustomlayout, null);
holder = new ViewHolder();
holder.namehomepage = (TextView) convertView.findViewById(R.id.userhp);
holder.prohomepage = (TextView) convertView.findViewById(R.id.prohp);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
ParseObject statusObject = mProfessionals.get(position);
String pname = statusObject.getString("Name");
holder.namehomepage.setText(pname);
String ppro = statusObject.getString("Profession");
holder.prohomepage.setText(ppro);
return convertView;
}
public static class ViewHolder
{
TextView namehomepage; // name of professional from parse database
TextView prohomepage; // name of profession from parse
}
}
清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sangram.nearbyapp" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".HomepageActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RegisterActivity"
android:label="@string/title_activity_login" >
</activity>
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login" >
</activity>
</application>
</manifest>
logcat的
12月4日至15日:52:22.287 1784年至1784年/ com.example.sangram。 nearbyapp E/ResourceType:樣式包含鍵入錯誤的鍵:0x01010479 04-15 12:52:32.707 1784-1784/com.example.sangram.nearbyapp E/ResourceType:樣式包含具有錯誤條目的鍵:0x01010479 04-15 12:52:32.757 1784-1784/com.example.sangram .nearbyapp E/AndroidRuntime:致命例外:main java.lang.RuntimeException:無法啓動活動ComponentInfo {com.example.sangram.nearbyapp/com.example.sangram.nearbyapp.HomepageActivity}:java.lang.RuntimeException:您的內容必須在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 上的android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 處有一個List屬性爲'android.R.id.list'的ID屬性爲'android.R.id.list' 在android.app.ActivityThread.access $ 600(ActivityThread.java:141) at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:123 4) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5039) (Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit .java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) 引起:java.lang.RuntimeException:您的內容必須有一個ListView,其id屬性是android.app.ListActivity.onContentChanged(ListActivity.jav)上的'android.R.id.list' a:243) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273) at com.example.sangram上的android.app.Activity.setContentView(Activity.java:1881) 。 nearby.HomepageActivity.onCreate(HomepageActivity.java:26) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app。 ActivityThread.performLaunchActivity(ActivityThread.java:2144) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 在android.app.ActivityThread.access $ 600(ActivityThread.java:141) 在android.app.Acti vityThread $ H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper。java:137) at android.app.ActivityThread.main(ActivityThread.java:5039) 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:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system .NativeStart.main(本地方法) 04-15 12:53:18.019 1865-1865/com.example.sangram.nearbyapp E/ResourceType:Style包含具有錯誤條目的鍵:0x01010479
和哪裏是你的logcat的? –
我的應用程序不工作它崩潰,所以我從模擬器卸載我現在無法找到logcat –
你必須發佈你的logcat,否則沒有人可以幫助你。 – Soham