现在我正在尝试通过自学习在android中创建一个图形。在谷歌上做了一些搜索我得到了一些想法。它建议我使用一些库或jar文件在android上创建图形或图表。喜欢明智的我从这个link获得了kichart WinRAR文件。
模拟器运行后,它只是以“抱歉你的应用程序已意外停止。请再试一次。强制关闭”
任何人都可以帮我解决这个问题吗? 请找我的资料来源参考。
MainActiviy.java
package com.example.z_chart;
import com.kidroid.kichart.ChartActivity;
import com.kidroid.kichart.model.Aitem;
import com.kidroid.kichart.view.LineView;
import android.graphics.Color;
import android.os.Bundle;
public class MainActivity extends ChartActivity
{
LineView lv = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] arrX = new String[4];
arrX[0] = "2010.1";
arrX[1] = "2010.2";
arrX[2] = "2010.3";
arrX[3] = "2010.4";
float[] arr = new float[4];
arr[0] = 100;
arr[1] = 150;
arr[2] = 380;
arr[3] = 300;
Aitem[] items = new Aitem[1];
items[0] = new Aitem(Color.RED, "Payout", arr);
lv = new LineView(this);
lv.setTitle("Money balance in four months");
lv.setAxisValueX(arrX);
lv.setItems(items);
setContentView(lv);
}}
logcat的
08-17 11:08:53.473: W/dalvikvm(345): Unable to resolve superclass of Lcom/example/z_chart/MainActivity; (414)
08-17 11:08:53.473: W/dalvikvm(345): Link of class 'Lcom/example/z_chart/MainActivity;' failed
08-17 11:08:53.523: D/AndroidRuntime(345): Shutting down VM
08-17 11:08:53.523: W/dalvikvm(345): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-17 11:08:53.604: E/AndroidRuntime(345): FATAL EXCEPTION: main
08-17 11:08:53.604: E/AndroidRuntime(345): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.z_chart/com.example.z_chart.MainActivity}: java.lang.ClassNotFoundException: com.example.z_chart.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.z_chart-1.apk]
08-17 11:08:53.604: E/AndroidRuntime(345): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
08-17 11:08:53.604: E/AndroidRuntime(345): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-17 11:08:53.604: E/AndroidRuntime(345): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-17 11:08:53.604: E/AndroidRuntime(345): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-17 11:08:53.604: E/AndroidRuntime(345): at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 11:08:53.604: E/AndroidRuntime(345): at android.os.Looper.loop(Looper.java:123)
08-17 11:08:53.604: E/AndroidRuntime(345): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-17 11:08:53.604: E/AndroidRuntime(345): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 11:08:53.604: E/AndroidRuntime(345): at java.lang.reflect.Method.invoke(Method.java:521)
08-17 11:08:53.604: E/AndroidRuntime(345): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-17 11:08:53.604: E/AndroidRuntime(345): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-17 11:08:53.604: E/AndroidRuntime(345): at dalvik.system.NativeStart.main(Native Method)
08-17 11:08:53.604: E/AndroidRuntime(345): Caused by: java.lang.ClassNotFoundException: com.example.z_chart.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.z_chart-1.apk]
08-17 11:08:53.604: E/AndroidRuntime(345): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
08-17 11:08:53.604: E/AndroidRuntime(345): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
08-17 11:08:53.604: E/AndroidRuntime(345): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
08-17 11:08:53.604: E/AndroidRuntime(345): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-17 11:08:53.604: E/AndroidRuntime(345): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
08-17 11:08:53.604: E/AndroidRuntime(345): ... 11 more
的Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.z_chart"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
提前致谢!..
答案 0 :(得分:0)
尝试清理项目,然后再次检查。
点击项目 - &gt;在Eclipse中清理。
清理项目并重新构建它,以便更新R.java并且不使用任何缓存的文件
Here您可以找到不同的解决方案。
从代码中删除此行。
setContentView(R.layout.activity_main);