所以我试图运行Quickblox
sample chat和XMPP Sample Chat。
我正在使用Eclipse和最新的Android sdk / build。
导入示例后,Quickblox指南告诉我,我在代码中有一些错误,但没有多少导入丢失,但是当我试图运行应用程序时出现错误,应用程序安装正确但在错误开始弹出Logcat后正确。
public class SplashActivity extends Activity implements QBCallback {
private static final String APP_ID = "6445";
private static final String AUTH_KEY = "9a4bnSXbP-KN9G8";
private static final String AUTH_SECRET = "FwunQpKdkE2e7AJ";
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
QBSettings.getInstance().fastConfigInit(APP_ID, AUTH_KEY, AUTH_SECRET);
QBAuth.createSession(this);
}
@Override
public void onComplete(Result result) {
progressBar.setVisibility(View.GONE);
if (result.isSuccess()) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
} else {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("Error(s) occurred. Look into DDMS log for details, " +
"please. Errors: " + result.getErrors()).create().show();
}
}
@Override
public void onComplete(Result result, Object context)
{
}
}
public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
private static final int AUTHENTICATION_REQUEST = 1;
private static final int POSITION_USER = 0;
private static final int POSITION_ROOM = 1;
private SectionsPagerAdapter sectionsPagerAdapter;
private ViewPager viewPager;
private Action lastAction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
List<Fragment> tabs = new ArrayList<Fragment>();
tabs.add(UsersFragment.getInstance());
tabs.add(RoomsFragment.getInstance());
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), tabs);
viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < sectionsPagerAdapter.getCount(); i++) {
actionBar.addTab(actionBar.newTab()
.setText(sectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
int position = tab.getPosition();
QBUser qbUser = ((App) getApplication()).getQbUser();
if (qbUser != null) {
viewPager.setCurrentItem(position);
} else if (position == POSITION_ROOM) {
lastAction = Action.ROOM_LIST;
showAuthenticateDialog();
}
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (lastAction) {
case CHAT:
((UsersFragment) sectionsPagerAdapter.getItem(POSITION_USER)).startChat();
break;
case ROOM_LIST:
viewPager.setCurrentItem(POSITION_ROOM);
break;
}
((RoomsFragment) sectionsPagerAdapter.getItem(POSITION_ROOM)).loadRooms();
} else {
showUsersFragment();
}
}
private void showUsersFragment() {
getSupportActionBar().selectTab(getSupportActionBar().getTabAt(POSITION_USER));
viewPager.setCurrentItem(POSITION_USER);
}
public void setLastAction(Action lastAction) {
this.lastAction = lastAction;
}
public void showAuthenticateDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Authorize first");
builder.setItems(new String[]{"Login", "Register"}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivityForResult(intent, AUTHENTICATION_REQUEST);
break;
case 1:
intent = new Intent(MainActivity.this, RegistrationActivity.class);
startActivityForResult(intent, AUTHENTICATION_REQUEST);
break;
}
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
showUsersFragment();
}
});
builder.show();
}
public static enum Action {CHAT, ROOM_LIST}
public static class SectionsPagerAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments;
public SectionsPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case POSITION_USER:
return "Users";
case POSITION_ROOM:
return "Rooms";
}
return null;
}
}}
我的清单文件是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.quickblox.sample.chat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".App"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.quickblox.sample.chat.ui.activities.SplashActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activities.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAINMENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.activities.ChatActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".ui.activities.LoginActivity"
android:label="Login" />
<activity
android:name=".ui.activities.RegistrationActivity"
android:label="Registration" />
</application>
</manifest>
这是我的错误消息:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.quickblox.sample.chat/com.quickblox.sample.chat.ui.activities.SplashActivity}: java.lang.ClassNotFoundException: com.quickblox.sample.chat.ui.activities.SplashActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
答案 0 :(得分:1)
打开属性 - &gt; Java构建路径 - &gt;订购和导出并检查QB jar库。根据日志,您尚未将其添加到构建中。
答案 1 :(得分:1)
1)首先确保您已经在名为jar的文件夹中导入了Quickblox SDK附带的“quickblox-android-1.2.2.jar”,然后右键单击项目 - &gt;属性 - &gt;得到Java Build Path - &gt;订单和出口 - &gt;只需检查quickblox-android-1.2.2.jar(在列表中未选中) - &gt;单击“确定”。
2)只需清理项目并运行它。
注意: - 如果在步骤1之后没有清理项目,那么项目将崩溃,因此在运行之前清理项目。