【安卓】搞不懂安卓开发的版本和jar包问题!!

android的界面开发真是难得一哔————————,我越来越搞不懂它了,只要版本不对就什么都运行不了OTZ。有时候又会不知情况地R文件生成不了了,听说是ADT版本的问题,更新了一下,貌似行了,之后又继续出问题了,一时候这个The following classes could not be found,一时候又建不了activity。之后百度了好多下,发现好像是appcompat的问题,我就手贱把它删了,删了!之后每次运行都报错,程序根本运不出来。本人是小白,发现了android开发的众多规矩之后更白了。
所以来这请教各位大侠,看看我这到底出了什么问题(P.S.程序中是没有明显错误的),谢谢!!!!

12-02 08:26:10.114: D/AndroidRuntime(859): Shutting down VM

12-02 08:26:10.114: W/dalvikvm(859): threadid=1: thread exiting with uncaught exception (group=0x40a71930)

12-02 08:26:10.194: E/AndroidRuntime(859): FATAL EXCEPTION: main

12-02 08:26:10.194: E/AndroidRuntime(859): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flipfree/com.example.flipfree.MainActivity}: java.lang.ClassCastException: [email protected] must implement OnFragmentInteractionListener

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.ActivityThread.access$600(ActivityThread.java:141)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.os.Handler.dispatchMessage(Handler.java:99)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.os.Looper.loop(Looper.java:137)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.ActivityThread.main(ActivityThread.java:5041)

12-02 08:26:10.194: E/AndroidRuntime(859): at java.lang.reflect.Method.invokeNative(Native Method)

12-02 08:26:10.194: E/AndroidRuntime(859): at java.lang.reflect.Method.invoke(Method.java:511)

12-02 08:26:10.194: E/AndroidRuntime(859): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

12-02 08:26:10.194: E/AndroidRuntime(859): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)

12-02 08:26:10.194: E/AndroidRuntime(859): at dalvik.system.NativeStart.main(Native Method)

12-02 08:26:10.194: E/AndroidRuntime(859): Caused by: java.lang.ClassCastException: [email protected] must implement OnFragmentInteractionListener

12-02 08:26:10.194: E/AndroidRuntime(859): at com.example.flipfree.SearchPage.onAttach(SearchPage.java:83)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:844)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.BackStackRecord.run(BackStackRecord.java:682)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.Activity.performStart(Activity.java:5113)

12-02 08:26:10.194: E/AndroidRuntime(859): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)

12-02 08:26:10.194: E/AndroidRuntime(859): ... 11 more

12-02 08:26:35.334: I/Process(859): Sending signal. PID: 859 SIG: 9

运行程序之后就unfortunately了,顺便贴一下AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.flipfree"

android:versionCode="1"

android:versionName="1.0" >

<uses-sdk

android:minSdkVersion="11"

android:targetSdkVersion="17" />

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name=".MainActivity"

android:label="@string/title_activity_main" >

</activity>

</application>

</manifest>

还有一些界面的class用不了
【安卓】搞不懂安卓开发的版本和jar包问题!!

MainActivity.java

package com.example.flipfree;

import android.app.Activity;

import android.app.FragmentManager;

import android.app.FragmentTransaction;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.Window;

import android.widget.ImageButton;

import android.widget.LinearLayout;

public class MainActivity extends Activity implements OnClickListener {

//three tab, each button for each tab

private LinearLayout mTabSearch;

private LinearLayout mTabCollection;

private LinearLayout mTabSetting;

//three buttons

private ImageButton mSearchBtn;

private ImageButton mCollectionBtn;

private ImageButton mSettingBtn;

private SearchPage searchF;

private SettingPage settingF;

private CollectionPage collectionF;

private FragmentManager fm;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.activity_main);

mTabSearch = (LinearLayout) findViewById(R.id.bottom_tab_1);

mTabCollection = (LinearLayout) findViewById(R.id.bottom_tab_2);

mTabSetting = (LinearLayout) findViewById(R.id.bottom_tab_3);

mTabSearch.setOnClickListener(this);

mTabCollection.setOnClickListener(this);

mTabSetting.setOnClickListener(this);

// Set the default fragment that first comes out

setDefaultFragment();

}

private void setDefaultFragment() {

// TODO Auto-generated method stub

fm = getFragmentManager();

FragmentTransaction transaction = fm.beginTransaction();

searchF = new SearchPage();

transaction.replace(R.id.id_content, searchF);

transaction.commit();

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.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();

if (id == R.id.action_settings) {

return true;

}

return super.onOptionsItemSelected(item);

}

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

fm = getFragmentManager();

// ¿ªÆôFragmentÊÂÎñ

FragmentTransaction transaction = fm.beginTransaction();

switch (v.getId())

{

case R.id.bottom_tab_1:

if (searchF == null)

{

searchF = new SearchPage();

}

transaction.replace(R.id.id_content, searchF);

break;

case R.id.bottom_tab_2:

if (collectionF == null)

{

collectionF = new CollectionPage();

}

transaction.replace(R.id.id_content, collectionF);

break;

case R.id.bottom_tab_3:

if (settingF == null)

{

settingF = new SettingPage();

}

transaction.replace(R.id.id_content, settingF);

break;

}

transaction.commit();

}

}

已解决。
不知道是不是原本就是自定义class没有导入,令xml class cannot be found报错而产生的问题,还是我把implements OnClickListener(还是什么鬼)和Fragment里的一堆东西从fragment中移除的原因,反正改了一些代码以及导入了自定义class之后工程就能运行了。http://segmentfault.com/q/1010000004093236?_ea=487504

最后:怎么关闭问题?

回答

Caused by: java.lang.ClassCastException: [email protected] must implement OnFragmentInteractionListener

12-02 08:26:10.194: E/AndroidRuntime(859): at com.example.flipfree.SearchPage.onAttach(SearchPage.java:83)

androidstudio 一键开发,你还等啥

以上是 【安卓】搞不懂安卓开发的版本和jar包问题!! 的全部内容, 来源链接: utcz.com/a/105407.html

回到顶部